From cc686177d205192d30010e48cbf614fb4133986a Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 26 Jan 2024 13:52:23 +0800 Subject: [PATCH 01/16] Add GetRehydrationToken to Operation for rehydration purpose --- eng/Directory.Build.Common.targets | 1 + sdk/core/Azure.Core/src/Azure.Core.csproj | 8 +- sdk/core/Azure.Core/src/Operation.cs | 5 + .../src/RehydrationToken.Serialization.cs | 135 ++++++++++++++++++ sdk/core/Azure.Core/src/RehydrationToken.cs | 53 +++++++ .../Azure.Core/src/Shared/HeaderSource.cs | 13 ++ .../Shared/NextLinkOperationImplementation.cs | 8 -- .../Azure.Core/tests/Azure.Core.Tests.csproj | 4 - 8 files changed, 214 insertions(+), 13 deletions(-) create mode 100644 sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs create mode 100644 sdk/core/Azure.Core/src/RehydrationToken.cs create mode 100644 sdk/core/Azure.Core/src/Shared/HeaderSource.cs diff --git a/eng/Directory.Build.Common.targets b/eng/Directory.Build.Common.targets index b487c45f0401..483c44700d8e 100644 --- a/eng/Directory.Build.Common.targets +++ b/eng/Directory.Build.Common.targets @@ -211,6 +211,7 @@ + diff --git a/sdk/core/Azure.Core/src/Azure.Core.csproj b/sdk/core/Azure.Core/src/Azure.Core.csproj index e16d7472d3b0..50f12e1bd222 100644 --- a/sdk/core/Azure.Core/src/Azure.Core.csproj +++ b/sdk/core/Azure.Core/src/Azure.Core.csproj @@ -1,4 +1,4 @@ - + This is the implementation of the Azure Client Pipeline Microsoft Azure Client Pipeline @@ -21,6 +21,7 @@ + @@ -48,6 +49,8 @@ + + @@ -56,6 +59,7 @@ + @@ -63,6 +67,8 @@ + + diff --git a/sdk/core/Azure.Core/src/Operation.cs b/sdk/core/Azure.Core/src/Operation.cs index 0f12ae9f90ca..7ff18388e0f8 100644 --- a/sdk/core/Azure.Core/src/Operation.cs +++ b/sdk/core/Azure.Core/src/Operation.cs @@ -16,6 +16,11 @@ namespace Azure public abstract class Operation #pragma warning restore AZC0012 // Avoid single word type names { + /// + /// Get a token that can be used to rehydrate the operation. + /// + public virtual RehydrationToken? GetRehydrationToken() => null; + /// /// Gets an ID representing the operation that can be used to poll for /// the status of the long-running operation. diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs new file mode 100644 index 000000000000..e9db5971c926 --- /dev/null +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -0,0 +1,135 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; + +#nullable disable + +namespace Azure.Core +{ + public partial struct RehydrationToken : IJsonModel + { + internal RehydrationToken DeserializeRehydrationToken(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return default; + } + Optional id = default; + string version = string.Empty; + HeaderSource headerSource = default; + string nextRequestUri = string.Empty; + string initialUri = string.Empty; + RequestMethod requestMethod = default; + bool originalResponseHasLocation = default; + Optional lastKnownLocation = default; + OperationFinalStateVia finalStateVia = default; + + 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)) + { + if (!Enum.TryParse(property.Value.GetString(), out headerSource)) + { + headerSource = default; + } + 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()); + continue; + } + if (property.NameEquals("originalResponseHasLocation"u8)) + { + originalResponseHasLocation = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("lastKnownLocation"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + lastKnownLocation = property.Value.GetString(); + continue; + } + if (property.NameEquals("finalStateVia"u8)) + { + if (!Enum.TryParse(property.Value.GetString(), out finalStateVia)) + { + finalStateVia = default; + } + continue; + } + } + return new RehydrationToken(id.Value, version, headerSource, nextRequestUri, initialUri, requestMethod, originalResponseHasLocation, lastKnownLocation.Value, finalStateVia); + } + + void IJsonModel.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("originalResponseHasLocation"u8); + writer.WriteBooleanValue(OriginalResponseHasLocation); + writer.WritePropertyName("lastKnownLocation"u8); + writer.WriteStringValue(LastKnownLocation); + writer.WritePropertyName("finalStateVia"u8); + writer.WriteStringValue(FinalStateVia.ToString()); + writer.WriteEndObject(); + } + + RehydrationToken IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + using var document = JsonDocument.ParseValue(ref reader); + return DeserializeRehydrationToken(document.RootElement, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + => ModelReaderWriter.Write(this, options); + + RehydrationToken IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + using var document = JsonDocument.Parse(data); + return DeserializeRehydrationToken(document.RootElement, options); + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs new file mode 100644 index 000000000000..1cb3975260d8 --- /dev/null +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#nullable enable + +using System; + +namespace Azure.Core +{ + /// + /// Represents a token that can be used to rehydrate a long-running operation. + /// + public partial struct RehydrationToken + { + /// + /// Gets an ID representing the operation that can be used to poll for + /// the status of the long-running operation. + /// + public Guid? Id { get; } + + internal string Version { get; } = "1.0.0"; + + internal HeaderSource HeaderSource { get; } + + internal string NextRequestUri { get; } + + internal string InitialUri { get; } + + internal RequestMethod RequestMethod { get; } + + internal bool OriginalResponseHasLocation { get; } + + internal string? LastKnownLocation { get; } + + internal OperationFinalStateVia FinalStateVia { get; } + + internal RehydrationToken(Guid? id, string? version, HeaderSource headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, bool originalResponseHasLocation, string? lastKnownLocation, OperationFinalStateVia finalStateVia) + { + Id = id; + if (version is not null) + { + Version = version; + } + HeaderSource = headerSource; + NextRequestUri = nextRequestUri; + InitialUri = initialUri; + RequestMethod = requestMethod; + OriginalResponseHasLocation = originalResponseHasLocation; + LastKnownLocation = lastKnownLocation; + FinalStateVia = finalStateVia; + } + } +} diff --git a/sdk/core/Azure.Core/src/Shared/HeaderSource.cs b/sdk/core/Azure.Core/src/Shared/HeaderSource.cs new file mode 100644 index 000000000000..a0be39f96246 --- /dev/null +++ b/sdk/core/Azure.Core/src/Shared/HeaderSource.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.Core +{ + internal enum HeaderSource + { + None, + OperationLocation, + AzureAsyncOperation, + Location + } +} diff --git a/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs b/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs index 120c2d63a7d3..3f38b46aba34 100644 --- a/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs +++ b/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs @@ -394,14 +394,6 @@ private static HeaderSource GetHeaderSource(RequestMethod requestMethod, Uri req return HeaderSource.None; } - private enum HeaderSource - { - None, - OperationLocation, - AzureAsyncOperation, - Location - } - private class CompletedOperation : IOperation { private readonly OperationState _operationState; diff --git a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj index 0faa6ea6ffe1..fbcc25e1998f 100644 --- a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj +++ b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj @@ -30,8 +30,6 @@ - - @@ -44,8 +42,6 @@ - - From b425271c29124f6cbea8bd9e4b89105aa784edb4 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 26 Jan 2024 13:56:06 +0800 Subject: [PATCH 02/16] export API --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 13 +++++++++++++ sdk/core/Azure.Core/api/Azure.Core.net472.cs | 13 +++++++++++++ sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 13 +++++++++++++ .../Azure.Core/api/Azure.Core.netstandard2.0.cs | 13 +++++++++++++ 4 files changed, 52 insertions(+) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 49995b0e56e3..614cf4fa5bee 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -137,6 +137,7 @@ protected Operation() { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public abstract Azure.Response GetRawResponse(); + public virtual Azure.Core.RehydrationToken? GetRehydrationToken() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string? ToString() { throw null; } public abstract Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); @@ -518,6 +519,18 @@ public static partial class MultipartResponse public static Azure.Response[] Parse(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + private object _dummy; + private int _dummyPrimitive; + public System.Guid? Id { get { throw null; } } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public abstract partial class Request : System.IDisposable { protected Request() { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net472.cs b/sdk/core/Azure.Core/api/Azure.Core.net472.cs index 49995b0e56e3..614cf4fa5bee 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net472.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net472.cs @@ -137,6 +137,7 @@ protected Operation() { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public abstract Azure.Response GetRawResponse(); + public virtual Azure.Core.RehydrationToken? GetRehydrationToken() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string? ToString() { throw null; } public abstract Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); @@ -518,6 +519,18 @@ public static partial class MultipartResponse public static Azure.Response[] Parse(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + private object _dummy; + private int _dummyPrimitive; + public System.Guid? Id { get { throw null; } } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public abstract partial class Request : System.IDisposable { protected Request() { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index 16d3e7cb99ce..3fbb3dcbb17c 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -137,6 +137,7 @@ protected Operation() { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public abstract Azure.Response GetRawResponse(); + public virtual Azure.Core.RehydrationToken? GetRehydrationToken() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string? ToString() { throw null; } public abstract Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); @@ -518,6 +519,18 @@ public static partial class MultipartResponse public static Azure.Response[] Parse(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + private object _dummy; + private int _dummyPrimitive; + public System.Guid? Id { get { throw null; } } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public abstract partial class Request : System.IDisposable { protected Request() { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 49995b0e56e3..614cf4fa5bee 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -137,6 +137,7 @@ protected Operation() { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public abstract Azure.Response GetRawResponse(); + public virtual Azure.Core.RehydrationToken? GetRehydrationToken() { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override string? ToString() { throw null; } public abstract Azure.Response UpdateStatus(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); @@ -518,6 +519,18 @@ public static partial class MultipartResponse public static Azure.Response[] Parse(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + private object _dummy; + private int _dummyPrimitive; + public System.Guid? Id { get { throw null; } } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } public abstract partial class Request : System.IDisposable { protected Request() { } From 74183b13970d7091300a8124855e66d724bfe256 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 26 Jan 2024 15:00:12 +0800 Subject: [PATCH 03/16] make struct readonly --- sdk/core/Azure.Core/src/RehydrationToken.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index 1cb3975260d8..a0ed1d148bfc 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -10,7 +10,7 @@ namespace Azure.Core /// /// Represents a token that can be used to rehydrate a long-running operation. /// - public partial struct RehydrationToken + public readonly partial struct RehydrationToken { /// /// Gets an ID representing the operation that can be used to poll for From 1530b50ac9e2dcee80ad02f4f37b0b530382c16a Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 26 Jan 2024 15:01:03 +0800 Subject: [PATCH 04/16] export API --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 6 +++--- sdk/core/Azure.Core/api/Azure.Core.net472.cs | 6 +++--- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 6 +++--- sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 614cf4fa5bee..3cdc6d4c25a0 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -520,10 +520,10 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public System.Guid? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net472.cs b/sdk/core/Azure.Core/api/Azure.Core.net472.cs index 614cf4fa5bee..3cdc6d4c25a0 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net472.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net472.cs @@ -520,10 +520,10 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public System.Guid? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index 3fbb3dcbb17c..6772bc9c0a60 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -520,10 +520,10 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public System.Guid? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 614cf4fa5bee..3cdc6d4c25a0 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -520,10 +520,10 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - private object _dummy; - private int _dummyPrimitive; + private readonly object _dummy; + private readonly int _dummyPrimitive; public System.Guid? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } From ddc3f57da8f48298d1cd1a877eaa631a037c874e Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jan 2024 10:39:31 +0800 Subject: [PATCH 05/16] update --- eng/Directory.Build.Common.targets | 1 - sdk/core/Azure.Core/src/Azure.Core.csproj | 1 - sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs | 7 ++----- sdk/core/Azure.Core/src/RehydrationToken.cs | 4 ++-- .../src/Shared/NextLinkOperationImplementation.cs | 8 ++++++++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/eng/Directory.Build.Common.targets b/eng/Directory.Build.Common.targets index 483c44700d8e..b487c45f0401 100644 --- a/eng/Directory.Build.Common.targets +++ b/eng/Directory.Build.Common.targets @@ -211,7 +211,6 @@ - diff --git a/sdk/core/Azure.Core/src/Azure.Core.csproj b/sdk/core/Azure.Core/src/Azure.Core.csproj index 50f12e1bd222..29e35e0c3218 100644 --- a/sdk/core/Azure.Core/src/Azure.Core.csproj +++ b/sdk/core/Azure.Core/src/Azure.Core.csproj @@ -59,7 +59,6 @@ - diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index e9db5971c926..bf6b9a39821c 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -19,7 +19,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model } Optional id = default; string version = string.Empty; - HeaderSource headerSource = default; + string headerSource = default; string nextRequestUri = string.Empty; string initialUri = string.Empty; RequestMethod requestMethod = default; @@ -44,10 +44,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model } if (property.NameEquals("headerSource"u8)) { - if (!Enum.TryParse(property.Value.GetString(), out headerSource)) - { - headerSource = default; - } + headerSource = property.Value.GetString(); continue; } if (property.NameEquals("nextRequestUri"u8)) diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index a0ed1d148bfc..16c891e105f3 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -20,7 +20,7 @@ public readonly partial struct RehydrationToken internal string Version { get; } = "1.0.0"; - internal HeaderSource HeaderSource { get; } + internal string HeaderSource { get; } internal string NextRequestUri { get; } @@ -34,7 +34,7 @@ public readonly partial struct RehydrationToken internal OperationFinalStateVia FinalStateVia { get; } - internal RehydrationToken(Guid? id, string? version, HeaderSource headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, bool originalResponseHasLocation, string? lastKnownLocation, OperationFinalStateVia finalStateVia) + internal RehydrationToken(Guid? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, bool originalResponseHasLocation, string? lastKnownLocation, OperationFinalStateVia finalStateVia) { Id = id; if (version is not null) diff --git a/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs b/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs index 3f38b46aba34..120c2d63a7d3 100644 --- a/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs +++ b/sdk/core/Azure.Core/src/Shared/NextLinkOperationImplementation.cs @@ -394,6 +394,14 @@ private static HeaderSource GetHeaderSource(RequestMethod requestMethod, Uri req return HeaderSource.None; } + private enum HeaderSource + { + None, + OperationLocation, + AzureAsyncOperation, + Location + } + private class CompletedOperation : IOperation { private readonly OperationState _operationState; From c40f52a9ddbde7d6d43c9d5bc0c01efc70dd4411 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jan 2024 17:18:14 +0800 Subject: [PATCH 06/16] clean up --- sdk/core/Azure.Core/src/Shared/HeaderSource.cs | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 sdk/core/Azure.Core/src/Shared/HeaderSource.cs diff --git a/sdk/core/Azure.Core/src/Shared/HeaderSource.cs b/sdk/core/Azure.Core/src/Shared/HeaderSource.cs deleted file mode 100644 index a0be39f96246..000000000000 --- a/sdk/core/Azure.Core/src/Shared/HeaderSource.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -namespace Azure.Core -{ - internal enum HeaderSource - { - None, - OperationLocation, - AzureAsyncOperation, - Location - } -} From 087a93976186ba85dc4dcf61d101380d47d586a3 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 31 Jan 2024 10:49:50 +0800 Subject: [PATCH 07/16] update --- .../Azure.Core/src/RehydrationToken.Serialization.cs | 10 +--------- sdk/core/Azure.Core/src/RehydrationToken.cs | 5 +---- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index bf6b9a39821c..eff6721beb79 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -23,7 +23,6 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model string nextRequestUri = string.Empty; string initialUri = string.Empty; RequestMethod requestMethod = default; - bool originalResponseHasLocation = default; Optional lastKnownLocation = default; OperationFinalStateVia finalStateVia = default; @@ -62,11 +61,6 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model requestMethod = new RequestMethod(property.Value.GetString()); continue; } - if (property.NameEquals("originalResponseHasLocation"u8)) - { - originalResponseHasLocation = property.Value.GetBoolean(); - continue; - } if (property.NameEquals("lastKnownLocation"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -85,7 +79,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model continue; } } - return new RehydrationToken(id.Value, version, headerSource, nextRequestUri, initialUri, requestMethod, originalResponseHasLocation, lastKnownLocation.Value, finalStateVia); + return new RehydrationToken(id.Value, version, headerSource, nextRequestUri, initialUri, requestMethod, lastKnownLocation.Value, finalStateVia); } void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) @@ -103,8 +97,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriter writer.WriteStringValue(InitialUri); writer.WritePropertyName("requestMethod"u8); writer.WriteStringValue(RequestMethod.ToString()); - writer.WritePropertyName("originalResponseHasLocation"u8); - writer.WriteBooleanValue(OriginalResponseHasLocation); writer.WritePropertyName("lastKnownLocation"u8); writer.WriteStringValue(LastKnownLocation); writer.WritePropertyName("finalStateVia"u8); diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index 16c891e105f3..e57c6ddb4236 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -28,13 +28,11 @@ public readonly partial struct RehydrationToken internal RequestMethod RequestMethod { get; } - internal bool OriginalResponseHasLocation { get; } - internal string? LastKnownLocation { get; } internal OperationFinalStateVia FinalStateVia { get; } - internal RehydrationToken(Guid? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, bool originalResponseHasLocation, string? lastKnownLocation, OperationFinalStateVia finalStateVia) + internal RehydrationToken(Guid? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, string? lastKnownLocation, OperationFinalStateVia finalStateVia) { Id = id; if (version is not null) @@ -45,7 +43,6 @@ internal RehydrationToken(Guid? id, string? version, string headerSource, string NextRequestUri = nextRequestUri; InitialUri = initialUri; RequestMethod = requestMethod; - OriginalResponseHasLocation = originalResponseHasLocation; LastKnownLocation = lastKnownLocation; FinalStateVia = finalStateVia; } From 4c5f363cb4fc5001959b47e26bc3d6d11f903e3a Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 1 Feb 2024 09:02:54 +0800 Subject: [PATCH 08/16] remove Optional --- sdk/core/Azure.Core/src/Azure.Core.csproj | 3 --- .../src/RehydrationToken.Serialization.cs | 22 +++++++++---------- .../Azure.Core/tests/Azure.Core.Tests.csproj | 3 +++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sdk/core/Azure.Core/src/Azure.Core.csproj b/sdk/core/Azure.Core/src/Azure.Core.csproj index 29e35e0c3218..20088b485b0d 100644 --- a/sdk/core/Azure.Core/src/Azure.Core.csproj +++ b/sdk/core/Azure.Core/src/Azure.Core.csproj @@ -49,8 +49,6 @@ - - @@ -66,7 +64,6 @@ - diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index eff6721beb79..c191f8017ea4 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -5,7 +5,7 @@ using System.ClientModel.Primitives; using System.Text.Json; -#nullable disable +#nullable enable namespace Azure.Core { @@ -17,13 +17,13 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model { return default; } - Optional id = default; + Guid? id = default; string version = string.Empty; - string headerSource = default; + string headerSource = string.Empty; string nextRequestUri = string.Empty; string initialUri = string.Empty; RequestMethod requestMethod = default; - Optional lastKnownLocation = default; + string? lastKnownLocation = null; OperationFinalStateVia finalStateVia = default; foreach (var property in element.EnumerateObject()) @@ -34,31 +34,31 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model { continue; } - id = Guid.Parse(property.Value.GetString()); + id = Guid.Parse(property.Value.GetString()!); } if (property.NameEquals("version"u8)) { - version = property.Value.GetString(); + version = property.Value.GetString()!; continue; } if (property.NameEquals("headerSource"u8)) { - headerSource = property.Value.GetString(); + headerSource = property.Value.GetString()!; continue; } if (property.NameEquals("nextRequestUri"u8)) { - nextRequestUri = property.Value.GetString(); + nextRequestUri = property.Value.GetString()!; continue; } if (property.NameEquals("initialUri"u8)) { - initialUri = property.Value.GetString(); + initialUri = property.Value.GetString()!; continue; } if (property.NameEquals("requestMethod"u8)) { - requestMethod = new RequestMethod(property.Value.GetString()); + requestMethod = new RequestMethod(property.Value.GetString()!); continue; } if (property.NameEquals("lastKnownLocation"u8)) @@ -79,7 +79,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model continue; } } - return new RehydrationToken(id.Value, version, headerSource, nextRequestUri, initialUri, requestMethod, lastKnownLocation.Value, finalStateVia); + return new RehydrationToken(id, version, headerSource, nextRequestUri, initialUri, requestMethod, lastKnownLocation, finalStateVia); } void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) diff --git a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj index fbcc25e1998f..78b946cbbc93 100644 --- a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj +++ b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj @@ -30,6 +30,8 @@ + + @@ -42,6 +44,7 @@ + From 09e4e8e560149cc1ddd49e4482512d11526befe6 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 1 Feb 2024 23:38:36 +0800 Subject: [PATCH 09/16] update --- sdk/core/Azure.Core/src/Azure.Core.csproj | 1 - sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs | 7 ++----- sdk/core/Azure.Core/src/RehydrationToken.cs | 4 ++-- sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj | 1 + 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/sdk/core/Azure.Core/src/Azure.Core.csproj b/sdk/core/Azure.Core/src/Azure.Core.csproj index 20088b485b0d..2dbf8c1dbc4b 100644 --- a/sdk/core/Azure.Core/src/Azure.Core.csproj +++ b/sdk/core/Azure.Core/src/Azure.Core.csproj @@ -64,7 +64,6 @@ - diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index c191f8017ea4..b5955565162d 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -24,7 +24,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model string initialUri = string.Empty; RequestMethod requestMethod = default; string? lastKnownLocation = null; - OperationFinalStateVia finalStateVia = default; + string finalStateVia = string.Empty; foreach (var property in element.EnumerateObject()) { @@ -72,10 +72,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model } if (property.NameEquals("finalStateVia"u8)) { - if (!Enum.TryParse(property.Value.GetString(), out finalStateVia)) - { - finalStateVia = default; - } + finalStateVia = property.Value.GetString()!; continue; } } diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index e57c6ddb4236..d5a7c5f876a0 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -30,9 +30,9 @@ public readonly partial struct RehydrationToken internal string? LastKnownLocation { get; } - internal OperationFinalStateVia FinalStateVia { get; } + internal string FinalStateVia { get; } - internal RehydrationToken(Guid? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, string? lastKnownLocation, OperationFinalStateVia finalStateVia) + 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) diff --git a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj index 78b946cbbc93..0faa6ea6ffe1 100644 --- a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj +++ b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj @@ -44,6 +44,7 @@ + From 282625608cbb10ca4b64257a76aec59ffb75053e Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 2 Feb 2024 08:30:32 +0800 Subject: [PATCH 10/16] Address comments --- sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs | 6 +++--- sdk/core/Azure.Core/src/RehydrationToken.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index b5955565162d..70079d6c83b0 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -17,7 +17,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model { return default; } - Guid? id = default; + string? id = null; string version = string.Empty; string headerSource = string.Empty; string nextRequestUri = string.Empty; @@ -34,7 +34,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model { continue; } - id = Guid.Parse(property.Value.GetString()!); + id = property.Value.GetString()!; } if (property.NameEquals("version"u8)) { @@ -83,7 +83,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriter { writer.WriteStartObject(); writer.WritePropertyName("id"u8); - writer.WriteStringValue(Id.ToString()); + writer.WriteStringValue(Id); writer.WritePropertyName("version"u8); writer.WriteStringValue(Version); writer.WritePropertyName("headerSource"u8); diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index d5a7c5f876a0..4b9b6bab63ea 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -16,7 +16,7 @@ public readonly partial struct RehydrationToken /// Gets an ID representing the operation that can be used to poll for /// the status of the long-running operation. /// - public Guid? Id { get; } + public string? Id { get; } internal string Version { get; } = "1.0.0"; @@ -32,7 +32,7 @@ public readonly partial struct RehydrationToken internal string FinalStateVia { get; } - internal RehydrationToken(Guid? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, string? lastKnownLocation, string finalStateVia) + internal RehydrationToken(string? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, string? lastKnownLocation, string finalStateVia) { Id = id; if (version is not null) From 4826528868a9504117bc13281e074eeb7b8a61f3 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 2 Feb 2024 08:32:50 +0800 Subject: [PATCH 11/16] update API --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net472.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 2 +- sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index 3cdc6d4c25a0..c51499d7d22e 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -524,7 +524,7 @@ public static partial class MultipartResponse { private readonly object _dummy; private readonly int _dummyPrimitive; - public System.Guid? Id { get { throw null; } } + public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net472.cs b/sdk/core/Azure.Core/api/Azure.Core.net472.cs index 3cdc6d4c25a0..c51499d7d22e 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net472.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net472.cs @@ -524,7 +524,7 @@ public static partial class MultipartResponse { private readonly object _dummy; private readonly int _dummyPrimitive; - public System.Guid? Id { get { throw null; } } + public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index 6772bc9c0a60..e5ae8ee52ec7 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -524,7 +524,7 @@ public static partial class MultipartResponse { private readonly object _dummy; private readonly int _dummyPrimitive; - public System.Guid? Id { get { throw null; } } + public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index 3cdc6d4c25a0..c51499d7d22e 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -524,7 +524,7 @@ public static partial class MultipartResponse { private readonly object _dummy; private readonly int _dummyPrimitive; - public System.Guid? Id { get { throw null; } } + public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } From 5992a975086b50167d3913e513976669112f29f8 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 6 Feb 2024 14:00:48 +0800 Subject: [PATCH 12/16] Address PR comments. --- sdk/core/Azure.Core/CHANGELOG.md | 2 ++ .../src/RehydrationToken.Serialization.cs | 13 +++++++++---- sdk/core/Azure.Core/src/RehydrationToken.cs | 4 ---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sdk/core/Azure.Core/CHANGELOG.md b/sdk/core/Azure.Core/CHANGELOG.md index f8f75384227c..1fbb14c810c1 100644 --- a/sdk/core/Azure.Core/CHANGELOG.md +++ b/sdk/core/Azure.Core/CHANGELOG.md @@ -4,6 +4,8 @@ ### Features Added +- Add `GetRehydrationToken` to `Operation` for rehydration purpose. + ### Breaking Changes ### Bugs Fixed diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index 70079d6c83b0..d6a7198a4988 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -5,18 +5,23 @@ using System.ClientModel.Primitives; using System.Text.Json; -#nullable enable - namespace Azure.Core { public partial struct RehydrationToken : IJsonModel { internal RehydrationToken DeserializeRehydrationToken(JsonElement element, ModelReaderWriterOptions options) { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RehydrationToken)} does not support '{format}' format."); + } + if (element.ValueKind == JsonValueKind.Null) { - return default; + throw new InvalidOperationException("Cannot deserialize a null value to a non-nullable RehydrationToken"); } + string? id = null; string version = string.Empty; string headerSource = string.Empty; @@ -34,7 +39,7 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model { continue; } - id = property.Value.GetString()!; + id = property.Value.GetString(); } if (property.NameEquals("version"u8)) { diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index 4b9b6bab63ea..0d3cd4f0f63b 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -1,10 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#nullable enable - -using System; - namespace Azure.Core { /// From 3b04c8547bc16ee3e5382485b941d3006c955fb2 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 7 Feb 2024 10:36:05 +0800 Subject: [PATCH 13/16] Address comments --- .../src/RehydrationToken.Serialization.cs | 25 ++++++++++++++----- sdk/core/Azure.Core/src/RehydrationToken.cs | 8 ++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index d6a7198a4988..af2efbb45075 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -3,6 +3,7 @@ using System; using System.ClientModel.Primitives; +using System.Diagnostics; using System.Text.Json; namespace Azure.Core @@ -43,27 +44,37 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model } if (property.NameEquals("version"u8)) { - version = property.Value.GetString()!; + var versionString = property.Value.GetString(); + Debug.Assert(versionString is not null); + version = versionString!; continue; } if (property.NameEquals("headerSource"u8)) { - headerSource = property.Value.GetString()!; + var headerSourceString = property.Value.GetString(); + Debug.Assert(headerSourceString is not null); + headerSource = headerSourceString!; continue; } if (property.NameEquals("nextRequestUri"u8)) { - nextRequestUri = property.Value.GetString()!; + var nextRequestUriString = property.Value.GetString(); + Debug.Assert(nextRequestUriString is not null); + nextRequestUri = nextRequestUriString!; continue; } if (property.NameEquals("initialUri"u8)) { - initialUri = property.Value.GetString()!; + var initialUriString = property.Value.GetString(); + Debug.Assert(initialUriString is not null); + initialUri = initialUriString!; continue; } if (property.NameEquals("requestMethod"u8)) { - requestMethod = new RequestMethod(property.Value.GetString()!); + var requestMethodString = property.Value.GetString(); + Debug.Assert(requestMethodString is not null); + requestMethod = new RequestMethod(requestMethodString!); continue; } if (property.NameEquals("lastKnownLocation"u8)) @@ -77,7 +88,9 @@ internal RehydrationToken DeserializeRehydrationToken(JsonElement element, Model } if (property.NameEquals("finalStateVia"u8)) { - finalStateVia = property.Value.GetString()!; + var finalStateViaString = property.Value.GetString(); + Debug.Assert(finalStateViaString is not null); + finalStateVia = finalStateViaString!; continue; } } diff --git a/sdk/core/Azure.Core/src/RehydrationToken.cs b/sdk/core/Azure.Core/src/RehydrationToken.cs index 0d3cd4f0f63b..13addaadc64f 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.cs @@ -14,18 +14,26 @@ public readonly partial struct RehydrationToken /// public string? Id { get; } + // Version for this contract itself since we might change the members in the future. internal string Version { get; } = "1.0.0"; + // The below members are used to re-construct . + // Value of . internal string HeaderSource { get; } + // The polling Uri of the operation. internal string NextRequestUri { get; } + // The initial Uri of the operation. internal string InitialUri { get; } + // The Http request method of the operation. internal RequestMethod RequestMethod { get; } + // The last known location of the operation. internal string? LastKnownLocation { get; } + // The final state of the operation, could be azure-async-operation, location, original-uri or operation-location. internal string FinalStateVia { get; } internal RehydrationToken(string? id, string? version, string headerSource, string nextRequestUri, string initialUri, RequestMethod requestMethod, string? lastKnownLocation, string finalStateVia) From 168ae3f539db7f1f05948ac57b95313f8b4b2277 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Feb 2024 15:43:50 +0800 Subject: [PATCH 14/16] Add unit tests --- .../src/RehydrationToken.Serialization.cs | 50 +++++++++++++++++-- .../Azure.Core/tests/RehydrationTokenTests.cs | 34 +++++++++++++ 2 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 sdk/core/Azure.Core/tests/RehydrationTokenTests.cs diff --git a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs index af2efbb45075..470323817458 100644 --- a/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs +++ b/sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs @@ -8,7 +8,7 @@ namespace Azure.Core { - public partial struct RehydrationToken : IJsonModel + public partial struct RehydrationToken : IJsonModel, IJsonModel { internal RehydrationToken DeserializeRehydrationToken(JsonElement element, ModelReaderWriterOptions options) { @@ -121,19 +121,59 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriter RehydrationToken IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - using var document = JsonDocument.ParseValue(ref reader); + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RehydrationToken)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); return DeserializeRehydrationToken(document.RootElement, options); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - => ModelReaderWriter.Write(this, options); + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RehydrationToken)} does not support '{options.Format}' format."); + } + } RehydrationToken IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - using var document = JsonDocument.Parse(data); - return DeserializeRehydrationToken(document.RootElement, options); + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRehydrationToken(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RehydrationToken)} does not support '{options.Format}' format."); + } } string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + => ((IPersistableModel)this).Write(options); + + object IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + => ((IPersistableModel)this).Create(data, options); + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => ((IJsonModel)this).Write(writer, options); + + object IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + => ((IJsonModel)this).Create(ref reader, options); } } diff --git a/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs b/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs new file mode 100644 index 000000000000..b2fc4000544a --- /dev/null +++ b/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ClientModel.Primitives; +using NUnit.Framework; + +namespace Azure.Core.Tests +{ + public class RehydrationTokenTests + { + [Test] + public void ThrowOnDeserializationWithNullRehydrationToken() + { + Assert.Throws(() => new RehydrationToken().DeserializeRehydrationToken(default, new ModelReaderWriterOptions("J"))); + } + + [Test] + public void ThrowOnDeserializationWithRehydrationTokenNullRequiredMember() + { + var data = BinaryData.FromString("{'requestMethod': null}".Replace('\'', '\"')); + Assert.That(() => ModelReaderWriter.Read(data, typeof(RehydrationToken)), Throws.Exception); + } + + [Test] + public void RoundTripForRehydrationToken() + { + var token = new RehydrationToken(Guid.NewGuid().ToString(), null, "headerSource", "nextRequestUri", "initialUri", RequestMethod.Get, "lastKnownLocation", OperationFinalStateVia.OperationLocation.ToString()); + var data = ModelReaderWriter.Write(token); + var deserializedToken = ModelReaderWriter.Read(data, typeof(RehydrationToken)); + Assert.AreEqual(token, deserializedToken); + } + } +} From ea2348b58bd37cdfd39668ec8f4833f07db9dbdb Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Feb 2024 16:17:49 +0800 Subject: [PATCH 15/16] update API --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 7 ++++++- sdk/core/Azure.Core/api/Azure.Core.net472.cs | 7 ++++++- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 7 ++++++- sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index c51499d7d22e..956318e726c3 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -520,16 +520,21 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel, System.ClientModel.Primitives.IPersistableModel { private readonly object _dummy; private readonly int _dummyPrimitive; public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + object System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + object System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public abstract partial class Request : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.net472.cs b/sdk/core/Azure.Core/api/Azure.Core.net472.cs index c51499d7d22e..956318e726c3 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net472.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net472.cs @@ -520,16 +520,21 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel, System.ClientModel.Primitives.IPersistableModel { private readonly object _dummy; private readonly int _dummyPrimitive; public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + object System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + object System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public abstract partial class Request : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index e5ae8ee52ec7..df2f51671bc3 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -520,16 +520,21 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel, System.ClientModel.Primitives.IPersistableModel { private readonly object _dummy; private readonly int _dummyPrimitive; public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + object System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + object System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public abstract partial class Request : System.IDisposable { diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index c51499d7d22e..956318e726c3 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -520,16 +520,21 @@ public static partial class MultipartResponse public static System.Threading.Tasks.Task ParseAsync(Azure.Response response, bool expectCrLf, System.Threading.CancellationToken cancellationToken) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public readonly partial struct RehydrationToken : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel, System.ClientModel.Primitives.IPersistableModel { private readonly object _dummy; private readonly int _dummyPrimitive; public string? Id { get { throw null; } } Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + object System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + object System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public abstract partial class Request : System.IDisposable { From 5fe92c419f96a6008bda5cb56712facf202b3dd2 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 20 Feb 2024 09:45:18 +0800 Subject: [PATCH 16/16] minor --- sdk/core/Azure.Core/tests/RehydrationTokenTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs b/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs index b2fc4000544a..b93551c6454a 100644 --- a/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs +++ b/sdk/core/Azure.Core/tests/RehydrationTokenTests.cs @@ -18,7 +18,7 @@ public void ThrowOnDeserializationWithNullRehydrationToken() [Test] public void ThrowOnDeserializationWithRehydrationTokenNullRequiredMember() { - var data = BinaryData.FromString("{'requestMethod': null}".Replace('\'', '\"')); + var data = BinaryData.FromString("\"requestMethod\": null}"); Assert.That(() => ModelReaderWriter.Read(data, typeof(RehydrationToken)), Throws.Exception); }