Might have initial support for paging being generated.
This commit is contained in:
Родитель
d252776945
Коммит
0719a5c6ec
|
@ -40,14 +40,6 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
if (method != null)
|
||||
{
|
||||
methods.Add(method);
|
||||
|
||||
//if ((operation.Extensions?.ContainsKey("x-ms-pageable") ?? false) && operation.Extensions["x-ms-pageable"] is IDictionary<string, object> pageable)
|
||||
//{
|
||||
// if (pageable.ContainsKey("nextLinkName") && operation.Extensions["x-ms-pageable"] is string nextLinkName)
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,14 +184,6 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
BuildResponseHeaderModel(operation, httpResponse)
|
||||
);
|
||||
|
||||
if ((operation.Extensions?.ContainsKey("x-ms-pageable") ?? false) && operation.Extensions["x-ms-pageable"] is IDictionary<string, object> pageable)
|
||||
{
|
||||
if (pageable.ContainsKey("nextLinkName") && operation.Extensions["x-ms-pageable"] is string nextLinkName)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
string operationName = operation.CSharpName();
|
||||
return new ClientMethod(
|
||||
operationName,
|
||||
|
@ -207,139 +191,21 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
request,
|
||||
OrderParameters(methodParameters),
|
||||
clientResponse,
|
||||
new ClientMethodDiagnostics($"{clientName}.{operationName}", Array.Empty<DiagnosticScopeAttributes>())
|
||||
new ClientMethodDiagnostics($"{clientName}.{operationName}",Array.Empty<DiagnosticScopeAttributes>()),
|
||||
GetClientMethodPaging(operation)
|
||||
);
|
||||
}
|
||||
|
||||
//private static ClientMethod? BuildNextPageMethod(Operation operation, string clientName, string nextLinkName, IReadOnlyDictionary<string, ServiceClientParameter> clientParameters)
|
||||
//{
|
||||
// var httpRequest = operation.Request.Protocol.Http as HttpRequest;
|
||||
// var httpRequestWithBody = httpRequest as HttpWithBodyRequest;
|
||||
|
||||
// //TODO: Handle multiple responses
|
||||
// var response = operation.Responses.FirstOrDefault();
|
||||
// var httpResponse = response?.Protocol.Http as HttpResponse;
|
||||
|
||||
// if (httpRequest == null || httpResponse == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// Dictionary<string, ConstantOrParameter> uriParameters = new Dictionary<string, ConstantOrParameter>();
|
||||
// Dictionary<string, PathSegment> pathParameters = new Dictionary<string, PathSegment>();
|
||||
// List<QueryParameter> query = new List<QueryParameter>();
|
||||
// List<RequestHeader> headers = new List<RequestHeader>();
|
||||
// List<ServiceClientParameter> methodParameters = new List<ServiceClientParameter>();
|
||||
|
||||
// ObjectRequestBody? body = null;
|
||||
// foreach (Parameter requestParameter in operation.Request.Parameters ?? Array.Empty<Parameter>())
|
||||
// {
|
||||
// string defaultName = requestParameter.Language.Default.Name;
|
||||
// string serializedName = requestParameter.Language.Default.SerializedName ?? defaultName;
|
||||
// ConstantOrParameter constantOrParameter;
|
||||
// Schema valueSchema = requestParameter.Schema;
|
||||
|
||||
// if (requestParameter.Implementation == ImplementationLocation.Method)
|
||||
// {
|
||||
// switch (requestParameter.Schema)
|
||||
// {
|
||||
// case ConstantSchema constant:
|
||||
// constantOrParameter = ClientModelBuilderHelpers.ParseClientConstant(constant);
|
||||
// valueSchema = constant.ValueType;
|
||||
// break;
|
||||
// case BinarySchema _:
|
||||
// // skip
|
||||
// continue;
|
||||
// default:
|
||||
// constantOrParameter = BuildParameter(requestParameter);
|
||||
// break;
|
||||
// }
|
||||
|
||||
// if (!constantOrParameter.IsConstant)
|
||||
// {
|
||||
// methodParameters.Add(constantOrParameter.Parameter);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// constantOrParameter = clientParameters[defaultName];
|
||||
// }
|
||||
|
||||
|
||||
// if (requestParameter.Protocol.Http is HttpParameter httpParameter)
|
||||
// {
|
||||
// SerializationFormat serializationFormat = ClientModelBuilderHelpers.GetSerializationFormat(valueSchema);
|
||||
// switch (httpParameter.In)
|
||||
// {
|
||||
// case ParameterLocation.Header:
|
||||
// headers.Add(new RequestHeader(serializedName, constantOrParameter, serializationFormat));
|
||||
// break;
|
||||
// case ParameterLocation.Query:
|
||||
// query.Add(new QueryParameter(serializedName, constantOrParameter, GetSerializationStyle(httpParameter, valueSchema), true, serializationFormat));
|
||||
// break;
|
||||
// //case ParameterLocation.Path:
|
||||
// // pathParameters.Add(serializedName, new PathSegment(constantOrParameter, true, serializationFormat));
|
||||
// // break;
|
||||
// //case ParameterLocation.Body:
|
||||
// // Debug.Assert(httpRequestWithBody != null);
|
||||
// // var serialization = SerializationBuilder.Build(httpRequestWithBody.KnownMediaType, requestParameter.Schema, requestParameter.IsNullable());
|
||||
|
||||
// // body = new ObjectRequestBody(constantOrParameter, serialization);
|
||||
// // break;
|
||||
// //case ParameterLocation.Uri:
|
||||
// // uriParameters[defaultName] = constantOrParameter;
|
||||
// // break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// if (httpRequestWithBody != null)
|
||||
// {
|
||||
// headers.AddRange(httpRequestWithBody.MediaTypes.Select(mediaType => new RequestHeader("Content-Type", ClientModelBuilderHelpers.StringConstant(mediaType))));
|
||||
// }
|
||||
|
||||
// var request = new ClientMethodRequest(
|
||||
// ToCoreRequestMethod(httpRequest.Method) ?? RequestMethod.Get,
|
||||
// ToParts(httpRequest.Uri, uriParameters),
|
||||
// ToPathParts(httpRequest.Path, pathParameters),
|
||||
// query.ToArray(),
|
||||
// headers.ToArray(),
|
||||
// body
|
||||
// );
|
||||
|
||||
// ResponseBody? responseBody = null;
|
||||
// if (response is SchemaResponse schemaResponse)
|
||||
// {
|
||||
// var schema = schemaResponse.Schema is ConstantSchema constantSchema ? constantSchema.ValueType : schemaResponse.Schema;
|
||||
// var responseType = ClientModelBuilderHelpers.CreateType(schema, isNullable: false);
|
||||
|
||||
// ObjectSerialization serialization = SerializationBuilder.Build(httpResponse.KnownMediaType, schema, isNullable: false);
|
||||
|
||||
// responseBody = new ObjectResponseBody(responseType, serialization);
|
||||
// }
|
||||
// else if (response is BinaryResponse)
|
||||
// {
|
||||
// responseBody = new StreamResponseBody();
|
||||
// }
|
||||
|
||||
// ClientMethodResponse clientResponse = new ClientMethodResponse(
|
||||
// responseBody,
|
||||
// httpResponse.StatusCodes.Select(ToStatusCode).ToArray(),
|
||||
// BuildResponseHeaderModel(operation, httpResponse)
|
||||
// );
|
||||
|
||||
// string operationName = operation.CSharpName();
|
||||
// return new ClientMethod(
|
||||
// operationName,
|
||||
// ClientModelBuilderHelpers.EscapeXmlDescription(operation.Language.Default.Description),
|
||||
// request,
|
||||
// OrderParameters(methodParameters),
|
||||
// clientResponse,
|
||||
// new ClientMethodDiagnostics($"{clientName}.{operationName}", Array.Empty<DiagnosticScopeAttributes>())
|
||||
// );
|
||||
//}
|
||||
|
||||
private static ClientMethodPaging? GetClientMethodPaging(Operation operation)
|
||||
{
|
||||
var pageable = operation.Extensions.GetValue<IDictionary<object, object>>("x-ms-pageable");
|
||||
return pageable != null
|
||||
? new ClientMethodPaging(
|
||||
pageable.GetValue<string>("nextLinkName"),
|
||||
pageable.GetValue<string>("itemName"),
|
||||
pageable.GetValue<string>("operationName"))
|
||||
: null;
|
||||
}
|
||||
|
||||
private static ServiceClientParameter BuildParameter(Parameter requestParameter)
|
||||
{
|
||||
|
@ -349,12 +215,19 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
defaultValue = ClientModelBuilderHelpers.ParseClientConstant(constantSchema);
|
||||
}
|
||||
|
||||
ParameterLocation? location = null;
|
||||
if (requestParameter.Protocol.Http is HttpParameter httpParameter)
|
||||
{
|
||||
location = httpParameter.In;
|
||||
}
|
||||
|
||||
return new ServiceClientParameter(
|
||||
requestParameter.CSharpName(),
|
||||
CreateDescription(requestParameter),
|
||||
ClientModelBuilderHelpers.CreateType(requestParameter.Schema, requestParameter.IsNullable()),
|
||||
CreateDefaultValueConstant(requestParameter) ?? defaultValue,
|
||||
requestParameter.Required == true);
|
||||
requestParameter.Required == true,
|
||||
location);
|
||||
}
|
||||
|
||||
private static ResponseHeaderModel? BuildResponseHeaderModel(Operation operation, HttpResponse httpResponse)
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
{
|
||||
internal class ClientMethod
|
||||
{
|
||||
public ClientMethod(string name, string? description, ClientMethodRequest request, ServiceClientParameter[] parameters, ClientMethodResponse responseType, ClientMethodDiagnostics diagnostics, bool includesPaging)
|
||||
public ClientMethod(string name, string? description, ClientMethodRequest request, ServiceClientParameter[] parameters, ClientMethodResponse responseType, ClientMethodDiagnostics diagnostics, ClientMethodPaging? paging)
|
||||
{
|
||||
Name = name;
|
||||
Request = request;
|
||||
|
@ -13,7 +13,7 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
Response = responseType;
|
||||
Description = description;
|
||||
Diagnostics = diagnostics;
|
||||
IncludesPaging = includesPaging;
|
||||
Paging = paging;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
@ -22,6 +22,6 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
public ServiceClientParameter[] Parameters { get; }
|
||||
public ClientMethodResponse Response { get; }
|
||||
public ClientMethodDiagnostics Diagnostics { get; }
|
||||
public bool IncludesPaging { get; }
|
||||
public ClientMethodPaging? Paging { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,15 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
{
|
||||
internal class ClientMethodPaging
|
||||
{
|
||||
public ClientMethodPaging(string name, string? description, ClientMethodRequest request, ServiceClientParameter[] parameters, ClientMethodResponse responseType, ClientMethodDiagnostics diagnostics, bool includesPaging)
|
||||
public ClientMethodPaging(string? nextLinkName, string? itemName, string? operationName)
|
||||
{
|
||||
IncludesPaging = includesPaging;
|
||||
NextLinkName = nextLinkName;
|
||||
ItemName = itemName;
|
||||
OperationName = operationName;
|
||||
}
|
||||
|
||||
public bool IncludesPaging { get; }
|
||||
public string? NextLinkName { get; }
|
||||
public string? ItemName { get; }
|
||||
public string? OperationName { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
|
||||
namespace AutoRest.CSharp.V3.ClientModels
|
||||
{
|
||||
internal class ServiceClientParameter
|
||||
{
|
||||
public ServiceClientParameter(string name, string? description, ClientTypeReference type, ClientConstant? defaultValue, bool isRequired)
|
||||
public ServiceClientParameter(string name, string? description, ClientTypeReference type, ClientConstant? defaultValue, bool isRequired, ParameterLocation? location)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
Type = type;
|
||||
DefaultValue = defaultValue;
|
||||
IsRequired = isRequired;
|
||||
Location = location;
|
||||
}
|
||||
|
||||
public ClientTypeReference Type { get; }
|
||||
|
@ -19,5 +22,6 @@ namespace AutoRest.CSharp.V3.ClientModels
|
|||
public string? Description { get; }
|
||||
public ClientConstant? DefaultValue { get; }
|
||||
public bool IsRequired { get; }
|
||||
public ParameterLocation? Location { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,13 @@ using System.Threading.Tasks;
|
|||
using System.Xml.Linq;
|
||||
using AutoRest.CSharp.V3.ClientModels;
|
||||
using AutoRest.CSharp.V3.ClientModels.Serialization;
|
||||
using AutoRest.CSharp.V3.Pipeline.Generated;
|
||||
using AutoRest.CSharp.V3.Utilities;
|
||||
using Azure;
|
||||
using Azure.Core;
|
||||
using Azure.Core.Pipeline;
|
||||
using Response = Azure.Response;
|
||||
using SerializationFormat = AutoRest.CSharp.V3.ClientModels.SerializationFormat;
|
||||
|
||||
namespace AutoRest.CSharp.V3.CodeGen
|
||||
{
|
||||
|
@ -44,6 +47,11 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
WriteRequestCreation(writer, method);
|
||||
WriteOperation(writer, method, async: true);
|
||||
WriteOperation(writer, method, async: false);
|
||||
if (method.Paging != null)
|
||||
{
|
||||
WriteRequestCreation(writer, method, true);
|
||||
WriteOperation(writer, method, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,19 +104,28 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
writer.AppendRaw(",");
|
||||
}
|
||||
|
||||
|
||||
private string CreateRequestMethodName(ClientMethod operation) => $"Create{operation.Name}Request";
|
||||
|
||||
private void WriteRequestCreation(CodeWriter writer, ClientMethod operation)
|
||||
private string CreatePagingRequestMethodName(ClientMethod operation) => $"Create{operation.Name}PageRequest";
|
||||
|
||||
private string GetPagingMethodName(ClientMethod operation) => $"{operation.Name}NextPage";
|
||||
|
||||
private void WriteRequestCreation(CodeWriter writer, ClientMethod operation, bool paging = false)
|
||||
{
|
||||
writer.Append($"internal {typeof(HttpMessage)} {CreateRequestMethodName(operation)}(");
|
||||
foreach (ServiceClientParameter clientParameter in operation.Parameters)
|
||||
var methodName = paging ? CreatePagingRequestMethodName(operation) : CreateRequestMethodName(operation);
|
||||
writer.Append($"internal {typeof(HttpMessage)} {methodName}(");
|
||||
var parameters = paging
|
||||
? operation.Parameters.Where(p =>
|
||||
p.Location != ParameterLocation.Path && p.Location != ParameterLocation.Uri ||
|
||||
p.Location != ParameterLocation.Body).ToArray()
|
||||
: operation.Parameters;
|
||||
foreach (ServiceClientParameter clientParameter in parameters)
|
||||
{
|
||||
writer.Append($"{_typeFactory.CreateInputType(clientParameter.Type)} {clientParameter.Name},");
|
||||
}
|
||||
if (operation.IncludesPaging)
|
||||
if (paging)
|
||||
{
|
||||
writer.Append($"{writer.Type(typeof(string), true)} nextLinkUrl = default");
|
||||
writer.Append($"{writer.Type(typeof(string), true)} nextLinkUrl");
|
||||
}
|
||||
writer.RemoveTrailingComma();
|
||||
writer.Line($")");
|
||||
|
@ -119,11 +136,15 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
var method = operation.Request.Method;
|
||||
writer.Line($"request.Method = {typeof(RequestMethod)}.{method.ToRequestMethodName()};");
|
||||
|
||||
using (operation.IncludesPaging ? writer.If("nextLinkUrl != null") : default)
|
||||
{
|
||||
writer.Line($"request.Uri.Reset(new {typeof(Uri)}(nextLinkUrl));");
|
||||
}
|
||||
using (operation.IncludesPaging ? writer.Else() : default)
|
||||
//using (operation.Paging != null ? writer.If("nextLinkUrl != null") : default)
|
||||
//{
|
||||
if (paging)
|
||||
{
|
||||
writer.Line($"request.Uri.Reset(new {typeof(Uri)}(nextLinkUrl));");
|
||||
}
|
||||
//}
|
||||
//using (operation.Paging != null ? writer.Else() : default)
|
||||
else
|
||||
{
|
||||
//TODO: Add logic to escape the strings when specified, using Uri.EscapeDataString(value);
|
||||
//TODO: Need proper logic to convert the values to strings. Right now, everything is just using default ToString().
|
||||
|
@ -148,7 +169,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
WriteQueryParameter(writer, queryParameter);
|
||||
}
|
||||
|
||||
if (operation.Request.Body is ObjectRequestBody body && body.Serialization is JsonSerialization jsonSerialization)
|
||||
if (!paging && operation.Request.Body is ObjectRequestBody body && body.Serialization is JsonSerialization jsonSerialization)
|
||||
{
|
||||
writer.Line($"using var content = new {typeof(Utf8JsonRequestContent)}();");
|
||||
|
||||
|
@ -162,7 +183,7 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
|
||||
writer.Line($"request.Content = content;");
|
||||
}
|
||||
else if (operation.Request.Body is ObjectRequestBody xmlBody && xmlBody.Serialization is XmlElementSerialization xmlSerialization)
|
||||
else if (!paging && operation.Request.Body is ObjectRequestBody xmlBody && xmlBody.Serialization is XmlElementSerialization xmlSerialization)
|
||||
{
|
||||
writer.Line($"using var content = new {typeof(XmlWriterContent)}();");
|
||||
|
||||
|
@ -180,13 +201,13 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
writer.Line($"return message;");
|
||||
}
|
||||
}
|
||||
private void WriteOperation(CodeWriter writer, ClientMethod operation, bool async)
|
||||
|
||||
private void WriteOperation(CodeWriter writer, ClientMethod operation, bool async, bool paging = false)
|
||||
{
|
||||
//TODO: Handle multiple responses
|
||||
var responseBody = operation.Response.ResponseBody;
|
||||
CSharpType? bodyType = responseBody != null ? _typeFactory.CreateType(responseBody.Type) : null;
|
||||
CSharpType? headerModelType = operation.Response.HeaderModel != null ? _typeFactory.CreateType(operation.Response.HeaderModel.Name) : null;
|
||||
|
||||
CSharpType responseType = bodyType switch
|
||||
{
|
||||
null when headerModelType != null => new CSharpType(typeof(ResponseWithHeaders<>), headerModelType),
|
||||
|
@ -194,21 +215,33 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
{ } => new CSharpType(typeof(ResponseWithHeaders<>), bodyType, headerModelType),
|
||||
_ => new CSharpType(typeof(Response)),
|
||||
};
|
||||
|
||||
var parameters = paging
|
||||
? operation.Parameters.Where(p =>
|
||||
p.Location != ParameterLocation.Path && p.Location != ParameterLocation.Uri ||
|
||||
p.Location != ParameterLocation.Body).ToArray()
|
||||
: operation.Parameters;
|
||||
|
||||
writer.WriteXmlDocumentationSummary(operation.Description);
|
||||
|
||||
foreach (ServiceClientParameter parameter in operation.Parameters)
|
||||
foreach (ServiceClientParameter parameter in parameters)
|
||||
{
|
||||
writer.WriteXmlDocumentationParameter(parameter.Name, parameter.Description);
|
||||
}
|
||||
|
||||
if (paging)
|
||||
{
|
||||
writer.WriteXmlDocumentationParameter("nextLinkUrl", "The URL to the next page of results.");
|
||||
}
|
||||
writer.WriteXmlDocumentationParameter("cancellationToken", "The cancellation token to use.");
|
||||
|
||||
var methodName = operation.Name;
|
||||
if (async)
|
||||
CSharpType asyncReturnType = new CSharpType(typeof(ValueTask<>), responseType);
|
||||
if (paging)
|
||||
{
|
||||
writer.Append($"public async {asyncReturnType} {GetPagingMethodName(operation)}(");
|
||||
}
|
||||
else if (async)
|
||||
{
|
||||
CSharpType asyncReturnType = new CSharpType(typeof(ValueTask<>), responseType);
|
||||
writer.Append($"public async {asyncReturnType} {methodName}Async(");
|
||||
}
|
||||
else
|
||||
|
@ -216,15 +249,20 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
writer.Append($"public {responseType} {methodName}(");
|
||||
}
|
||||
|
||||
foreach (ServiceClientParameter parameter in operation.Parameters)
|
||||
foreach (ServiceClientParameter parameter in parameters)
|
||||
{
|
||||
WriteParameter(writer, parameter);
|
||||
}
|
||||
|
||||
if (paging)
|
||||
{
|
||||
writer.Append($"{typeof(string)} nextLinkUrl, ");
|
||||
}
|
||||
writer.Line($"{typeof(CancellationToken)} cancellationToken = default)");
|
||||
|
||||
using (writer.Scope())
|
||||
{
|
||||
WriteParameterNullChecks(writer, operation.Parameters);
|
||||
WriteParameterNullChecks(writer, parameters);
|
||||
|
||||
writer.Line($"using var scope = clientDiagnostics.CreateScope({operation.Diagnostics.ScopeName:L});");
|
||||
foreach (DiagnosticScopeAttributes diagnosticScopeAttributes in operation.Diagnostics.Attributes)
|
||||
|
@ -235,12 +273,18 @@ namespace AutoRest.CSharp.V3.CodeGen
|
|||
|
||||
using (writer.Scope($"try"))
|
||||
{
|
||||
writer.Append($"using var message = {CreateRequestMethodName(operation)}(");
|
||||
var requestMethodName = paging ? CreatePagingRequestMethodName(operation) : CreateRequestMethodName(operation);
|
||||
writer.Append($"using var message = {requestMethodName}(");
|
||||
|
||||
foreach (ServiceClientParameter parameter in operation.Parameters)
|
||||
foreach (ServiceClientParameter parameter in parameters)
|
||||
{
|
||||
writer.Append($"{parameter.Name}, ");
|
||||
}
|
||||
|
||||
if (paging)
|
||||
{
|
||||
writer.Append($"nextLinkUrl");
|
||||
}
|
||||
writer.RemoveTrailingComma();
|
||||
writer.Line($");");
|
||||
|
||||
|
|
|
@ -95,6 +95,10 @@
|
|||
"body-datetime": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\body-datetime\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\body-datetime --namespace=body_datetime"
|
||||
},
|
||||
"paging": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--standalone --input-codemodel=$(SolutionDir)\\test\\TestServerProjects\\paging\\CodeModel.yaml --plugin=cs-modeler --output-path=$(SolutionDir)\\test\\TestServerProjects\\paging --namespace=paging"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
@ -59,5 +60,17 @@ namespace AutoRest.CSharp.V3.Utilities
|
|||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
//[return: MaybeNull]
|
||||
//public static TValue GetValue<TValue, TKey>(this IDictionary<TKey, object>? dictionary, TKey key) where TKey : notnull =>
|
||||
// ((dictionary?.ContainsKey(key) ?? false) && dictionary![key] is TValue item) ? item : default;
|
||||
|
||||
[return: MaybeNull]
|
||||
public static TValue GetValue<TValue>(this IDictionary<string, object>? dictionary, string key) =>
|
||||
((dictionary?.ContainsKey(key) ?? false) && dictionary![key] is TValue item) ? item : default;
|
||||
|
||||
[return: MaybeNull]
|
||||
public static T GetValue<T>(this IDictionary<object, object>? dictionary, string key) =>
|
||||
((dictionary?.ContainsKey(key) ?? false) && dictionary![key] is T item) ? item : default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,6 +96,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetNoItemNamePagesPageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that must return result of the default 'value' node. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResultValue>> GetNoItemNamePagesNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetNoItemNamePages");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetNoItemNamePagesPageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResultValue.DeserializeProductResultValue(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetNullNextLinkNamePagesRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -163,6 +201,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetNullNextLinkNamePagesPageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that must ignore any kind of nextLink, and stop after page 1. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetNullNextLinkNamePagesNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetNullNextLinkNamePages");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetNullNextLinkNamePagesPageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetSinglePagesRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -230,6 +306,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetSinglePagesPageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that finishes on the first call without a nextlink. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetSinglePagesNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetSinglePages");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetSinglePagesPageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesRequest(string? clientRequestId, int? maxresults, int? timeout)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -315,6 +429,59 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesPageRequest(string? clientRequestId, int? maxresults, int? timeout, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
if (clientRequestId != null)
|
||||
{
|
||||
request.Headers.Add("client-request-id", clientRequestId);
|
||||
}
|
||||
if (maxresults != null)
|
||||
{
|
||||
request.Headers.Add("maxresults", maxresults.Value);
|
||||
}
|
||||
if (timeout != null)
|
||||
{
|
||||
request.Headers.Add("timeout", timeout.Value);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that includes a nextLink that has 10 pages. </summary>
|
||||
/// <param name="clientRequestId"> MISSING·PARAMETER-DESCRIPTION. </param>
|
||||
/// <param name="maxresults"> Sets the maximum number of items to return in the response. </param>
|
||||
/// <param name="timeout"> Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesNextPage(string? clientRequestId, int? maxresults, int? timeout, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePages");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesPageRequest(clientRequestId, maxresults, timeout, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetOdataMultiplePagesRequest(string? clientRequestId, int? maxresults, int? timeout)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -400,6 +567,59 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetOdataMultiplePagesPageRequest(string? clientRequestId, int? maxresults, int? timeout, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
if (clientRequestId != null)
|
||||
{
|
||||
request.Headers.Add("client-request-id", clientRequestId);
|
||||
}
|
||||
if (maxresults != null)
|
||||
{
|
||||
request.Headers.Add("maxresults", maxresults.Value);
|
||||
}
|
||||
if (timeout != null)
|
||||
{
|
||||
request.Headers.Add("timeout", timeout.Value);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that includes a nextLink in odata format that has 10 pages. </summary>
|
||||
/// <param name="clientRequestId"> MISSING·PARAMETER-DESCRIPTION. </param>
|
||||
/// <param name="maxresults"> Sets the maximum number of items to return in the response. </param>
|
||||
/// <param name="timeout"> Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<OdataProductResult>> GetOdataMultiplePagesNextPage(string? clientRequestId, int? maxresults, int? timeout, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetOdataMultiplePages");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetOdataMultiplePagesPageRequest(clientRequestId, maxresults, timeout, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = OdataProductResult.DeserializeOdataProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesWithOffsetRequest(string? clientRequestId, int? maxresults, int offset, int? timeout)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -488,6 +708,60 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesWithOffsetPageRequest(string? clientRequestId, int? maxresults, int offset, int? timeout, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
if (clientRequestId != null)
|
||||
{
|
||||
request.Headers.Add("client-request-id", clientRequestId);
|
||||
}
|
||||
if (maxresults != null)
|
||||
{
|
||||
request.Headers.Add("maxresults", maxresults.Value);
|
||||
}
|
||||
if (timeout != null)
|
||||
{
|
||||
request.Headers.Add("timeout", timeout.Value);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that includes a nextLink that has 10 pages. </summary>
|
||||
/// <param name="clientRequestId"> MISSING·PARAMETER-DESCRIPTION. </param>
|
||||
/// <param name="maxresults"> Sets the maximum number of items to return in the response. </param>
|
||||
/// <param name="offset"> Offset of return value. </param>
|
||||
/// <param name="timeout"> Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesWithOffsetNextPage(string? clientRequestId, int? maxresults, int offset, int? timeout, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesWithOffset");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesWithOffsetPageRequest(clientRequestId, maxresults, offset, timeout, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesRetryFirstRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -555,6 +829,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesRetryFirstPageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that fails on the first call with 500 and then retries and then get a response including a nextLink that has 10 pages. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesRetryFirstNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesRetryFirst");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesRetryFirstPageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesRetrySecondRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -622,6 +934,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesRetrySecondPageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that includes a nextLink that has 10 pages, of which the 2nd call fails first with 500. The client should retry and finish all 10 pages eventually. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesRetrySecondNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesRetrySecond");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesRetrySecondPageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetSinglePagesFailureRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -689,6 +1039,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetSinglePagesFailurePageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that receives a 400 on the first call. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetSinglePagesFailureNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetSinglePagesFailure");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetSinglePagesFailurePageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFailureRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -756,6 +1144,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFailurePageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that receives a 400 on the second call. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesFailureNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesFailure");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesFailurePageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFailureUriRequest()
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -823,6 +1249,44 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFailureUriPageRequest(string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that receives an invalid nextLink. </summary>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesFailureUriNextPage(string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesFailureUri");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesFailureUriPageRequest(nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFragmentNextLinkRequest(string apiVersion, string tenant)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -912,6 +1376,55 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFragmentNextLinkPageRequest(string apiVersion, string tenant, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
request.Uri.AppendQuery("api_version", apiVersion, true);
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that doesn't return a full URL, just a fragment. </summary>
|
||||
/// <param name="apiVersion"> Sets the api version to use. </param>
|
||||
/// <param name="tenant"> Sets the tenant to use. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<OdataProductResult>> GetMultiplePagesFragmentNextLinkNextPage(string apiVersion, string tenant, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (apiVersion == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(apiVersion));
|
||||
}
|
||||
if (tenant == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tenant));
|
||||
}
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesFragmentNextLink");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesFragmentNextLinkPageRequest(apiVersion, tenant, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = OdataProductResult.DeserializeOdataProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFragmentWithGroupingNextLinkRequest(string apiVersion, string tenant)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -1001,6 +1514,55 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesFragmentWithGroupingNextLinkPageRequest(string apiVersion, string tenant, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
request.Uri.AppendQuery("api_version", apiVersion, true);
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that doesn't return a full URL, just a fragment with parameters grouped. </summary>
|
||||
/// <param name="apiVersion"> Sets the api version to use. </param>
|
||||
/// <param name="tenant"> Sets the tenant to use. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<OdataProductResult>> GetMultiplePagesFragmentWithGroupingNextLinkNextPage(string apiVersion, string tenant, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (apiVersion == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(apiVersion));
|
||||
}
|
||||
if (tenant == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tenant));
|
||||
}
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesFragmentWithGroupingNextLink");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesFragmentWithGroupingNextLinkPageRequest(apiVersion, tenant, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = OdataProductResult.DeserializeOdataProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesLRORequest(string? clientRequestId, int? maxresults, int? timeout)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -1086,6 +1648,59 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateGetMultiplePagesLROPageRequest(string? clientRequestId, int? maxresults, int? timeout, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Post;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
if (clientRequestId != null)
|
||||
{
|
||||
request.Headers.Add("client-request-id", clientRequestId);
|
||||
}
|
||||
if (maxresults != null)
|
||||
{
|
||||
request.Headers.Add("maxresults", maxresults.Value);
|
||||
}
|
||||
if (timeout != null)
|
||||
{
|
||||
request.Headers.Add("timeout", timeout.Value);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
/// <summary> A long-running paging operation that includes a nextLink that has 10 pages. </summary>
|
||||
/// <param name="clientRequestId"> MISSING·PARAMETER-DESCRIPTION. </param>
|
||||
/// <param name="maxresults"> Sets the maximum number of items to return in the response. </param>
|
||||
/// <param name="timeout"> Sets the maximum time that the server can spend processing the request, in seconds. The default is 30 seconds. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<ProductResult>> GetMultiplePagesLRONextPage(string? clientRequestId, int? maxresults, int? timeout, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.GetMultiplePagesLRO");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateGetMultiplePagesLROPageRequest(clientRequestId, maxresults, timeout, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 202:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = ProductResult.DeserializeProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateNextFragmentRequest(string apiVersion, string tenant, string nextLink)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -1187,6 +1802,60 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateNextFragmentPageRequest(string apiVersion, string tenant, string nextLink, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
request.Uri.AppendQuery("api_version", apiVersion, true);
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that doesn't return a full URL, just a fragment. </summary>
|
||||
/// <param name="apiVersion"> Sets the api version to use. </param>
|
||||
/// <param name="tenant"> Sets the tenant to use. </param>
|
||||
/// <param name="nextLink"> Next link for list operation. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<OdataProductResult>> NextFragmentNextPage(string apiVersion, string tenant, string nextLink, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (apiVersion == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(apiVersion));
|
||||
}
|
||||
if (tenant == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tenant));
|
||||
}
|
||||
if (nextLink == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nextLink));
|
||||
}
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.NextFragment");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateNextFragmentPageRequest(apiVersion, tenant, nextLink, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = OdataProductResult.DeserializeOdataProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateNextFragmentWithGroupingRequest(string apiVersion, string tenant, string nextLink)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
|
@ -1288,5 +1957,59 @@ namespace paging
|
|||
throw;
|
||||
}
|
||||
}
|
||||
internal HttpMessage CreateNextFragmentWithGroupingPageRequest(string apiVersion, string tenant, string nextLink, string? nextLinkUrl)
|
||||
{
|
||||
var message = pipeline.CreateMessage();
|
||||
var request = message.Request;
|
||||
request.Method = RequestMethod.Get;
|
||||
request.Uri.Reset(new Uri(nextLinkUrl));
|
||||
request.Uri.AppendQuery("api_version", apiVersion, true);
|
||||
return message;
|
||||
}
|
||||
/// <summary> A paging operation that doesn't return a full URL, just a fragment. </summary>
|
||||
/// <param name="apiVersion"> Sets the api version to use. </param>
|
||||
/// <param name="tenant"> Sets the tenant to use. </param>
|
||||
/// <param name="nextLink"> Next link for list operation. </param>
|
||||
/// <param name="nextLinkUrl"> The URL to the next page of results. </param>
|
||||
/// <param name="cancellationToken"> The cancellation token to use. </param>
|
||||
public async ValueTask<Response<OdataProductResult>> NextFragmentWithGroupingNextPage(string apiVersion, string tenant, string nextLink, string nextLinkUrl, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (apiVersion == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(apiVersion));
|
||||
}
|
||||
if (tenant == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(tenant));
|
||||
}
|
||||
if (nextLink == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(nextLink));
|
||||
}
|
||||
|
||||
using var scope = clientDiagnostics.CreateScope("PagingOperations.NextFragmentWithGrouping");
|
||||
scope.Start();
|
||||
try
|
||||
{
|
||||
using var message = CreateNextFragmentWithGroupingPageRequest(apiVersion, tenant, nextLink, nextLinkUrl);
|
||||
await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
|
||||
switch (message.Response.Status)
|
||||
{
|
||||
case 200:
|
||||
{
|
||||
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
|
||||
var value = OdataProductResult.DeserializeOdataProductResult(document.RootElement);
|
||||
return Response.FromValue(value, message.Response);
|
||||
}
|
||||
default:
|
||||
throw await message.Response.CreateRequestFailedExceptionAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
scope.Failed(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче