-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add GetRehydrationtoken for rehydration purpose #41655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cc68617
Add GetRehydrationToken to Operation for rehydration purpose
live1206 b425271
export API
live1206 74183b1
make struct readonly
live1206 1530b50
export API
live1206 ddc3f57
update
live1206 c40f52a
clean up
live1206 fcd3930
Merge branch 'main' into rehydration-token
live1206 087a939
update
live1206 4c5f363
remove Optional
live1206 09e4e8e
update
live1206 2826256
Address comments
live1206 4826528
update API
live1206 5992a97
Address PR comments.
live1206 3b04c85
Address comments
live1206 a4a10e6
Merge remote-tracking branch 'origin/main' into rehydration-token
live1206 168ae3f
Add unit tests
live1206 d2df11d
Merge branch 'rehydration-token' of https://github.com/Azure/azure-sd…
live1206 ea2348b
update API
live1206 c33dfe5
Merge branch 'main' into rehydration-token
live1206 5fe92c4
minor
live1206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.Text.Json; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Azure.Core | ||
| { | ||
| public partial struct RehydrationToken : IJsonModel<RehydrationToken> | ||
| { | ||
| internal RehydrationToken DeserializeRehydrationToken(JsonElement element, ModelReaderWriterOptions options) | ||
| { | ||
| if (element.ValueKind == JsonValueKind.Null) | ||
| { | ||
| return default; | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Guid? id = default; | ||
| string version = string.Empty; | ||
| string headerSource = string.Empty; | ||
| string nextRequestUri = string.Empty; | ||
| string initialUri = string.Empty; | ||
| RequestMethod requestMethod = default; | ||
| string? lastKnownLocation = null; | ||
| string finalStateVia = string.Empty; | ||
|
|
||
| foreach (var property in element.EnumerateObject()) | ||
| { | ||
| if (property.NameEquals("id"u8)) | ||
| { | ||
| if (property.Value.ValueKind == JsonValueKind.Null) | ||
| { | ||
| continue; | ||
| } | ||
| id = Guid.Parse(property.Value.GetString()!); | ||
| } | ||
| if (property.NameEquals("version"u8)) | ||
| { | ||
| version = property.Value.GetString()!; | ||
| continue; | ||
| } | ||
| if (property.NameEquals("headerSource"u8)) | ||
| { | ||
| headerSource = property.Value.GetString()!; | ||
| continue; | ||
| } | ||
| if (property.NameEquals("nextRequestUri"u8)) | ||
| { | ||
| nextRequestUri = property.Value.GetString()!; | ||
| continue; | ||
| } | ||
| if (property.NameEquals("initialUri"u8)) | ||
| { | ||
| initialUri = property.Value.GetString()!; | ||
| continue; | ||
| } | ||
| if (property.NameEquals("requestMethod"u8)) | ||
| { | ||
| requestMethod = new RequestMethod(property.Value.GetString()!); | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| continue; | ||
| } | ||
| if (property.NameEquals("lastKnownLocation"u8)) | ||
| { | ||
| if (property.Value.ValueKind == JsonValueKind.Null) | ||
| { | ||
| continue; | ||
| } | ||
| lastKnownLocation = property.Value.GetString(); | ||
| continue; | ||
| } | ||
| if (property.NameEquals("finalStateVia"u8)) | ||
| { | ||
| finalStateVia = property.Value.GetString()!; | ||
| continue; | ||
| } | ||
| } | ||
| return new RehydrationToken(id, version, headerSource, nextRequestUri, initialUri, requestMethod, lastKnownLocation, finalStateVia); | ||
live1206 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void IJsonModel<RehydrationToken>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WritePropertyName("id"u8); | ||
| writer.WriteStringValue(Id.ToString()); | ||
| writer.WritePropertyName("version"u8); | ||
| writer.WriteStringValue(Version); | ||
| writer.WritePropertyName("headerSource"u8); | ||
| writer.WriteStringValue(HeaderSource.ToString()); | ||
| writer.WritePropertyName("nextRequestUri"u8); | ||
| writer.WriteStringValue(NextRequestUri); | ||
| writer.WritePropertyName("initialUri"u8); | ||
| writer.WriteStringValue(InitialUri); | ||
| writer.WritePropertyName("requestMethod"u8); | ||
| writer.WriteStringValue(RequestMethod.ToString()); | ||
| writer.WritePropertyName("lastKnownLocation"u8); | ||
| writer.WriteStringValue(LastKnownLocation); | ||
| writer.WritePropertyName("finalStateVia"u8); | ||
| writer.WriteStringValue(FinalStateVia.ToString()); | ||
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| RehydrationToken IJsonModel<RehydrationToken>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) | ||
| { | ||
| using var document = JsonDocument.ParseValue(ref reader); | ||
| return DeserializeRehydrationToken(document.RootElement, options); | ||
| } | ||
|
|
||
| BinaryData IPersistableModel<RehydrationToken>.Write(ModelReaderWriterOptions options) | ||
| => ModelReaderWriter.Write(this, options); | ||
|
|
||
| RehydrationToken IPersistableModel<RehydrationToken>.Create(BinaryData data, ModelReaderWriterOptions options) | ||
| { | ||
| using var document = JsonDocument.Parse(data); | ||
| return DeserializeRehydrationToken(document.RootElement, options); | ||
| } | ||
|
|
||
| string IPersistableModel<RehydrationToken>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #nullable enable | ||
annelo-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| using System; | ||
|
|
||
| namespace Azure.Core | ||
| { | ||
| /// <summary> | ||
| /// Represents a token that can be used to rehydrate a long-running operation. | ||
| /// </summary> | ||
| public readonly partial struct RehydrationToken | ||
jsquire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary> | ||
| /// Gets an ID representing the operation that can be used to poll for | ||
| /// the status of the long-running operation. | ||
| /// </summary> | ||
| public Guid? Id { get; } | ||
|
|
||
| internal string Version { get; } = "1.0.0"; | ||
|
|
||
| internal string HeaderSource { get; } | ||
jsquire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| internal string NextRequestUri { get; } | ||
|
|
||
| internal string InitialUri { get; } | ||
|
|
||
| internal RequestMethod RequestMethod { get; } | ||
|
|
||
| internal string? LastKnownLocation { get; } | ||
|
|
||
| internal string FinalStateVia { get; } | ||
|
|
||
| internal RehydrationToken(Guid? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, string? lastKnownLocation, string finalStateVia) | ||
| { | ||
| Id = id; | ||
| if (version is not null) | ||
| { | ||
| Version = version; | ||
| } | ||
| HeaderSource = headerSource; | ||
| NextRequestUri = nextRequestUri; | ||
| InitialUri = initialUri; | ||
| RequestMethod = requestMethod; | ||
| LastKnownLocation = lastKnownLocation; | ||
| FinalStateVia = finalStateVia; | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.