diff --git a/eng/CodeGeneration.targets b/eng/CodeGeneration.targets index d0b2857a979f..2b01d61a5836 100644 --- a/eng/CodeGeneration.targets +++ b/eng/CodeGeneration.targets @@ -3,7 +3,7 @@ <_AutoRestVersion>https://github.com/Azure/autorest/releases/download/autorest-3.0.6236/autorest-3.0.6236.tgz <_AutoRestCoreVersion>3.0.6306 - <_AutoRestCSharpVersion>https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200911.1/autorest-csharp-v3-3.0.0-dev.20200911.1.tgz + <_AutoRestCSharpVersion>https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200811.1/autorest-csharp-v3-3.0.0-dev.20200811.1.tgz <_SupportsCodeGeneration Condition="'$(IsClientLibrary)' == 'true'">true <_DefaultInputName Condition="Exists('$(MSBuildProjectDirectory)/autorest.md')">$(MSBuildProjectDirectory)/autorest.md $(_DefaultInputName) @@ -12,16 +12,11 @@ use the following command line (remove the space between minus minus): dotnet msbuild /t:GenerateCode /p:AutoRestAdditionalParameters="- -interactive" --> - <_SharedCodeDirectory>$(MSBuildThisFileDirectory)../sdk/core/Azure.Core/src/Shared/ - <_AutoRestSharedCodeDirectory>$(_SharedCodeDirectory)AutoRest/ <_GenerateCode Condition="'$(_SupportsCodeGeneration)' == 'true' AND '$(AutoRestInput)' != ''">true - <_AutoRestVersion Condition="'$(TemporaryUsePreviousGeneratorVersion)' == 'true'">https://github.com/Azure/autorest/releases/download/autorest-3.0.6236/autorest-3.0.6236.tgz - <_AutoRestCoreVersion Condition="'$(TemporaryUsePreviousGeneratorVersion)' == 'true'">3.0.6306 - <_AutoRestCSharpVersion Condition="'$(TemporaryUsePreviousGeneratorVersion)' == 'true'">https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200811.1/autorest-csharp-v3-3.0.0-dev.20200811.1.tgz @@ -38,17 +33,9 @@ - + - - $(NoWarn);CA1812 - - - - - - diff --git a/eng/Directory.Build.Data.props b/eng/Directory.Build.Data.props index beac9ee03593..4c8aa548c2af 100644 --- a/eng/Directory.Build.Data.props +++ b/eng/Directory.Build.Data.props @@ -152,4 +152,12 @@ + + + + + $(AzureCoreSharedSources) + + false + diff --git a/eng/Directory.Build.Data.targets b/eng/Directory.Build.Data.targets index 38e61536e99b..80dc8df79ed1 100644 --- a/eng/Directory.Build.Data.targets +++ b/eng/Directory.Build.Data.targets @@ -50,8 +50,10 @@ - + + + @@ -103,7 +105,7 @@ - + diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index 9656920f9bb2..273b7ce67d5b 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -9,6 +9,7 @@ + diff --git a/eng/scripts/CodeChecks.ps1 b/eng/scripts/CodeChecks.ps1 index 6484a926bc44..15f16e61759b 100644 --- a/eng/scripts/CodeChecks.ps1 +++ b/eng/scripts/CodeChecks.ps1 @@ -72,7 +72,7 @@ try { Write-Host "Re-generating clients" Invoke-Block { - & dotnet msbuild $PSScriptRoot\..\service.proj /t:GenerateCode /p:ServiceDirectory=$ServiceDirectory + & dotnet msbuild $PSScriptRoot\..\service.proj /restore /t:GenerateCode /p:ServiceDirectory=$ServiceDirectory # https://github.com/Azure/azure-sdk-for-net/issues/8584 # & $repoRoot\storage\generate.ps1 diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ArmOperationHelpers.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ArmOperationHelpers.cs deleted file mode 100644 index 8298a74099f4..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ArmOperationHelpers.cs +++ /dev/null @@ -1,359 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Linq; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core.Pipeline; - -namespace Azure.Core -{ - /// - /// This implements the ARM scenarios for LROs. It is highly recommended to read the ARM spec prior to modifying this code: - /// https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/Addendum.md#asynchronous-operations - /// Other reference documents include: - /// https://github.com/Azure/autorest/blob/master/docs/extensions/readme.md#x-ms-long-running-operation - /// https://github.com/Azure/adx-documentation-pr/blob/master/sdks/LRO/LRO_AzureSDK.md - /// - /// The final result of the LRO. - internal class ArmOperationHelpers - { - public static TimeSpan DefaultPollingInterval { get; } = TimeSpan.FromSeconds(1); - - private static readonly string[] s_failureStates = {"failed", "canceled"}; - private static readonly string[] s_terminalStates = {"succeeded", "failed", "canceled"}; - - private readonly HttpPipeline _pipeline; - private readonly ClientDiagnostics _clientDiagnostics; - private readonly string _scopeName; - private readonly RequestMethod _requestMethod; - private readonly string _originalUri; - private readonly OperationFinalStateVia _finalStateVia; - private HeaderFrom _headerFrom; - private string _pollUri = default!; - private bool _originalHasLocation; - private string? _lastKnownLocation; - - private readonly IOperationSource _source; - private Response _rawResponse; - private T _value = default!; - private bool _hasValue; - private bool _hasCompleted; - private bool _shouldPoll; - - public ArmOperationHelpers( - IOperationSource source, - ClientDiagnostics clientDiagnostics, - HttpPipeline pipeline, - Request originalRequest, - Response originalResponse, - OperationFinalStateVia finalStateVia, - string scopeName) - { - _source = source; - _rawResponse = originalResponse; - _requestMethod = originalRequest.Method; - _originalUri = originalRequest.Uri.ToString(); - _finalStateVia = finalStateVia; - InitializeScenarioInfo(); - - _pipeline = pipeline; - _clientDiagnostics = clientDiagnostics; - _scopeName = scopeName; - // When the original response has no headers, we do not start polling immediately. - _shouldPoll = _headerFrom != HeaderFrom.None; - } - - public Response GetRawResponse() => _rawResponse; - - public ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) - { - return WaitForCompletionAsync(DefaultPollingInterval, cancellationToken); - } - - public async ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) - { - while (true) - { - await UpdateStatusAsync(cancellationToken).ConfigureAwait(false); - if (HasCompleted) - { - return Response.FromValue(Value, GetRawResponse()); - } - - await Task.Delay(pollingInterval, cancellationToken).ConfigureAwait(false); - } - } - - private async ValueTask UpdateStatusAsync(bool async, CancellationToken cancellationToken) - { - if (_hasCompleted) - { - return GetRawResponse(); - } - - if (_shouldPoll) - { - UpdatePollUri(); - _rawResponse = async - ? await GetResponseAsync(_pollUri, cancellationToken).ConfigureAwait(false) - : GetResponse(_pollUri, cancellationToken); - } - - _shouldPoll = true; - _hasCompleted = IsTerminalState(out string state); - if (_hasCompleted) - { - Response finalResponse = GetRawResponse(); - if (s_failureStates.Contains(state)) - { - throw _clientDiagnostics.CreateRequestFailedException(finalResponse); - } - - string? finalUri = GetFinalUri(); - if (finalUri != null) - { - finalResponse = async - ? await GetResponseAsync(finalUri, cancellationToken).ConfigureAwait(false) - : GetResponse(finalUri, cancellationToken); - } - - switch (finalResponse.Status) - { - case 200: - case 201 when _requestMethod == RequestMethod.Put: - case 204 when !(_requestMethod == RequestMethod.Put || _requestMethod == RequestMethod.Patch): - { - _value = async - ? await _source.CreateResultAsync(finalResponse, cancellationToken).ConfigureAwait(false) - : _source.CreateResult(finalResponse, cancellationToken); - _rawResponse = finalResponse; - _hasValue = true; - break; - } - default: - throw _clientDiagnostics.CreateRequestFailedException(finalResponse); - } - } - - return GetRawResponse(); - } - - public async ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => await UpdateStatusAsync(async: true, cancellationToken).ConfigureAwait(false); - - public Response UpdateStatus(CancellationToken cancellationToken = default) => UpdateStatusAsync(async: false, cancellationToken).EnsureCompleted(); - -#pragma warning disable CA1822 - //TODO: This is currently unused. - public string Id => throw new NotImplementedException(); -#pragma warning restore CA1822 - - public T Value - { - get - { - if (!HasValue) - { - throw new InvalidOperationException("The operation has not completed yet."); - } - - return _value; - } - } - - public bool HasCompleted => _hasCompleted; - public bool HasValue => _hasValue; - - private HttpMessage CreateRequest(string link) - { - HttpMessage message = _pipeline.CreateMessage(); - Request request = message.Request; - request.Method = RequestMethod.Get; - request.Uri.Reset(new Uri(link)); - return message; - } - - private async ValueTask GetResponseAsync(string link, CancellationToken cancellationToken = default) - { - if (link == null) - { - throw new ArgumentNullException(nameof(link)); - } - - using DiagnosticScope scope = _clientDiagnostics.CreateScope(_scopeName); - scope.Start(); - try - { - using HttpMessage message = CreateRequest(link); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - return message.Response; - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - private Response GetResponse(string link, CancellationToken cancellationToken = default) - { - if (link == null) - { - throw new ArgumentNullException(nameof(link)); - } - - using DiagnosticScope scope = _clientDiagnostics.CreateScope(_scopeName); - scope.Start(); - try - { - using HttpMessage message = CreateRequest(link); - _pipeline.Send(message, cancellationToken); - return message.Response; - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - private bool IsTerminalState(out string state) - { - Response response = GetRawResponse(); - state = string.Empty; - if (_headerFrom == HeaderFrom.Location) - { - return response.Status != 202; - } - - if (response.Status >= 200 && response.Status <= 204) - { - if (response.ContentStream?.Length > 0) - { - try - { - using JsonDocument document = JsonDocument.Parse(response.ContentStream); - foreach (JsonProperty property in document.RootElement.EnumerateObject()) - { - if ((_headerFrom == HeaderFrom.OperationLocation || - _headerFrom == HeaderFrom.AzureAsyncOperation) && - property.NameEquals("status")) - { - state = property.Value.GetString().ToLowerInvariant(); - return s_terminalStates.Contains(state); - } - - if (_headerFrom == HeaderFrom.None && property.NameEquals("properties")) - { - foreach (JsonProperty innerProperty in property.Value.EnumerateObject()) - { - if (innerProperty.NameEquals("provisioningState")) - { - state = innerProperty.Value.GetString().ToLowerInvariant(); - return s_terminalStates.Contains(state); - } - } - } - } - } - finally - { - // It is required to reset the position of the content after reading as this response may be used for deserialization. - response.ContentStream.Position = 0; - } - } - - // If provisioningState was not found, it defaults to Succeeded. - if (_headerFrom == HeaderFrom.None) - { - return true; - } - } - - throw _clientDiagnostics.CreateRequestFailedException(response); - } - - private enum HeaderFrom - { - None, - OperationLocation, - AzureAsyncOperation, - Location - } - - private void InitializeScenarioInfo() - { - _originalHasLocation = _rawResponse.Headers.Contains("Location"); - - if (_rawResponse.Headers.Contains("Operation-Location")) - { - _headerFrom = HeaderFrom.OperationLocation; - return; - } - - if (_rawResponse.Headers.Contains("Azure-AsyncOperation")) - { - _headerFrom = HeaderFrom.AzureAsyncOperation; - return; - } - - if (_originalHasLocation) - { - _headerFrom = HeaderFrom.Location; - return; - } - - _pollUri = _originalUri; - _headerFrom = HeaderFrom.None; - } - - private void UpdatePollUri() - { - var hasLocation = _rawResponse.Headers.TryGetValue("Location", out string? location); - if (hasLocation) - { - _lastKnownLocation = location; - } - - switch (_headerFrom) - { - case HeaderFrom.OperationLocation when _rawResponse.Headers.TryGetValue("Operation-Location", out string? operationLocation): - _pollUri = operationLocation; - return; - case HeaderFrom.AzureAsyncOperation when _rawResponse.Headers.TryGetValue("Azure-AsyncOperation", out string? azureAsyncOperation): - _pollUri = azureAsyncOperation; - return; - case HeaderFrom.Location when hasLocation: - _pollUri = location!; - return; - } - } - - private string? GetFinalUri() - { - if (_headerFrom == HeaderFrom.OperationLocation || _headerFrom == HeaderFrom.AzureAsyncOperation) - { - if (_requestMethod == RequestMethod.Delete) - { - return null; - } - - if (_requestMethod == RequestMethod.Put || (_originalHasLocation && _finalStateVia == OperationFinalStateVia.OriginalUri)) - { - return _originalUri; - } - - if (_originalHasLocation && _finalStateVia == OperationFinalStateVia.Location) - { - return _lastKnownLocation; - } - } - - return null; - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingDictionary.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingDictionary.cs deleted file mode 100644 index 909b30872232..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingDictionary.cs +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections; -using System.Collections.Generic; - -#nullable enable - -namespace Azure.Core -{ - internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey: notnull - { - private IDictionary? _innerDictionary; - - public ChangeTrackingDictionary() - { - } - - public ChangeTrackingDictionary(Optional> optionalDictionary) : this(optionalDictionary.Value) - { - } - - public ChangeTrackingDictionary(Optional> optionalDictionary) : this(optionalDictionary.Value) - { - } - - private ChangeTrackingDictionary(IDictionary dictionary) - { - if (dictionary == null) return; - - _innerDictionary = new Dictionary(dictionary); - } - - private ChangeTrackingDictionary(IReadOnlyDictionary dictionary) - { - if (dictionary == null) return; - - _innerDictionary = new Dictionary(); - foreach (KeyValuePair pair in dictionary) - { - _innerDictionary.Add(pair); - } - } - - public bool IsUndefined => _innerDictionary == null; - - public IEnumerator> GetEnumerator() - { - if (IsUndefined) - { - IEnumerator> GetEmptyEnumerator() - { - yield break; - } - return GetEmptyEnumerator(); - } - return EnsureDictionary().GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public void Add(KeyValuePair item) - { - EnsureDictionary().Add(item); - } - - public void Clear() - { - EnsureDictionary().Clear(); - } - - public bool Contains(KeyValuePair item) - { - if (IsUndefined) - { - return false; - } - - return EnsureDictionary().Contains(item); - } - - public void CopyTo(KeyValuePair[] array, int arrayIndex) - { - if (IsUndefined) - { - return; - } - - EnsureDictionary().CopyTo(array, arrayIndex); - } - - public bool Remove(KeyValuePair item) - { - if (IsUndefined) - { - return false; - } - - return EnsureDictionary().Remove(item); - } - - public int Count - { - get - { - if (IsUndefined) - { - return 0; - } - - return EnsureDictionary().Count; - } - } - - public bool IsReadOnly - { - get - { - if (IsUndefined) - { - return false; - } - return EnsureDictionary().IsReadOnly; - } - } - - public void Add(TKey key, TValue value) - { - EnsureDictionary().Add(key, value); - } - - public bool ContainsKey(TKey key) - { - if (IsUndefined) - { - return false; - } - - return EnsureDictionary().ContainsKey(key); - } - - public bool Remove(TKey key) - { - if (IsUndefined) - { - return false; - } - - return EnsureDictionary().Remove(key); - } - - public bool TryGetValue(TKey key, out TValue value) - { - if (IsUndefined) - { - value = default!; - return false; - } - return EnsureDictionary().TryGetValue(key, out value); - } - - public TValue this[TKey key] - { - get - { - if (IsUndefined) - { - throw new KeyNotFoundException(nameof(key)); - } - - return EnsureDictionary()[key]; - } - set => EnsureDictionary()[key] = value; - } - - IEnumerable IReadOnlyDictionary.Keys => Keys; - - IEnumerable IReadOnlyDictionary.Values => Values; - - public ICollection Keys - { - get - { - if (IsUndefined) - { - return Array.Empty(); - } - - return EnsureDictionary().Keys; - } - } - - public ICollection Values - { - get - { - if (IsUndefined) - { - return Array.Empty(); - } - - return EnsureDictionary().Values; - } - } - - private IDictionary EnsureDictionary() - { - return _innerDictionary ??= new Dictionary(); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingList.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingList.cs deleted file mode 100644 index d39f21d305db..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ChangeTrackingList.cs +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -#nullable enable - -namespace Azure.Core -{ - internal class ChangeTrackingList: IList, IReadOnlyList - { - private IList? _innerList; - - public ChangeTrackingList() - { - } - - public ChangeTrackingList(Optional> optionalList) : this(optionalList.Value) - { - } - - public ChangeTrackingList(Optional> optionalList) : this(optionalList.Value) - { - } - - private ChangeTrackingList(IEnumerable innerList) - { - if (innerList == null) - { - return; - } - - _innerList = innerList.ToList(); - } - - private ChangeTrackingList(IList innerList) - { - if (innerList == null) - { - return; - } - - _innerList = innerList; - } - - public bool IsUndefined => _innerList == null; - - public void Reset() - { - _innerList = null; - } - - public IEnumerator GetEnumerator() - { - if (IsUndefined) - { - IEnumerator EnumerateEmpty() - { - yield break; - } - - return EnumerateEmpty(); - } - return EnsureList().GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public void Add(T item) - { - EnsureList().Add(item); - } - - public void Clear() - { - EnsureList().Clear(); - } - - public bool Contains(T item) - { - if (IsUndefined) - { - return false; - } - - return EnsureList().Contains(item); - } - - public void CopyTo(T[] array, int arrayIndex) - { - if (IsUndefined) - { - return; - } - - EnsureList().CopyTo(array, arrayIndex); - } - - public bool Remove(T item) - { - if (IsUndefined) - { - return false; - } - - return EnsureList().Remove(item); - } - - public int Count - { - get - { - if (IsUndefined) - { - return 0; - } - return EnsureList().Count; - } - } - - public bool IsReadOnly - { - get - { - if (IsUndefined) - { - return false; - } - - return EnsureList().IsReadOnly; - } - } - - public int IndexOf(T item) - { - if (IsUndefined) - { - return -1; - } - - return EnsureList().IndexOf(item); - } - - public void Insert(int index, T item) - { - EnsureList().Insert(index, item); - } - - public void RemoveAt(int index) - { - if (IsUndefined) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - EnsureList().RemoveAt(index); - } - - public T this[int index] - { - get - { - if (IsUndefined) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - return EnsureList()[index]; - } - set - { - if (IsUndefined) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - EnsureList()[index] = value; - } - } - - private IList EnsureList() - { - return _innerList ??= new List(); - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenClientAttribute.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenClientAttribute.cs deleted file mode 100644 index 522ee46691d4..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenClientAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; - -namespace Azure.Core -{ - [AttributeUsage(AttributeTargets.Class)] - internal class CodeGenClientAttribute : CodeGenTypeAttribute - { - public CodeGenClientAttribute(string originalName) : base(originalName) - { - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenMemberAttribute.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenMemberAttribute.cs deleted file mode 100644 index 50c57d56ca42..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenMemberAttribute.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; - -namespace Azure.Core -{ - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - internal class CodeGenMemberAttribute : CodeGenTypeAttribute - { - public CodeGenMemberAttribute() : base(null) - { - } - - public CodeGenMemberAttribute(string originalName) : base(originalName) - { - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenModelAttribute.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenModelAttribute.cs deleted file mode 100644 index 4b04d68bb8a8..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenModelAttribute.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; - -namespace Azure.Core -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct)] - internal class CodeGenModelAttribute : CodeGenTypeAttribute - { - /// - /// Gets or sets a coma separated list of additional model usage modes. Allowed values: model, error, intput, output. - /// - public string[]? Usage { get; set; } - - /// - /// Gets or sets a coma separated list of additional model serialization formats. - /// - public string[]? Formats { get; set; } - - public CodeGenModelAttribute() : base(null) - { - } - - public CodeGenModelAttribute(string originalName): base(originalName) - { - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenSuppressAttribute.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenSuppressAttribute.cs deleted file mode 100644 index efb2c82f864e..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenSuppressAttribute.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; - -namespace Azure.Core -{ - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct, AllowMultiple = true)] - internal class CodeGenSuppressAttribute : Attribute - { - public string Member { get; } - public Type[] Parameters { get; } - - public CodeGenSuppressAttribute(string member, params Type[] parameters) - { - Member = member; - Parameters = parameters; - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenTypeAttribute.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenTypeAttribute.cs deleted file mode 100644 index 08095da55db6..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/CodeGenTypeAttribute.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; - -namespace Azure.Core -{ - [AttributeUsage(AttributeTargets.Class)] - internal class CodeGenTypeAttribute : Attribute - { - public string? OriginalName { get; } - - public CodeGenTypeAttribute(string? originalName) - { - OriginalName = originalName; - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/IOperationSource.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/IOperationSource.cs deleted file mode 100644 index a7b779100063..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/IOperationSource.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.Core -{ - internal interface IOperationSource - { - T CreateResult(Response response, CancellationToken cancellationToken); - ValueTask CreateResultAsync(Response response, CancellationToken cancellationToken); - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/IUtf8JsonSerializable.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/IUtf8JsonSerializable.cs deleted file mode 100644 index 5653e4609313..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/IUtf8JsonSerializable.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System.Text.Json; - -namespace Azure.Core -{ - internal interface IUtf8JsonSerializable - { - void Write(Utf8JsonWriter writer); - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/IXmlSerializable.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/IXmlSerializable.cs deleted file mode 100644 index 343b127384d2..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/IXmlSerializable.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System.Xml; - -namespace Azure.Core -{ - internal interface IXmlSerializable - { - void Write(XmlWriter writer, string? nameHint); - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/JsonElementExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/JsonElementExtensions.cs deleted file mode 100644 index 9b5efa3e00c0..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/JsonElementExtensions.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text.Json; -using System.Xml; - -namespace Azure.Core -{ - internal static class JsonElementExtensions - { - public static object? GetObject(in this JsonElement element) - { - switch (element.ValueKind) - { - case JsonValueKind.String: - return element.GetString(); - case JsonValueKind.Number: - if (element.TryGetInt32(out int intValue)) - { - return intValue; - } - if (element.TryGetInt64(out long longValue)) - { - return longValue; - } - return element.GetDouble(); - case JsonValueKind.True: - return true; - case JsonValueKind.False: - return false; - case JsonValueKind.Undefined: - case JsonValueKind.Null: - return null; - case JsonValueKind.Object: - var dictionary = new Dictionary(); - foreach (JsonProperty jsonProperty in element.EnumerateObject()) - { - dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); - } - return dictionary; - case JsonValueKind.Array: - var list = new List(); - foreach (JsonElement item in element.EnumerateArray()) - { - list.Add(item.GetObject()); - } - return list.ToArray(); - default: - throw new NotSupportedException("Not supported value kind " + element.ValueKind); - } - } - - public static byte[] GetBytesFromBase64(in this JsonElement element, string format) => format switch - { - "U" => TypeFormatters.FromBase64UrlString(element.GetString()), - _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) - }; - - public static DateTimeOffset GetDateTimeOffset(in this JsonElement element, string format) => format switch - { - "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), - _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) - }; - - public static TimeSpan GetTimeSpan(in this JsonElement element, string format) => - TypeFormatters.ParseTimeSpan(element.GetString(), format); - - public static char GetChar(this in JsonElement element) - { - if (element.ValueKind == JsonValueKind.String) - { - var text = element.GetString(); - if (text == null || text.Length != 1) - { - throw new NotSupportedException($"Cannot convert \"{text}\" to a Char"); - } - return text[0]; - } - else - { - throw new NotSupportedException($"Cannot convert {element.ValueKind} to a Char"); - } - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ManagementPipelineBuilder.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ManagementPipelineBuilder.cs deleted file mode 100644 index 4c0b41167bdf..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ManagementPipelineBuilder.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text.Json; -using System.Xml; -using Azure.Core.Pipeline; - -namespace Azure.Core -{ - internal static class ManagementPipelineBuilder - { - public static HttpPipeline Build(TokenCredential credential, Uri endpoint, ClientOptions options) - { - return HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(credential, $"{endpoint}/.default")); - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/OperationFinalStateVia.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/OperationFinalStateVia.cs deleted file mode 100644 index 6b6c2771e5a1..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/OperationFinalStateVia.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -namespace Azure.Core -{ - internal enum OperationFinalStateVia - { - AzureAsyncOperation, - Location, - OriginalUri - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/Optional.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/Optional.cs deleted file mode 100644 index cc17f461cb48..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/Optional.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable disable - -using System.Collections.Generic; -using System.Linq; - -namespace Azure.Core -{ - internal static class Optional - { - public static bool IsCollectionDefined(IEnumerable collection) - { - return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); - } - - public static bool IsCollectionDefined(IReadOnlyDictionary collection) - { - return !(collection is ChangeTrackingDictionary changeTrackingList && changeTrackingList.IsUndefined); - } - - public static bool IsCollectionDefined(IDictionary collection) - { - return !(collection is ChangeTrackingDictionary changeTrackingList && changeTrackingList.IsUndefined); - } - - public static bool IsDefined(T? value) where T: struct - { - return value.HasValue; - } - public static bool IsDefined(object value) - { - return value != null; - } - public static bool IsDefined(string value) - { - return value != null; - } - - public static IReadOnlyDictionary ToDictionary(Optional> optional) - { - if (optional.HasValue) - { - return optional.Value; - } - return new ChangeTrackingDictionary(optional); - } - - public static IDictionary ToDictionary(Optional> optional) - { - if (optional.HasValue) - { - return optional.Value; - } - return new ChangeTrackingDictionary(optional); - } - public static IReadOnlyList ToList(Optional> optional) - { - if (optional.HasValue) - { - return optional.Value; - } - return new ChangeTrackingList(optional); - } - - public static IList ToList(Optional> optional) - { - if (optional.HasValue) - { - return optional.Value; - } - return new ChangeTrackingList(optional); - } - - public static T? ToNullable(Optional optional) where T: struct - { - if (optional.HasValue) - { - return optional.Value; - } - return default; - } - - public static T? ToNullable(Optional optional) where T: struct - { - return optional.Value; - } - } - - internal readonly partial struct Optional - { - public Optional(T value) : this() - { - Value = value; - HasValue = true; - } - - public T Value { get; } - public bool HasValue { get; } - - public static implicit operator Optional(T value) => new Optional(value); - public static implicit operator T(Optional optional) => optional.Value; - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/Page.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/Page.cs deleted file mode 100644 index 1438fdfd5f04..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/Page.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System.Collections.Generic; -using System.Linq; - -namespace Azure.Core -{ - internal static class Page - { - public static Page FromValues(IEnumerable values, string continuationToken, Response response) => - Page.FromValues(values.ToList(), continuationToken, response); - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/PageableHelpers.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/PageableHelpers.cs deleted file mode 100644 index a0ea80ba24d2..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/PageableHelpers.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Azure.Core -{ - internal static class PageableHelpers - { - public static Pageable CreateEnumerable(Func> firstPageFunc, Func>? nextPageFunc, int? pageSize = default) where T : notnull - { - PageFunc first = (continuationToken, pageSizeHint) => firstPageFunc(pageSizeHint); - PageFunc? next = nextPageFunc != null ? new PageFunc(nextPageFunc) : null; - return new FuncPageable(first, next, pageSize); - } - - public static AsyncPageable CreateAsyncEnumerable(Func>> firstPageFunc, Func>>? nextPageFunc, int? pageSize = default) where T : notnull - { - AsyncPageFunc first = (continuationToken, pageSizeHint) => firstPageFunc(pageSizeHint); - AsyncPageFunc? next = nextPageFunc != null ? new AsyncPageFunc(nextPageFunc) : null; - return new FuncAsyncPageable(first, next, pageSize); - } - - internal delegate Task> AsyncPageFunc(string? continuationToken = default, int? pageSizeHint = default); - internal delegate Page PageFunc(string? continuationToken = default, int? pageSizeHint = default); - - internal class FuncAsyncPageable : AsyncPageable where T : notnull - { - private readonly AsyncPageFunc _firstPageFunc; - private readonly AsyncPageFunc? _nextPageFunc; - private readonly int? _defaultPageSize; - - public FuncAsyncPageable(AsyncPageFunc firstPageFunc, AsyncPageFunc? nextPageFunc, int? defaultPageSize = default) - { - _firstPageFunc = firstPageFunc; - _nextPageFunc = nextPageFunc; - _defaultPageSize = defaultPageSize; - } - - public override async IAsyncEnumerable> AsPages(string? continuationToken = default, int? pageSizeHint = default) - { - AsyncPageFunc? pageFunc = string.IsNullOrEmpty(continuationToken) ? _firstPageFunc : _nextPageFunc; - - if (pageFunc == null) - { - yield break; - } - - int? pageSize = pageSizeHint ?? _defaultPageSize; - do - { - Page pageResponse = await pageFunc(continuationToken, pageSize).ConfigureAwait(false); - yield return pageResponse; - continuationToken = pageResponse.ContinuationToken; - pageFunc = _nextPageFunc; - } while (!string.IsNullOrEmpty(continuationToken) && pageFunc != null); - } - } - - internal class FuncPageable : Pageable where T : notnull - { - private readonly PageFunc _firstPageFunc; - private readonly PageFunc? _nextPageFunc; - private readonly int? _defaultPageSize; - - public FuncPageable(PageFunc firstPageFunc, PageFunc? nextPageFunc, int? defaultPageSize = default) - { - _firstPageFunc = firstPageFunc; - _nextPageFunc = nextPageFunc; - _defaultPageSize = defaultPageSize; - } - - public override IEnumerable> AsPages(string? continuationToken = default, int? pageSizeHint = default) - { - PageFunc? pageFunc = string.IsNullOrEmpty(continuationToken) ? _firstPageFunc : _nextPageFunc; - - if (pageFunc == null) - { - yield break; - } - - int? pageSize = pageSizeHint ?? _defaultPageSize; - do - { - Page pageResponse = pageFunc(continuationToken, pageSize); - yield return pageResponse; - continuationToken = pageResponse.ContinuationToken; - pageFunc = _nextPageFunc; - } while (!string.IsNullOrEmpty(continuationToken) && pageFunc != null); - } - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/RawRequestUriBuilder.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/RawRequestUriBuilder.cs deleted file mode 100644 index c77b4b72ef7b..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/RawRequestUriBuilder.cs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Globalization; - -namespace Azure.Core -{ - internal class RawRequestUriBuilder: RequestUriBuilder - { - private const string SchemeSeparator = "://"; - private const char HostSeparator = '/'; - private const char PortSeparator = ':'; - private static readonly char[] HostOrPort = { HostSeparator, PortSeparator }; - private const char QueryBeginSeparator = '?'; - private const char QueryContinueSeparator = '&'; - private const char QueryValueSeparator = '='; - - private RawWritingPosition? _position; - - private static (string Name, string Value) GetQueryParts(string queryUnparsed) - { - int separatorIndex = queryUnparsed.IndexOf(QueryValueSeparator); - if (separatorIndex == -1) - { - return (queryUnparsed, string.Empty); - } - return (queryUnparsed.Substring(0, separatorIndex), queryUnparsed.Substring(separatorIndex + 1)); - } - - public void AppendRaw(string value, bool escape) - { - if (_position == null) - { - if (!string.IsNullOrEmpty(Query)) - { - _position = RawWritingPosition.Query; - } - else if (!string.IsNullOrEmpty(Path)) - { - _position = RawWritingPosition.Path; - } - else if (!string.IsNullOrEmpty(Host)) - { - _position = RawWritingPosition.Host; - } - else - { - _position = RawWritingPosition.Scheme; - } - } - while (!string.IsNullOrWhiteSpace(value)) - { - if (_position == RawWritingPosition.Scheme) - { - int separator = value.IndexOf(SchemeSeparator, StringComparison.InvariantCultureIgnoreCase); - if (separator == -1) - { - Scheme += value; - value = string.Empty; - } - else - { - Scheme += value.Substring(0, separator); - // TODO: Find a better way to map schemes to default ports - Port = string.Equals(Scheme, "https", StringComparison.OrdinalIgnoreCase) ? 443 : 80; - value = value.Substring(separator + SchemeSeparator.Length); - _position = RawWritingPosition.Host; - } - } - else if (_position == RawWritingPosition.Host) - { - int separator = value.IndexOfAny(HostOrPort); - if (separator == -1) - { - if (string.IsNullOrEmpty(Path)) - { - Host += value; - value = string.Empty; - } - else - { - // All Host information must be written before Path information - // If Path already has information, we transition to writing Path - _position = RawWritingPosition.Path; - } - } - else - { - Host += value.Substring(0, separator); - _position = value[separator] == HostSeparator ? RawWritingPosition.Path : RawWritingPosition.Port; - value = value.Substring(separator + 1); - } - } - else if (_position == RawWritingPosition.Port) - { - int separator = value.IndexOf(HostSeparator); - if (separator == -1) - { - Port = int.Parse(value, CultureInfo.InvariantCulture); - value = string.Empty; - } - else - { - Port = int.Parse(value.Substring(0, separator), CultureInfo.InvariantCulture); - value = value.Substring(separator + 1); - } - // Port cannot be split (like Host), so always transition to Path when Port is parsed - _position = RawWritingPosition.Path; - } - else if (_position == RawWritingPosition.Path) - { - int separator = value.IndexOf(QueryBeginSeparator); - if (separator == -1) - { - AppendPath(value, escape); - value = string.Empty; - } - else - { - AppendPath(value.Substring(0, separator), escape); - value = value.Substring(separator + 1); - _position = RawWritingPosition.Query; - } - } - else if (_position == RawWritingPosition.Query) - { - int separator = value.IndexOf(QueryContinueSeparator); - if (separator == 0) - { - value = value.Substring(1); - } - else if (separator == -1) - { - (string queryName, string queryValue) = GetQueryParts(value); - AppendQuery(queryName, queryValue, escape); - value = string.Empty; - } - else - { - (string queryName, string queryValue) = GetQueryParts(value.Substring(0, separator)); - AppendQuery(queryName, queryValue, escape); - value = value.Substring(separator + 1); - } - } - } - } - - private enum RawWritingPosition - { - Scheme, - Host, - Port, - Path, - Query - } - - public void AppendRawNextLink(string nextLink, bool escape) - { - // If it is an absolute link, we use the nextLink as the entire url - if (nextLink.StartsWith(Uri.UriSchemeHttp, StringComparison.InvariantCultureIgnoreCase)) - { - Reset(new Uri(nextLink)); - return; - } - - AppendRaw(nextLink, escape); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/RequestHeaderExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/RequestHeaderExtensions.cs deleted file mode 100644 index 5417f05ecc62..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/RequestHeaderExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Globalization; - -namespace Azure.Core -{ - internal static class RequestHeaderExtensions - { - public static void Add(this RequestHeaders headers, string name, bool value) - { - headers.Add(name, TypeFormatters.ToString(value)); - } - - public static void Add(this RequestHeaders headers, string name, float value) - { - headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture)); - } - - public static void Add(this RequestHeaders headers, string name, double value) - { - headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture)); - } - - public static void Add(this RequestHeaders headers, string name, int value) - { - headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture)); - } - - public static void Add(this RequestHeaders headers, string name, DateTimeOffset value, string format) - { - headers.Add(name, TypeFormatters.ToString(value, format)); - } - - public static void Add(this RequestHeaders headers, string name, TimeSpan value, string format) - { - headers.Add(name, TypeFormatters.ToString(value, format)); - } - - public static void Add(this RequestHeaders headers, string name, Guid value) - { - headers.Add(name, value.ToString()); - } - - public static void Add(this RequestHeaders headers, string name, byte[] value) - { - headers.Add(name, Convert.ToBase64String(value)); - } - - public static void AddDelimited(this RequestHeaders headers, string name, IEnumerable value, string delimiter) - { - headers.Add(name, string.Join(delimiter, value)); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/RequestUriBuilderExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/RequestUriBuilderExtensions.cs deleted file mode 100644 index 5b43df070308..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/RequestUriBuilderExtensions.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Xml; - -namespace Azure.Core -{ - internal static class RequestUriBuilderExtensions - { - public static void AppendPath(this RequestUriBuilder builder, bool value, bool escape = false) - { - builder.AppendPath(TypeFormatters.ToString(value), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, float value, bool escape = true) - { - builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, double value, bool escape = true) - { - builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, int value, bool escape = true) - { - builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, byte[] value, bool escape = true) - { - builder.AppendPath(TypeFormatters.ToBase64UrlString(value), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, IEnumerable value, bool escape = true) - { - builder.AppendPath(string.Join(",", value), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, DateTimeOffset value, string format, bool escape = true) - { - builder.AppendPath(TypeFormatters.ToString(value, format), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, TimeSpan value, string format, bool escape = true) - { - builder.AppendPath(TypeFormatters.ToString(value, format), escape); - } - - public static void AppendPath(this RequestUriBuilder builder, Guid value, bool escape = true) - { - builder.AppendPath(value.ToString(), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, bool value, bool escape = false) - { - builder.AppendQuery(name, TypeFormatters.ToString(value), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, float value, bool escape = true) - { - builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, DateTimeOffset value, string format, bool escape = true) - { - builder.AppendQuery(name, TypeFormatters.ToString(value, format), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, TimeSpan value, string format, bool escape = true) - { - builder.AppendQuery(name, TypeFormatters.ToString(value, format), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, double value, bool escape = true) - { - builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, int value, bool escape = true) - { - builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, TimeSpan value, bool escape = true) - { - builder.AppendQuery(name, XmlConvert.ToString(value), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, byte[] value, bool escape = true) - { - builder.AppendQuery(name, Convert.ToBase64String(value), escape); - } - - public static void AppendQuery(this RequestUriBuilder builder, string name, Guid value, bool escape = true) - { - builder.AppendQuery(name, value.ToString(), escape); - } - - public static void AppendQueryDelimited(this RequestUriBuilder builder, string name, IEnumerable value, string delimiter, bool escape = true) - { - builder.AppendQuery(name, string.Join(delimiter, value), escape); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseHeadersExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseHeadersExtensions.cs deleted file mode 100644 index f54a1b41f743..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseHeadersExtensions.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Globalization; -using System.Xml; - -namespace Azure.Core -{ - internal static class ResponseHeadersExtensions - { - public static bool TryGetValue(this ResponseHeaders headers, string name, out byte[]? value) - { - if (headers.TryGetValue(name, out string? stringValue)) - { - value = Convert.FromBase64String(stringValue); - return true; - } - - value = null; - return false; - } - - public static bool TryGetValue(this ResponseHeaders headers, string name, out TimeSpan? value) - { - if (headers.TryGetValue(name, out string? stringValue)) - { - value = XmlConvert.ToTimeSpan(stringValue); - return true; - } - - value = null; - return false; - } - - public static bool TryGetValue(this ResponseHeaders headers, string name, out DateTimeOffset? value) - { - if (headers.TryGetValue(name, out string? stringValue)) - { - value = DateTimeOffset.Parse(stringValue, CultureInfo.InvariantCulture); - return true; - } - - value = null; - return false; - } - - public static bool TryGetValue(this ResponseHeaders headers, string name, out T? value) where T : struct - { - if (headers.TryGetValue(name, out string? stringValue)) - { - value = (T)Convert.ChangeType(stringValue, typeof(T), CultureInfo.InvariantCulture); - return true; - } - - value = null; - return false; - } - - public static bool TryGetValue(this ResponseHeaders headers, string name, out T? value) where T : class - { - if (headers.TryGetValue(name, out string? stringValue)) - { - value = (T)Convert.ChangeType(stringValue, typeof(T), CultureInfo.InvariantCulture); - return true; - } - - value = null; - return false; - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders.cs deleted file mode 100644 index 2a48fb0ebbfb..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -namespace Azure.Core -{ - internal static class ResponseWithHeaders - { - public static ResponseWithHeaders FromValue(T value, THeaders headers, Response rawResponse) - { - return new ResponseWithHeaders(value, headers, rawResponse); - } - - public static ResponseWithHeaders FromValue(THeaders headers, Response rawResponse) - { - return new ResponseWithHeaders(headers, rawResponse); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{T,THeaders}.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{T,THeaders}.cs deleted file mode 100644 index b8f16f46234c..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{T,THeaders}.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -namespace Azure.Core -{ - internal class ResponseWithHeaders : Response - { - private readonly Response _rawResponse; - - public ResponseWithHeaders(T value, THeaders headers, Response rawResponse) - { - _rawResponse = rawResponse; - Value = value; - Headers = headers; - } - - public override Response GetRawResponse() => _rawResponse; - - public override T Value { get; } - - public THeaders Headers { get; } - - public static implicit operator Response(ResponseWithHeaders self) => self.GetRawResponse(); - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{THeaders}.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{THeaders}.cs deleted file mode 100644 index d2c105aea021..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/ResponseWithHeaders{THeaders}.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -namespace Azure.Core -{ - internal class ResponseWithHeaders - { - private readonly Response _rawResponse; - - public ResponseWithHeaders(THeaders headers, Response rawResponse) - { - _rawResponse = rawResponse; - Headers = headers; - } - - public Response GetRawResponse() => _rawResponse; - - public THeaders Headers { get; } - - public static implicit operator Response(ResponseWithHeaders self) => self.GetRawResponse(); - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/StringRequestContent.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/StringRequestContent.cs deleted file mode 100644 index 8d1bcf33bd9e..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/StringRequestContent.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.IO; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.Core -{ - internal class StringRequestContent : RequestContent - { - private readonly byte[] _bytes; - - public StringRequestContent(string value) - { - _bytes = Encoding.UTF8.GetBytes(value); - } - - public override async Task WriteToAsync(Stream stream, CancellationToken cancellation) - { - await stream.WriteAsync(_bytes, 0, _bytes.Length, cancellation).ConfigureAwait(false); - } - - public override void WriteTo(Stream stream, CancellationToken cancellation) - { - stream.Write(_bytes, 0, _bytes.Length); - } - - public override bool TryComputeLength(out long length) - { - length = _bytes.Length; - return true; - } - - public override void Dispose() - { - } - } -} \ No newline at end of file diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/TypeFormatters.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/TypeFormatters.cs deleted file mode 100644 index d5422af4feaf..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/TypeFormatters.cs +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Diagnostics; -using System.Globalization; -using System.Xml; - -namespace Azure.Core -{ - internal class TypeFormatters - { - private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; - public static string DefaultNumberFormat { get; } = "G"; - - public static string ToString(bool value) => value ? "true" : "false"; - - public static string ToString(DateTimeOffset value, string format) => format switch - { - "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), - "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), - "O" when value.Offset == TimeSpan.Zero => value.ToString(RoundtripZFormat, CultureInfo.InvariantCulture), - "o" when value.Offset == TimeSpan.Zero => value.ToString(RoundtripZFormat, CultureInfo.InvariantCulture), - _ => value.ToString(format, CultureInfo.InvariantCulture) - }; - - public static string ToString(TimeSpan value, string format) => format switch - { - "P" => XmlConvert.ToString(value), - _ => value.ToString(format, CultureInfo.InvariantCulture) - }; - - public static string ToBase64UrlString(byte[] value) - { - var numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; - var size = checked(numWholeOrPartialInputBlocks * 4); - var output = new char[size]; - - var numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); - - // Fix up '+' -> '-' and '/' -> '_'. Drop padding characters. - int i = 0; - for (; i < numBase64Chars; i++) - { - var ch = output[i]; - if (ch == '+') - { - output[i] = '-'; - } - else if (ch == '/') - { - output[i] = '_'; - } - else if (ch == '=') - { - // We've reached a padding character; truncate the remainder. - break; - } - } - - return new string(output, 0, i); - } - - public static byte[] FromBase64UrlString(string value) - { - var paddingCharsToAdd = GetNumBase64PaddingCharsToAddForDecode(value.Length); - - var output = new char[value.Length + paddingCharsToAdd]; - - int i; - for (i = 0; i < value.Length; i++) - { - var ch = value[i]; - if (ch == '-') - { - output[i] = '+'; - } - else if (ch == '_') - { - output[i] = '/'; - } - else - { - output[i] = ch; - } - } - - for (; i < output.Length; i++) - { - output[i] = '='; - } - - return Convert.FromBase64CharArray(output, 0, output.Length); - } - - - private static int GetNumBase64PaddingCharsToAddForDecode(int inputLength) - { - switch (inputLength % 4) - { - case 0: - return 0; - case 2: - return 2; - case 3: - return 1; - default: - throw new InvalidOperationException("Malformed input"); - } - } - - public static DateTimeOffset ParseDateTimeOffset(string value, string format) - { - return format switch - { - "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), - _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) - }; - } - - public static TimeSpan ParseTimeSpan(string value, string format) => format switch - { - "P" => XmlConvert.ToTimeSpan(value), - _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) - }; - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonRequestContent.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonRequestContent.cs deleted file mode 100644 index 5f87a1385dc6..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonRequestContent.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System.IO; -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; - -namespace Azure.Core -{ - internal class Utf8JsonRequestContent: RequestContent - { - private readonly MemoryStream _stream; - private readonly RequestContent _content; - - public Utf8JsonWriter JsonWriter { get; } - - public Utf8JsonRequestContent() - { - _stream = new MemoryStream(); - _content = Create(_stream); - JsonWriter = new Utf8JsonWriter(_stream); - } - - public override async Task WriteToAsync(Stream stream, CancellationToken cancellation) - { - await JsonWriter.FlushAsync(cancellation).ConfigureAwait(false); - await _content.WriteToAsync(stream, cancellation).ConfigureAwait(false); - } - - public override void WriteTo(Stream stream, CancellationToken cancellation) - { - JsonWriter.Flush(); - _content.WriteTo(stream, cancellation); - } - - public override bool TryComputeLength(out long length) - { - length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; - return true; - } - - public override void Dispose() - { - JsonWriter.Dispose(); - _content.Dispose(); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonWriterExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonWriterExtensions.cs deleted file mode 100644 index d9ba5265e9a5..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/Utf8JsonWriterExtensions.cs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text.Json; - -namespace Azure.Core -{ - internal static class Utf8JsonWriterExtensions - { - public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) => - writer.WriteStringValue(TypeFormatters.ToString(value, format)); - - public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) => - writer.WriteStringValue(TypeFormatters.ToString(value, format)); - - public static void WriteStringValue(this Utf8JsonWriter writer, char value) => - writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); - - public static void WriteObjectValue(this Utf8JsonWriter writer, IUtf8JsonSerializable value) - { - value.Write(writer); - } - - public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) - { - switch (format) - { - case "U": - writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); - break; - default: - throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); - } - } - - public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) - { - if (format != "U") throw new ArgumentOutOfRangeException(format, "Only 'U' format is supported when writing a DateTimeOffset as a Number."); - - writer.WriteNumberValue(value.ToUnixTimeSeconds()); - } - - public static void WriteObjectValue(this Utf8JsonWriter writer, object value) - { - switch (value) - { - case null: - writer.WriteNullValue(); - break; - case IUtf8JsonSerializable serializable: - writer.WriteObjectValue(serializable); - break; - case byte[] bytes: - writer.WriteStringValue(Convert.ToBase64String(bytes)); - break; - case int i: - writer.WriteNumberValue(i); - break; - case decimal d: - writer.WriteNumberValue(d); - break; - case double d: - writer.WriteNumberValue(d); - break; - case float f: - writer.WriteNumberValue(f); - break; - case long l: - writer.WriteNumberValue(l); - break; - case string s: - writer.WriteStringValue(s); - break; - case bool b: - writer.WriteBooleanValue(b); - break; - case Guid g: - writer.WriteStringValue(g); - break; - case DateTimeOffset dateTimeOffset: - writer.WriteStringValue(dateTimeOffset,"O"); - break; - case DateTime dateTime: - writer.WriteStringValue(dateTime, "O"); - break; - case IEnumerable> enumerable: - writer.WriteStartObject(); - foreach (KeyValuePair pair in enumerable) - { - writer.WritePropertyName(pair.Key); - writer.WriteObjectValue(pair.Value); - } - writer.WriteEndObject(); - break; - case IEnumerable objectEnumerable: - writer.WriteStartArray(); - foreach (object item in objectEnumerable) - { - writer.WriteObjectValue(item); - } - writer.WriteEndArray(); - break; - - default: - throw new NotSupportedException("Not supported type " + value.GetType()); - } - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/XElementExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/XElementExtensions.cs deleted file mode 100644 index d09fb05e7fe9..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/XElementExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Globalization; -using System.Xml; -using System.Xml.Linq; - -namespace Azure.Core -{ - internal static class XElementExtensions - { - public static byte[] GetBytesFromBase64Value(this XElement element, string format) => format switch - { - "U" => TypeFormatters.FromBase64UrlString(element.Value), - _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) - }; - - public static DateTimeOffset GetDateTimeOffsetValue(this XElement element, string format) => format switch - { - "U" => DateTimeOffset.FromUnixTimeSeconds((long)element), - _ => TypeFormatters.ParseDateTimeOffset(element.Value, format) - }; - - public static TimeSpan GetTimeSpanValue(this XElement element, string format) => TypeFormatters.ParseTimeSpan(element.Value, format); - #pragma warning disable CA1801 //Parameter format of method GetObjectValue is never used. Remove the parameter or use it in the method body. - public static object GetObjectValue(this XElement element, string format) - #pragma warning restore - { - return element.Value; - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterContent.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterContent.cs deleted file mode 100644 index b0b4f5a04d50..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterContent.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System.IO; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Xml; - -namespace Azure.Core -{ - internal class XmlWriterContent : RequestContent - { - private readonly MemoryStream _stream; - private readonly RequestContent _content; - - public XmlWriterContent() - { - _stream = new MemoryStream(); - _content = Create(_stream); - XmlWriter = new XmlTextWriter(_stream, Encoding.UTF8); - } - - public XmlWriter XmlWriter { get; } - - public override async Task WriteToAsync(Stream stream, CancellationToken cancellation) - { - XmlWriter.Flush(); - await _content.WriteToAsync(stream, cancellation).ConfigureAwait(false); - } - - public override void WriteTo(Stream stream, CancellationToken cancellation) - { - XmlWriter.Flush(); - _content.WriteTo(stream, cancellation); - } - - public override bool TryComputeLength(out long length) - { - XmlWriter.Flush(); - length = _stream.Length; - return true; - } - - public override void Dispose() - { - _content.Dispose(); - XmlWriter.Dispose(); - } - } -} diff --git a/sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterExtensions.cs b/sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterExtensions.cs deleted file mode 100644 index 84cf13f4c976..000000000000 --- a/sdk/core/Azure.Core/src/Shared/AutoRest/XmlWriterExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#nullable enable - -using System; -using System.Xml; - -namespace Azure.Core -{ - internal static class XmlWriterExtensions - { - public static void WriteObjectValue(this XmlWriter writer, object value, string? nameHint) - { - switch (value) - { - case IXmlSerializable serializable: - serializable.Write(writer, nameHint); - return; - default: - throw new NotImplementedException(); - } - } - - public static void WriteValue(this XmlWriter writer, DateTimeOffset value, string format) => - writer.WriteValue(TypeFormatters.ToString(value, format)); - - public static void WriteValue(this XmlWriter writer, TimeSpan value, string format) => - writer.WriteValue(TypeFormatters.ToString(value, format)); - - public static void WriteValue(this XmlWriter writer, byte[] value, string format) - { - switch (format) - { - case "U": - writer.WriteValue(TypeFormatters.ToBase64UrlString(value)); - break; - default: - throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); - } - } - } -} diff --git a/sdk/keyvault/samples/sharelink/Generated/ManagedStorageRestClient.cs b/sdk/keyvault/samples/sharelink/Generated/ManagedStorageRestClient.cs index 1412a931ace7..993ded0dc166 100644 --- a/sdk/keyvault/samples/sharelink/Generated/ManagedStorageRestClient.cs +++ b/sdk/keyvault/samples/sharelink/Generated/ManagedStorageRestClient.cs @@ -61,6 +61,7 @@ internal HttpMessage CreateGetStorageAccountsRequest(int? maxresults) } uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -120,6 +121,7 @@ internal HttpMessage CreateGetDeletedStorageAccountsRequest(int? maxresults) } uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -176,6 +178,7 @@ internal HttpMessage CreateGetDeletedStorageAccountRequest(string storageAccount uri.AppendPath(storageAccountName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -244,6 +247,7 @@ internal HttpMessage CreatePurgeDeletedStorageAccountRequest(string storageAccou uri.AppendPath(storageAccountName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -303,6 +307,7 @@ internal HttpMessage CreateRecoverDeletedStorageAccountRequest(string storageAcc uri.AppendPath("/recover", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -372,6 +377,7 @@ internal HttpMessage CreateBackupStorageAccountRequest(string storageAccountName uri.AppendPath("/backup", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -440,6 +446,7 @@ internal HttpMessage CreateRestoreStorageAccountRequest(byte[] storageBundleBack uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); var model = new StorageRestoreParameters(storageBundleBackup); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(model); @@ -512,6 +519,7 @@ internal HttpMessage CreateDeleteStorageAccountRequest(string storageAccountName uri.AppendPath(storageAccountName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -580,6 +588,7 @@ internal HttpMessage CreateGetStorageAccountRequest(string storageAccountName) uri.AppendPath(storageAccountName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -649,6 +658,7 @@ internal HttpMessage CreateSetStorageAccountRequest(string storageAccountName, s uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); StorageAccountCreateParameters storageAccountCreateParameters = new StorageAccountCreateParameters(resourceId, activeKeyName, autoRegenerateKey) { RegenerationPeriod = regenerationPeriod, @@ -759,6 +769,7 @@ internal HttpMessage CreateUpdateStorageAccountRequest(string storageAccountName uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); StorageAccountUpdateParameters storageAccountUpdateParameters = new StorageAccountUpdateParameters() { ActiveKeyName = activeKeyName, @@ -854,6 +865,7 @@ internal HttpMessage CreateRegenerateStorageAccountKeyRequest(string storageAcco uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); var model = new StorageAccountRegenerteKeyParameters(keyName); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(model); @@ -941,6 +953,7 @@ internal HttpMessage CreateGetSasDefinitionsRequest(string storageAccountName, i } uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1016,6 +1029,7 @@ internal HttpMessage CreateGetDeletedSasDefinitionsRequest(string storageAccount } uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1088,6 +1102,7 @@ internal HttpMessage CreateGetDeletedSasDefinitionRequest(string storageAccountN uri.AppendPath(sasDefinitionName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1169,6 +1184,7 @@ internal HttpMessage CreateRecoverDeletedSasDefinitionRequest(string storageAcco uri.AppendPath("/recover", false); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1249,6 +1265,7 @@ internal HttpMessage CreateDeleteSasDefinitionRequest(string storageAccountName, uri.AppendPath(sasDefinitionName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1329,6 +1346,7 @@ internal HttpMessage CreateGetSasDefinitionRequest(string storageAccountName, st uri.AppendPath(sasDefinitionName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1410,6 +1428,7 @@ internal HttpMessage CreateSetSasDefinitionRequest(string storageAccountName, st uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); SasDefinitionCreateParameters sasDefinitionCreateParameters = new SasDefinitionCreateParameters(templateUri, sasType, validityPeriod) { SasDefinitionAttributes = sasDefinitionAttributes @@ -1529,6 +1548,7 @@ internal HttpMessage CreateUpdateSasDefinitionRequest(string storageAccountName, uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); + request.Headers.Add("Accept", "application/json"); SasDefinitionUpdateParameters sasDefinitionUpdateParameters = new SasDefinitionUpdateParameters() { TemplateUri = templateUri, @@ -1630,6 +1650,7 @@ internal HttpMessage CreateGetStorageAccountsNextPageRequest(string nextLink, in uri.AppendRaw(vaultBaseUrl, false); uri.AppendRawNextLink(nextLink, false); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1698,6 +1719,7 @@ internal HttpMessage CreateGetDeletedStorageAccountsNextPageRequest(string nextL uri.AppendRaw(vaultBaseUrl, false); uri.AppendRawNextLink(nextLink, false); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1766,6 +1788,7 @@ internal HttpMessage CreateGetSasDefinitionsNextPageRequest(string nextLink, str uri.AppendRaw(vaultBaseUrl, false); uri.AppendRawNextLink(nextLink, false); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } @@ -1844,6 +1867,7 @@ internal HttpMessage CreateGetDeletedSasDefinitionsNextPageRequest(string nextLi uri.AppendRaw(vaultBaseUrl, false); uri.AppendRawNextLink(nextLink, false); request.Uri = uri; + request.Headers.Add("Accept", "application/json"); return message; } diff --git a/sdk/keyvault/samples/sharelink/ShareLink.csproj b/sdk/keyvault/samples/sharelink/ShareLink.csproj index 6d760add795a..d263bca5c5a9 100644 --- a/sdk/keyvault/samples/sharelink/ShareLink.csproj +++ b/sdk/keyvault/samples/sharelink/ShareLink.csproj @@ -22,6 +22,12 @@ + + + + + + @@ -39,19 +45,7 @@ - - - - - - - - - - - -