Skip to content

Commit

Permalink
[AutoPR Microsoft.Azure.Management.Subscription] [Hub Generated] Revi…
Browse files Browse the repository at this point in the history
…ew request for Microsoft.Subscription to add version preview/2018-11-01-preview (#250)

* Update swagger_to_sdk_config.json

* Generated from 12cf92bb36d2c853720ea3480580c9ef415f9984

Corrected the createSubscriptionUnderBillingProfile example with correct profile name.
  • Loading branch information
openapi-sdkautomation[bot] authored and SDK Automation committed Oct 17, 2019
1 parent 51c6870 commit 935954c
Show file tree
Hide file tree
Showing 162 changed files with 24,735 additions and 1,903 deletions.
4 changes: 2 additions & 2 deletions eng/mgmt/mgmtmetadata/datamigration_resource-manager.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Commencing code generation
Generating CSharp code
Executing AutoRest command
cmd.exe /c autorest.cmd https://github.com/Azure/azure-rest-api-specs/blob/master/specification/datamigration/resource-manager/readme.md --csharp --version=latest --reflect-api-versions --csharp-sdks-folder=C:\Dev\Git\azure-sdk-for-net\sdk
2019-10-15 23:51:19 UTC
2019-08-13 19:30:49 UTC
Azure-rest-api-specs repository information
GitHub fork: Azure
Branch: master
Commit: 411d4cf447639289e4ee1efa4d066df2773ebccd
Commit: e9b03021559994e2988fd977d465685795c2f70d
AutoRest information
Requested version: latest
Bootstrapper version: autorest@2.0.4283
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Request CreateAddRequest(ConfigurationSetting setting)
BuildUriForKvRoute(request.Uri, setting);

MatchConditions requestOptions = new MatchConditions();
requestOptions.IfNoneMatch = ETag.All;
requestOptions.SetIfNotExistsCondition();
ConditionalRequestOptionsExtensions.ApplyHeaders(request, requestOptions);

request.Headers.Add(s_mediaTypeKeyValueApplicationHeader);
Expand Down Expand Up @@ -220,7 +220,7 @@ public virtual async Task<Response<ConfigurationSetting>> SetAsync(Configuration
if (onlyIfUnchanged)
{
requestOptions = new MatchConditions();
requestOptions.IfMatch = setting.ETag;
requestOptions.SetIfUnmodifiedCondition(setting.ETag);
}

return await SetAsync(setting, requestOptions, cancellationToken).ConfigureAwait(false);
Expand All @@ -241,7 +241,7 @@ public virtual Response<ConfigurationSetting> Set(ConfigurationSetting setting,
if (onlyIfUnchanged)
{
requestOptions = new MatchConditions();
requestOptions.IfMatch = setting.ETag;
requestOptions.SetIfUnmodifiedCondition(setting.ETag);
}

return Set(setting, requestOptions, cancellationToken);
Expand Down Expand Up @@ -373,7 +373,7 @@ public virtual async Task<Response> DeleteAsync(ConfigurationSetting setting, bo
if (onlyIfUnchanged)
{
requestOptions = new MatchConditions();
requestOptions.IfMatch = setting.ETag;
requestOptions.SetIfUnmodifiedCondition(setting.ETag);
}

return await DeleteAsync(setting.Key, setting.Label, requestOptions, cancellationToken).ConfigureAwait(false);
Expand All @@ -394,7 +394,7 @@ public virtual Response Delete(ConfigurationSetting setting, bool onlyIfUnchange
if (onlyIfUnchanged)
{
requestOptions = new MatchConditions();
requestOptions.IfMatch = setting.ETag;
requestOptions.SetIfUnmodifiedCondition(setting.ETag);
}

return Delete(setting.Key, setting.Label, requestOptions, cancellationToken);
Expand Down Expand Up @@ -523,7 +523,7 @@ public virtual async Task<Response<ConfigurationSetting>> GetAsync(Configuration
if (onlyIfChanged)
{
requestOptions = new MatchConditions();
requestOptions.IfNoneMatch = setting.ETag;
requestOptions.SetIfModifiedCondition(setting.ETag);
}

return await GetAsync(setting.Key, setting.Label, acceptDateTime: default, requestOptions, cancellationToken).ConfigureAwait(false);
Expand All @@ -544,7 +544,7 @@ public virtual Response<ConfigurationSetting> Get(ConfigurationSetting setting,
if (onlyIfChanged)
{
requestOptions = new MatchConditions();
requestOptions.IfNoneMatch = setting.ETag;
requestOptions.SetIfModifiedCondition(setting.ETag);
}

return Get(setting.Key, setting.Label, acceptDateTime: default, requestOptions, cancellationToken);
Expand Down Expand Up @@ -703,7 +703,7 @@ private async Task<Page<ConfigurationSetting>> GetSettingsPageAsync(SettingSelec
case 200:
case 206:
SettingBatch settingBatch = await ConfigurationServiceSerializer.ParseBatchAsync(response, cancellationToken).ConfigureAwait(false);
return Page<ConfigurationSetting>.FromValues(settingBatch.Settings, settingBatch.NextBatchLink, response);
return new Page<ConfigurationSetting>(settingBatch.Settings, settingBatch.NextBatchLink, response);
default:
throw await response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
}
Expand Down Expand Up @@ -736,7 +736,7 @@ private Page<ConfigurationSetting> GetSettingsPage(SettingSelector selector, str
case 200:
case 206:
SettingBatch settingBatch = ConfigurationServiceSerializer.ParseBatch(response);
return Page<ConfigurationSetting>.FromValues(settingBatch.Settings, settingBatch.NextBatchLink, response);
return new Page<ConfigurationSetting>(settingBatch.Settings, settingBatch.NextBatchLink, response);
default:
throw response.CreateRequestFailedException();
}
Expand Down Expand Up @@ -784,7 +784,7 @@ private async Task<Page<ConfigurationSetting>> GetRevisionsPageAsync(SettingSele
case 200:
case 206:
SettingBatch settingBatch = await ConfigurationServiceSerializer.ParseBatchAsync(response, cancellationToken).ConfigureAwait(false);
return Page<ConfigurationSetting>.FromValues(settingBatch.Settings, settingBatch.NextBatchLink, response);
return new Page<ConfigurationSetting>(settingBatch.Settings, settingBatch.NextBatchLink, response);
default:
throw await response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
}
Expand Down Expand Up @@ -817,7 +817,7 @@ private Page<ConfigurationSetting> GetRevisionsPage(SettingSelector selector, st
case 200:
case 206:
SettingBatch settingBatch = ConfigurationServiceSerializer.ParseBatch(response);
return Page<ConfigurationSetting>.FromValues(settingBatch.Settings, settingBatch.NextBatchLink, response);
return new Page<ConfigurationSetting>(settingBatch.Settings, settingBatch.NextBatchLink, response);
default:
throw response.CreateRequestFailedException();
}
Expand Down
37 changes: 37 additions & 0 deletions sdk/core/Azure.Core/src/MatchConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,42 @@ public class MatchConditions
/// Optionally limit requests to resources that do not match the ETag.
/// </summary>
public ETag? IfNoneMatch { get; set; }

/// <summary>
/// Set preconditions that indicate to apply an operation only if the
/// target resource has changed.
/// </summary>
/// <param name="etag">The version of the resource to compare to.</param>
public virtual void SetIfModifiedCondition(ETag etag)
{
IfNoneMatch = etag;
}

/// <summary>
/// Set preconditions that indicate to apply an operation only if the
/// target resource has not changed.
/// </summary>
public virtual void SetIfUnmodifiedCondition(ETag etag)
{
IfMatch = etag;
}

/// <summary>
/// Set preconditions that indicate to apply an operation only if the
/// target resource is present.
/// </summary>
public virtual void SetIfExistsCondition()
{
IfMatch = ETag.All;
}

/// <summary>
/// Set preconditions that indicate to apply an operation only if the
/// target resource is not present.
/// </summary>
public virtual void SetIfNotExistsCondition()
{
IfNoneMatch = ETag.All;
}
}
}
22 changes: 22 additions & 0 deletions sdk/core/Azure.Core/src/ModifiedSinceConditions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure
{
public class ModifiedSinceConditions : MatchConditions
{
/// <summary>
/// Optionally limit requests to resources that have only been
/// modified since this point in time.
/// </summary>
public DateTimeOffset? IfModifiedSince { get; set; }

/// <summary>
/// Optionally limit requests to resources that have remained
/// unmodified
/// </summary>
public DateTimeOffset? IfUnmodifiedSince { get; set; }
}
}
37 changes: 13 additions & 24 deletions sdk/core/Azure.Core/src/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@ namespace Azure
/// zero or more <see cref="Page{T}"/>s of values.
/// </summary>
/// <typeparam name="T">The type of values.</typeparam>
public abstract class Page<T>
public readonly struct Page<T>
{
/// <summary>
/// Gets the values in this <see cref="Page{T}"/>.
/// </summary>
public abstract IReadOnlyList<T> Values { get; }
public IReadOnlyList<T> Values { get; }

/// <summary>
/// Gets the continuation token used to request the next
/// <see cref="Page{T}"/>. The continuation token may be null or
/// empty when there are no more pages.
/// </summary>
public abstract string? ContinuationToken { get; }
public string? ContinuationToken { get; }

/// <summary>
/// The <see cref="Response"/> that provided this <see cref="Page{T}"/>.
/// </summary>
private readonly Response _response;

/// <summary>
/// Gets the <see cref="Response"/> that provided this
/// <see cref="Page{T}"/>.
/// </summary>
public abstract Response GetRawResponse();
public Response GetRawResponse() => _response;

/// <summary>
/// Creates a new <see cref="Page{T}"/>.
Expand All @@ -43,11 +48,11 @@ public abstract class Page<T>
/// <param name="response">
/// The <see cref="Response"/> that provided this <see cref="Page{T}"/>.
/// </param>
#pragma warning disable CA1000 // Do not declare static members on generic types
public static Page<T> FromValues(IReadOnlyList<T> values, string? continuationToken, Response response)
#pragma warning restore CA1000 // Do not declare static members on generic types
public Page(IReadOnlyList<T> values, string? continuationToken, Response response)
{
return new PageCore(values, continuationToken, response);
Values = values;
ContinuationToken = continuationToken;
_response = response;
}

/// <summary>
Expand All @@ -73,21 +78,5 @@ public static Page<T> FromValues(IReadOnlyList<T> values, string? continuationTo
/// <returns>Hash code for the <see cref="Page{T}"/>.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => base.GetHashCode();

private class PageCore : Page<T>
{
private readonly Response _response;

public PageCore(IReadOnlyList<T> values, string? continuationToken, Response response)
{
_response = response;
Values = values;
ContinuationToken = continuationToken;
}

public override IReadOnlyList<T> Values { get; }
public override string? ContinuationToken { get; }
public override Response GetRawResponse() => _response;
}
}
}
17 changes: 0 additions & 17 deletions sdk/core/Azure.Core/src/RequestFailedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,10 @@

namespace Azure
{
/// <summary>
/// An exception thrown when service request fails.
/// </summary>
public class RequestFailedException : Exception
{
/// <summary>
/// Gets the HTTP status code of the response. Returns <code>0</code> if response was not received.
/// </summary>
public int Status { get; }

/// <summary>
/// Gets the service specific error code if available. Please refer to the client documentation for the list of supported error codes.
/// </summary>
public string? ErrorCode { get; }

public RequestFailedException(string message) : this(0, message)
{
}
Expand All @@ -34,15 +23,9 @@ public RequestFailedException(int status, string message)
}

public RequestFailedException(int status, string message, Exception? innerException)
: this(status, message, null, innerException)
{
}

public RequestFailedException(int status, string message, string? errorCode, Exception? innerException)
: base(message, innerException)
{
Status = status;
ErrorCode = errorCode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void ApplyHeaders(Request request, MatchConditions options)
request.Headers.Add(HttpHeader.Names.IfNoneMatch, value);
}

if (options is RequestConditions dateOptions)
if (options is ModifiedSinceConditions dateOptions)
{
if (dateOptions.IfModifiedSince.HasValue)
{
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/src/Shared/PageResponseEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Azure.Core
{
internal static class PageResponseEnumerator
{

public static FuncPageable<T> CreateEnumerable<T>(Func<string?, Page<T>> pageFunc) where T : notnull
{
return new FuncPageable<T>((continuationToken, pageSizeHint) => pageFunc(continuationToken));
Expand Down
34 changes: 18 additions & 16 deletions sdk/core/Azure.Core/src/Shared/ResponseExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand All @@ -15,25 +14,35 @@ internal static class ResponseExceptionExtensions
{
private const string DefaultMessage = "Service request failed.";

public static ValueTask<RequestFailedException> CreateRequestFailedExceptionAsync(this Response response, string message = null, string errorCode = null)
public static ValueTask<RequestFailedException> CreateRequestFailedExceptionAsync(this Response response)
{
return CreateRequestFailedExceptionAsync(message ?? DefaultMessage, response, errorCode, true);
return CreateRequestFailedExceptionAsync(response, DefaultMessage);
}

public static RequestFailedException CreateRequestFailedException(this Response response, string message = null, string errorCode = null)
public static ValueTask<RequestFailedException> CreateRequestFailedExceptionAsync(this Response response, string message)
{
ValueTask<RequestFailedException> messageTask = CreateRequestFailedExceptionAsync(message, response, errorCode, false);
return CreateRequestFailedExceptionAsync(message, response, true);
}

public static RequestFailedException CreateRequestFailedException(this Response response)
{
return CreateRequestFailedException(response, DefaultMessage);
}

public static RequestFailedException CreateRequestFailedException(this Response response, string message)
{
ValueTask<RequestFailedException> messageTask = CreateRequestFailedExceptionAsync(message, response, false);
Debug.Assert(messageTask.IsCompleted);
return messageTask.GetAwaiter().GetResult();
}

public static async ValueTask<RequestFailedException> CreateRequestFailedExceptionAsync(string message, Response response, string errorCode, bool async)
public static async ValueTask<RequestFailedException> CreateRequestFailedExceptionAsync(string message, Response response, bool async)
{
message = await CreateRequestFailedMessageAsync(message, response, errorCode, async).ConfigureAwait(false);
return new RequestFailedException(response.Status, message, errorCode, null);
message = await CreateRequestFailedMessageAsync(message, response, async).ConfigureAwait(false);
return new RequestFailedException(response.Status, message);
}

public static async ValueTask<string> CreateRequestFailedMessageAsync(string message, Response response, string errorCode, bool async)
public static async ValueTask<string> CreateRequestFailedMessageAsync(string message, Response response, bool async)
{
StringBuilder messageBuilder = new StringBuilder()
.AppendLine(message)
Expand All @@ -43,13 +52,6 @@ public static async ValueTask<string> CreateRequestFailedMessageAsync(string mes
.Append(response.ReasonPhrase)
.AppendLine(")");

if (!string.IsNullOrWhiteSpace(errorCode))
{
messageBuilder.Append("ErrorCode: ")
.Append(errorCode)
.AppendLine();
}

if (response.ContentStream != null &&
ContentTypeUtilities.TryGetTextEncoding(response.Headers.ContentType, out var encoding))
{
Expand Down
21 changes: 0 additions & 21 deletions sdk/core/Azure.Core/tests/FailedResponseExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,5 @@ public async Task DoesntFormatsResponseContentForNonTextContentTypes()
RequestFailedException exception = await response.CreateRequestFailedExceptionAsync();
Assert.AreEqual(formattedResponse, exception.Message);
}

[Test]
public async Task IncludesErrorCodeInMessageIfAvailable()
{
var formattedResponse =
"Service request failed." + s_nl +
"Status: 210 (Reason)" + s_nl +
"ErrorCode: CUSTOM CODE" + s_nl +
s_nl +
"Headers:" + s_nl +
"Custom-Header: Value" + s_nl +
"x-ms-requestId: 123" + s_nl;

var response = new MockResponse(210, "Reason");
response.AddHeader(new HttpHeader("Custom-Header", "Value"));
response.AddHeader(new HttpHeader("x-ms-requestId", "123"));

RequestFailedException exception = await response.CreateRequestFailedExceptionAsync(null, errorCode: "CUSTOM CODE");
Assert.AreEqual(formattedResponse, exception.Message);
}

}
}
Loading

0 comments on commit 935954c

Please sign in to comment.