Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<Azure.Response[]> 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<Azure.Core.RehydrationToken>, System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Guid? Id { get { throw null; } }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
void System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
string System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
System.BinaryData System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
}
public abstract partial class Request : System.IDisposable
{
protected Request() { }
Expand Down
13 changes: 13 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net472.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<Azure.Response[]> 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<Azure.Core.RehydrationToken>, System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Guid? Id { get { throw null; } }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
void System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
string System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
System.BinaryData System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
}
public abstract partial class Request : System.IDisposable
{
protected Request() { }
Expand Down
13 changes: 13 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<Azure.Response[]> 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<Azure.Core.RehydrationToken>, System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Guid? Id { get { throw null; } }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
void System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
string System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
System.BinaryData System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
}
public abstract partial class Request : System.IDisposable
{
protected Request() { }
Expand Down
13 changes: 13 additions & 0 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<Azure.Response[]> 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<Azure.Core.RehydrationToken>, System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Guid? Id { get { throw null; } }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
void System.ClientModel.Primitives.IJsonModel<Azure.Core.RehydrationToken>.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { }
Azure.Core.RehydrationToken System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
string System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
System.BinaryData System.ClientModel.Primitives.IPersistableModel<Azure.Core.RehydrationToken>.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; }
}
public abstract partial class Request : System.IDisposable
{
protected Request() { }
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/Azure.Core/src/Azure.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the implementation of the Azure Client Pipeline</Description>
<AssemblyTitle>Microsoft Azure Client Pipeline</AssemblyTitle>
Expand All @@ -21,6 +21,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="System.ClientModel" />
<PackageReference Include="System.Numerics.Vectors" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.Threading.Tasks.Extensions" />
Expand Down Expand Up @@ -63,6 +64,7 @@
<Compile Include="Shared\OperationInternalBase.cs" />
<Compile Include="Shared\TrimmingAttribute.cs" />
<Compile Include="Shared\VoidValue.cs" />
<Compile Include="Shared\OperationFinalStateVia.cs" />
<Compile Include="Shared\OperationInternal.cs" />
<Compile Include="Shared\OperationInternalOfT.cs" />
<Compile Include="Shared\SequentialDelayStrategy.cs" />
Expand Down
5 changes: 5 additions & 0 deletions sdk/core/Azure.Core/src/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace Azure
public abstract class Operation
#pragma warning restore AZC0012 // Avoid single word type names
{
/// <summary>
/// Get a token that can be used to rehydrate the operation.
/// </summary>
public virtual RehydrationToken? GetRehydrationToken() => null;

/// <summary>
/// Gets an ID representing the operation that can be used to poll for
/// the status of the long-running operation.
Expand Down
124 changes: 124 additions & 0 deletions sdk/core/Azure.Core/src/RehydrationToken.Serialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// 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;
}
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;
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))
{
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()!);
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, version, headerSource, nextRequestUri, initialUri, requestMethod, lastKnownLocation, finalStateVia);
}

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";
}
}
50 changes: 50 additions & 0 deletions sdk/core/Azure.Core/src/RehydrationToken.cs
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

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
{
/// <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; }

internal string NextRequestUri { get; }

internal string InitialUri { get; }

internal RequestMethod RequestMethod { get; }

internal string? LastKnownLocation { get; }

internal OperationFinalStateVia FinalStateVia { get; }

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)
{
Version = version;
}
HeaderSource = headerSource;
NextRequestUri = nextRequestUri;
InitialUri = initialUri;
RequestMethod = requestMethod;
LastKnownLocation = lastKnownLocation;
FinalStateVia = finalStateVia;
}
}
}
1 change: 0 additions & 1 deletion sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<Compile Include="..\src\Shared\NextLinkOperationImplementation.cs" LinkBase="Shared" />
<Compile Include="..\src\Shared\NoBodyResponseOfT.cs" LinkBase="Shared" />
<Compile Include="..\src\Shared\NoValueResponseOfT.cs" LinkBase="Shared" />
<Compile Include="..\src\Shared\OperationFinalStateVia.cs" LinkBase="Shared" />
<Compile Include="..\src\Shared\Optional.cs" LinkBase="Shared" />
<Compile Include="..\src\Shared\Page.cs" LinkBase="Shared" />
<Compile Include="..\src\Shared\PageableHelpers.cs" LinkBase="Shared" />
Expand Down