Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class CollectionResultDefinition : TypeProvider
protected InputOperation Operation { get; }
protected InputPagingServiceMetadata Paging { get; }

public string ScopeName { get; }

protected internal FieldProvider? PageSizeField { get; }

protected FieldProvider RequestOptionsField => _requestOptionsField ??= RequestFields
Expand Down Expand Up @@ -77,6 +79,7 @@ public CollectionResultDefinition(ClientProvider client, InputPagingServiceMetho
Paging = serviceMethod.PagingMetadata;
IsAsync = isAsync;
ItemModelType = itemModelType;
ScopeName = $"{Client.Name}.{Operation.Name.ToIdentifierName()}";

var response = Operation.Responses.FirstOrDefault(r => !r.IsErrorResponse);
ResponseModel = ScmCodeModelGenerator.Instance.TypeFactory.CreateModel((InputModelType)response!.BodyType!)!;
Expand Down Expand Up @@ -272,6 +275,8 @@ private MethodBodyStatement[] BuildConstructorBody(ParameterProvider clientParam
return statements.ToArray();
}

private string GetNextResponseMethodName => IsAsync ? "GetNextResponseAsync" : "GetNextResponse";

protected override MethodProvider[] BuildMethods()
{
MethodBodyStatement[] getRawPagesMethodBody = (Paging.NextLink, Paging.ContinuationToken) switch
Expand Down Expand Up @@ -328,9 +333,40 @@ protected override MethodProvider[] BuildMethods()
this));
}

methods.Add(BuildGetNextResponseMethod());

return methods.ToArray();
}

private MethodProvider BuildGetNextResponseMethod()
{
var messageParameter = new ParameterProvider(
"message",
$"The pipeline message containing the request to send.",
ScmCodeModelGenerator.Instance.TypeFactory.HttpMessageApi.HttpMessageType);

var signature = new MethodSignature(
GetNextResponseMethodName,
$"Sends the request in the pipeline message and returns the response.",
IsAsync ? MethodSignatureModifiers.Private | MethodSignatureModifiers.Async : MethodSignatureModifiers.Private,
IsAsync
? new CSharpType(typeof(ValueTask<>), typeof(ClientResult))
: new CSharpType(typeof(ClientResult)),
null,
[messageParameter]);

var processMessageExpression = ScmCodeModelGenerator.Instance.TypeFactory.ClientResponseApi.ToExpression().FromResponse(
ClientField.Property("Pipeline").ToApi<ClientPipelineApi>().ProcessMessage(
messageParameter.ToApi<HttpMessageApi>(),
RequestOptionsField.AsValueExpression.ToApi<HttpRequestOptionsApi>(),
IsAsync)).ToApi<ClientResponseApi>();

return new MethodProvider(
signature,
Return(processMessageExpression),
this);
}

private MethodBodyStatement[] BuildGetValuesFromPages()
{
var items = GetPropertyExpression(Paging.ItemPropertySegments, PageParameter.AsVariable());
Expand Down Expand Up @@ -426,11 +462,7 @@ private MethodBodyStatement[] BuildGetRawPagesForNextLink()
{
Declare(
"result",
ScmCodeModelGenerator.Instance.TypeFactory.ClientResponseApi.ToExpression().FromResponse(
ClientField.Property("Pipeline").ToApi<ClientPipelineApi>().ProcessMessage(
message.ToApi<HttpMessageApi>(),
RequestOptionsField.AsValueExpression.ToApi<HttpRequestOptionsApi>(),
IsAsync)).ToApi<ClientResponseApi>(),
This.Invoke(GetNextResponseMethodName, [message], IsAsync).ToApi<ClientResponseApi>(),
out ClientResponseApi result),

// Yield return result
Expand Down Expand Up @@ -465,11 +497,7 @@ private MethodBodyStatement[] BuildGetRawPagesForContinuationToken()
{
Declare(
"result",
ScmCodeModelGenerator.Instance.TypeFactory.ClientResponseApi.ToExpression().FromResponse(
ClientField.Property("Pipeline").ToApi<ClientPipelineApi>().ProcessMessage(
message.ToApi<HttpMessageApi>(),
RequestOptionsField.AsValueExpression.ToApi<HttpRequestOptionsApi>(),
IsAsync)).ToApi<ClientResponseApi>(),
This.Invoke(GetNextResponseMethodName, [message], IsAsync).ToApi<ClientResponseApi>(),
out ClientResponseApi result),

// Yield return result
Expand All @@ -491,16 +519,12 @@ private MethodBodyStatement[] BuildGetRawPagesForSingle()
"message",
InvokeCreateInitialRequest(),
out ScopedApi<PipelineMessage> m);
var pipelineResponse = ScmCodeModelGenerator.Instance.TypeFactory.ClientResponseApi.ToExpression().FromResponse(
ClientField.Property("Pipeline").ToApi<ClientPipelineApi>().ProcessMessage(
m.ToApi<HttpMessageApi>(),
RequestOptionsField.AsValueExpression.ToApi<HttpRequestOptionsApi>(),
IsAsync)).ToApi<ClientResponseApi>();
var result = This.Invoke(GetNextResponseMethodName, [m], IsAsync).ToApi<ClientResponseApi>();
return
[
pipelineMessageDeclaration,
// Yield return result
YieldReturn(pipelineResponse),
YieldReturn(result),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
global::System.ClientModel.ClientResult result = this.GetNextResponse(message);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NextPage;
Expand All @@ -53,5 +53,10 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string
return null;
}
}

private global::System.ClientModel.ClientResult GetNextResponse(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;
using Sample.Models;

namespace Sample
Expand All @@ -29,7 +30,7 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
global::System.ClientModel.ClientResult result = await this.GetNextResponseAsync(message).ConfigureAwait(false);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NextPage;
Expand All @@ -53,5 +54,10 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st
return null;
}
}

private async global::System.Threading.Tasks.ValueTask<global::System.ClientModel.ClientResult> GetNextResponseAsync(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CatClientGetCatsCollectionResultOfT(global::Sample.CatClient client, stri
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
global::System.ClientModel.ClientResult result = this.GetNextResponse(message);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NextPage;
Expand Down Expand Up @@ -58,5 +58,10 @@ public CatClientGetCatsCollectionResultOfT(global::Sample.CatClient client, stri
{
return ((global::Sample.Models.Page)page).Cats;
}

private global::System.ClientModel.ClientResult GetNextResponse(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CatClientGetCatsAsyncCollectionResultOfT(global::Sample.CatClient client,
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
global::System.ClientModel.ClientResult result = await this.GetNextResponseAsync(message).ConfigureAwait(false);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NextPage;
Expand Down Expand Up @@ -63,5 +63,10 @@ public CatClientGetCatsAsyncCollectionResultOfT(global::Sample.CatClient client,
await global::System.Threading.Tasks.Task.Yield();
}
}

private async global::System.Threading.Tasks.ValueTask<global::System.ClientModel.ClientResult> GetNextResponseAsync(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
global::System.ClientModel.ClientResult result = this.GetNextResponse(message);
yield return result;

if ((result.GetRawResponse().Headers.TryGetValue("nextPage", out string value) && !string.IsNullOrEmpty(value)))
Expand All @@ -54,5 +54,10 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string
return null;
}
}

private global::System.ClientModel.ClientResult GetNextResponse(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sample
{
Expand All @@ -28,7 +29,7 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
global::System.ClientModel.ClientResult result = await this.GetNextResponseAsync(message).ConfigureAwait(false);
yield return result;

if ((result.GetRawResponse().Headers.TryGetValue("nextPage", out string value) && !string.IsNullOrEmpty(value)))
Expand All @@ -54,5 +55,10 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st
return null;
}
}

private async global::System.Threading.Tasks.ValueTask<global::System.ClientModel.ClientResult> GetNextResponseAsync(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CatClientGetCatsCollectionResultOfT(global::Sample.CatClient client, stri
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
global::System.ClientModel.ClientResult result = this.GetNextResponse(message);
yield return result;

if ((result.GetRawResponse().Headers.TryGetValue("nextPage", out string value) && !string.IsNullOrEmpty(value)))
Expand Down Expand Up @@ -60,5 +60,10 @@ public CatClientGetCatsCollectionResultOfT(global::Sample.CatClient client, stri
{
return ((global::Sample.Models.Page)page).Cats;
}

private global::System.ClientModel.ClientResult GetNextResponse(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CatClientGetCatsAsyncCollectionResultOfT(global::Sample.CatClient client,
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
global::System.ClientModel.ClientResult result = await this.GetNextResponseAsync(message).ConfigureAwait(false);
yield return result;

if ((result.GetRawResponse().Headers.TryGetValue("nextPage", out string value) && !string.IsNullOrEmpty(value)))
Expand Down Expand Up @@ -65,5 +65,10 @@ public CatClientGetCatsAsyncCollectionResultOfT(global::Sample.CatClient client,
await global::System.Threading.Tasks.Task.Yield();
}
}

private async global::System.Threading.Tasks.ValueTask<global::System.ClientModel.ClientResult> GetNextResponseAsync(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
global::System.ClientModel.ClientResult result = this.GetNextResponse(message);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NestedNext?.NextPage;
Expand All @@ -53,5 +53,10 @@ public CatClientGetCatsCollectionResult(global::Sample.CatClient client, string
return null;
}
}

private global::System.ClientModel.ClientResult GetNextResponse(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Threading.Tasks;
using Sample.Models;

namespace Sample
Expand All @@ -29,7 +30,7 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
global::System.ClientModel.ClientResult result = await this.GetNextResponseAsync(message).ConfigureAwait(false);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NestedNext?.NextPage;
Expand All @@ -53,5 +54,10 @@ public CatClientGetCatsAsyncCollectionResult(global::Sample.CatClient client, st
return null;
}
}

private async global::System.Threading.Tasks.ValueTask<global::System.ClientModel.ClientResult> GetNextResponseAsync(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CatClientGetCatsCollectionResultOfT(global::Sample.CatClient client, stri
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
global::System.ClientModel.ClientResult result = this.GetNextResponse(message);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NestedNext?.NextPage;
Expand Down Expand Up @@ -58,5 +58,10 @@ public CatClientGetCatsCollectionResultOfT(global::Sample.CatClient client, stri
{
return ((global::Sample.Models.Page)page).NestedItems?.Cats;
}

private global::System.ClientModel.ClientResult GetNextResponse(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CatClientGetCatsAsyncCollectionResultOfT(global::Sample.CatClient client,
string nextToken = null;
while (true)
{
global::System.ClientModel.ClientResult result = global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
global::System.ClientModel.ClientResult result = await this.GetNextResponseAsync(message).ConfigureAwait(false);
yield return result;

nextToken = ((global::Sample.Models.Page)result).NestedNext?.NextPage;
Expand Down Expand Up @@ -63,5 +63,10 @@ public CatClientGetCatsAsyncCollectionResultOfT(global::Sample.CatClient client,
await global::System.Threading.Tasks.Task.Yield();
}
}

private async global::System.Threading.Tasks.ValueTask<global::System.ClientModel.ClientResult> GetNextResponseAsync(global::System.ClientModel.Primitives.PipelineMessage message)
{
return global::System.ClientModel.ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
}
}
}
Loading
Loading