Skip to content
Merged
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
50 changes: 25 additions & 25 deletions sdk/core/System.ClientModel/api/System.ClientModel.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ public ApiKeyCredential(string key) { }
public static implicit operator System.ClientModel.ApiKeyCredential (string key) { throw null; }
public void Update(string key) { }
}
public abstract partial class AsyncClientPageable<T> : System.ClientModel.AsyncCollectionResult<T>
{
protected AsyncClientPageable() { }
public System.Collections.Generic.IAsyncEnumerable<System.ClientModel.ClientPage<T>> AsPages(string fromPage = "") { throw null; }
public override System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.Task<System.ClientModel.ClientPage<T>> GetPageAsync(string pageToken) { throw null; }
protected abstract System.Threading.Tasks.Task<System.ClientModel.ClientPage<T>> GetPageCoreAsync(string pageToken);
}
public abstract partial class AsyncCollectionResult<T> : System.ClientModel.ClientResult, System.Collections.Generic.IAsyncEnumerable<T>
{
protected internal AsyncCollectionResult() { }
protected internal AsyncCollectionResult(System.ClientModel.Primitives.PipelineResponse response) { }
public abstract System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
public abstract partial class AsyncPageableResult<T> : System.ClientModel.AsyncCollectionResult<T>
{
protected AsyncPageableResult() { }
public System.Collections.Generic.IAsyncEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPages(string startPageToken = "") { throw null; }
protected abstract System.Collections.Generic.IAsyncEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPagesCore(string startPageToken);
public override System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<System.ClientModel.Primitives.ClientPage<T>> GetPageAsync(string pageToken = "") { throw null; }
}
public abstract partial class BinaryContent : System.IDisposable
{
protected BinaryContent() { }
Expand All @@ -32,6 +32,23 @@ protected BinaryContent() { }
public abstract void WriteTo(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
public abstract System.Threading.Tasks.Task WriteToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
public abstract partial class ClientPageable<T> : System.ClientModel.CollectionResult<T>
{
protected ClientPageable() { }
public System.Collections.Generic.IEnumerable<System.ClientModel.ClientPage<T>> AsPages(string fromPage = "") { throw null; }
public override System.Collections.Generic.IEnumerator<T> GetEnumerator() { throw null; }
public System.ClientModel.ClientPage<T> GetPage(string pageToken) { throw null; }
protected abstract System.ClientModel.ClientPage<T> GetPageCore(string pageToken);
}
public partial class ClientPage<T> : System.ClientModel.ClientResult
{
internal ClientPage() { }
public const string DefaultFirstPageToken = "";
public string? NextPageToken { get { throw null; } }
public string? PreviousPageToken { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<T> Values { get { throw null; } }
public static System.ClientModel.ClientPage<T> Create(System.Collections.Generic.IReadOnlyList<T> values, System.ClientModel.Primitives.PipelineResponse response, string? nextPageToken, string? previousPageToken = null) { throw null; }
}
public partial class ClientResult
{
protected ClientResult() { }
Expand Down Expand Up @@ -63,14 +80,6 @@ protected internal CollectionResult(System.ClientModel.Primitives.PipelineRespon
public abstract System.Collections.Generic.IEnumerator<T> GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
}
public abstract partial class PageableResult<T> : System.ClientModel.CollectionResult<T>
{
protected PageableResult() { }
public System.Collections.Generic.IEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPages(string startPageToken = "") { throw null; }
protected abstract System.Collections.Generic.IEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPagesCore(string startPageToken);
public override System.Collections.Generic.IEnumerator<T> GetEnumerator() { throw null; }
public virtual System.ClientModel.Primitives.ClientPage<T> GetPage(string pageToken = "") { throw null; }
}
}
namespace System.ClientModel.Primitives
{
Expand All @@ -89,15 +98,6 @@ public enum ClientErrorBehaviors
Default = 0,
NoThrow = 1,
}
public partial class ClientPage<T> : System.ClientModel.ClientResult
{
internal ClientPage() { }
public const string First = "";
public string? NextPageToken { get { throw null; } }
public string? PreviousPageToken { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<T> Values { get { throw null; } }
public static System.ClientModel.Primitives.ClientPage<T> Create(System.Collections.Generic.IReadOnlyList<T> values, System.ClientModel.Primitives.PipelineResponse response, string? nextPageToken, string? previousPageToken = null) { throw null; }
}
public sealed partial class ClientPipeline
{
internal ClientPipeline() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ public ApiKeyCredential(string key) { }
public static implicit operator System.ClientModel.ApiKeyCredential (string key) { throw null; }
public void Update(string key) { }
}
public abstract partial class AsyncClientPageable<T> : System.ClientModel.AsyncCollectionResult<T>
{
protected AsyncClientPageable() { }
public System.Collections.Generic.IAsyncEnumerable<System.ClientModel.ClientPage<T>> AsPages(string fromPage = "") { throw null; }
public override System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public System.Threading.Tasks.Task<System.ClientModel.ClientPage<T>> GetPageAsync(string pageToken) { throw null; }
protected abstract System.Threading.Tasks.Task<System.ClientModel.ClientPage<T>> GetPageCoreAsync(string pageToken);
}
public abstract partial class AsyncCollectionResult<T> : System.ClientModel.ClientResult, System.Collections.Generic.IAsyncEnumerable<T>
{
protected internal AsyncCollectionResult() { }
protected internal AsyncCollectionResult(System.ClientModel.Primitives.PipelineResponse response) { }
public abstract System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
public abstract partial class AsyncPageableResult<T> : System.ClientModel.AsyncCollectionResult<T>
{
protected AsyncPageableResult() { }
public System.Collections.Generic.IAsyncEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPages(string startPageToken = "") { throw null; }
protected abstract System.Collections.Generic.IAsyncEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPagesCore(string startPageToken);
public override System.Collections.Generic.IAsyncEnumerator<T> GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<System.ClientModel.Primitives.ClientPage<T>> GetPageAsync(string pageToken = "") { throw null; }
}
public abstract partial class BinaryContent : System.IDisposable
{
protected BinaryContent() { }
Expand All @@ -32,6 +32,23 @@ protected BinaryContent() { }
public abstract void WriteTo(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
public abstract System.Threading.Tasks.Task WriteToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
public abstract partial class ClientPageable<T> : System.ClientModel.CollectionResult<T>
{
protected ClientPageable() { }
public System.Collections.Generic.IEnumerable<System.ClientModel.ClientPage<T>> AsPages(string fromPage = "") { throw null; }
public override System.Collections.Generic.IEnumerator<T> GetEnumerator() { throw null; }
public System.ClientModel.ClientPage<T> GetPage(string pageToken) { throw null; }
protected abstract System.ClientModel.ClientPage<T> GetPageCore(string pageToken);
}
public partial class ClientPage<T> : System.ClientModel.ClientResult
{
internal ClientPage() { }
public const string DefaultFirstPageToken = "";
public string? NextPageToken { get { throw null; } }
public string? PreviousPageToken { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<T> Values { get { throw null; } }
public static System.ClientModel.ClientPage<T> Create(System.Collections.Generic.IReadOnlyList<T> values, System.ClientModel.Primitives.PipelineResponse response, string? nextPageToken, string? previousPageToken = null) { throw null; }
}
public partial class ClientResult
{
protected ClientResult() { }
Expand Down Expand Up @@ -63,14 +80,6 @@ protected internal CollectionResult(System.ClientModel.Primitives.PipelineRespon
public abstract System.Collections.Generic.IEnumerator<T> GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
}
public abstract partial class PageableResult<T> : System.ClientModel.CollectionResult<T>
{
protected PageableResult() { }
public System.Collections.Generic.IEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPages(string startPageToken = "") { throw null; }
protected abstract System.Collections.Generic.IEnumerable<System.ClientModel.Primitives.ClientPage<T>> AsPagesCore(string startPageToken);
public override System.Collections.Generic.IEnumerator<T> GetEnumerator() { throw null; }
public virtual System.ClientModel.Primitives.ClientPage<T> GetPage(string pageToken = "") { throw null; }
}
}
namespace System.ClientModel.Primitives
{
Expand All @@ -89,15 +98,6 @@ public enum ClientErrorBehaviors
Default = 0,
NoThrow = 1,
}
public partial class ClientPage<T> : System.ClientModel.ClientResult
{
internal ClientPage() { }
public const string First = "";
public string? NextPageToken { get { throw null; } }
public string? PreviousPageToken { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<T> Values { get { throw null; } }
public static System.ClientModel.Primitives.ClientPage<T> Create(System.Collections.Generic.IReadOnlyList<T> values, System.ClientModel.Primitives.PipelineResponse response, string? nextPageToken, string? previousPageToken = null) { throw null; }
}
public sealed partial class ClientPipeline
{
internal ClientPipeline() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,85 @@ namespace System.ClientModel;
/// Represents a collection of values returned from a cloud service operation
/// sequentially over one or more calls to the service.
/// </summary>
public abstract class AsyncPageableResult<T> : AsyncCollectionResult<T>
public abstract class AsyncClientPageable<T> : AsyncCollectionResult<T>
{
/// <summary>
/// Create a new instance of <see cref="AsyncPageableResult{T}"/>.
/// Create a new instance of <see cref="AsyncClientPageable{T}"/>.
/// </summary>
/// <remarks>This constructor does not take a <see cref="PipelineResponse"/>
/// because derived types are expected to defer the first service call
/// until the collection is enumerated using <c>await foreach</c>.
/// </remarks>
protected AsyncPageableResult() : base()
protected AsyncClientPageable() : base()
{
}

/// <summary>
/// TBD.
/// </summary>
public virtual async Task<ClientPage<T>> GetPageAsync(string pageToken = ClientPage<T>.First)
public async Task<ClientPage<T>> GetPageAsync(string pageToken)
{
Argument.AssertNotNull(pageToken, nameof(pageToken));

await foreach (ClientPage<T> page in AsPages(pageToken).ConfigureAwait(false))
{
return page;
}

throw new ArgumentOutOfRangeException(nameof(pageToken), $"No pages returned for pageToken '{pageToken}'.");
return await GetPageCoreAsync(pageToken).ConfigureAwait(false);
}

/// <summary>
/// Convert this <see cref="PageableResult{T}"/> to a collection of pages
/// TBD.
/// </summary>
/// <param name="pageToken"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException">If no page can be retrieved
/// from <paramref name="pageToken"/>.</exception>
protected abstract Task<ClientPage<T>> GetPageCoreAsync(string pageToken);

/// <summary>
/// Convert this <see cref="ClientPageable{T}"/> to a collection of pages
/// instead of a collection of the individual values of type
/// <typeparamref name="T"/>. Enumerating this collection will typically
/// make one service request for each page item.
/// </summary>
/// <param name="startPageToken">A token indicating the first page that will be
/// <param name="fromPage">A token indicating the first page that will be
/// requested when the returned collection is enumerated. If no
/// <paramref name="startPageToken"/> value is specified, the first page in the
/// <paramref name="fromPage"/> value is specified, the first page in the
/// returned collection will be the first page of values returned from the
/// service.</param>
/// <returns>An enumerable of <see cref="ClientPage{T}"/> that enumerates the
/// collection's pages instead of the collection's individual values,
/// starting at the page indicated by <paramref name="startPageToken"/>.
/// starting at the page indicated by <paramref name="fromPage"/>.
/// </returns>
public IAsyncEnumerable<ClientPage<T>> AsPages(string startPageToken = ClientPage<T>.First)
public IAsyncEnumerable<ClientPage<T>> AsPages(string fromPage = ClientPage<T>.DefaultFirstPageToken)
{
Argument.AssertNotNull(startPageToken, nameof(startPageToken));
Argument.AssertNotNull(fromPage, nameof(fromPage));

return AsPagesCore(startPageToken);
return new AsyncPageCollection(this, fromPage);
}

/// <summary>
/// TBD.
/// </summary>
protected abstract IAsyncEnumerable<ClientPage<T>> AsPagesCore(string startPageToken);
// TODO: Qn - AsPagesAsync? Why or why not? What is the "correct" .NET pattern
// here?
private class AsyncPageCollection : IAsyncEnumerable<ClientPage<T>>
{
private readonly AsyncClientPageable<T> _pageable;
private readonly string _fromPage;

public AsyncPageCollection(AsyncClientPageable<T> pageable, string fromPage)
{
_pageable = pageable;
_fromPage = fromPage;
}

public async IAsyncEnumerator<ClientPage<T>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
string? pageToken = _fromPage;
while (pageToken != null)
{
ClientPage<T> page = await _pageable.GetPageAsync(pageToken).ConfigureAwait(false);
_pageable.SetRawResponse(page.GetRawResponse());
yield return page;
pageToken = page.NextPageToken;
}
}
}

/// <summary>
/// Return an enumerator that iterates asynchronously through the collection
Expand Down
13 changes: 6 additions & 7 deletions sdk/core/System.ClientModel/src/Convenience/ClientPageOfT.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.ClientModel.Primitives;
using System.Collections.Generic;

namespace System.ClientModel.Primitives;
namespace System.ClientModel;

/// <summary>
/// Represents the subset (or page) of values contained in a single response
Expand All @@ -15,9 +16,7 @@ public class ClientPage<T> : ClientResult
/// <summary>
/// TBD.
/// </summary>
// TODO: Think about the difference between this and FirstPageToken property --
// what is the DevEx there and is it confusing?
public const string First = "";
public const string DefaultFirstPageToken = "";

private ClientPage(IReadOnlyList<T> values,
PipelineResponse response,
Expand Down Expand Up @@ -59,7 +58,7 @@ public static ClientPage<T> Create(IReadOnlyList<T> values,

/// <summary>
/// Gets a token that can be used to request the next page of results from
/// a <see cref="PageableResult{T}"/>, <see cref="AsyncPageableResult{T}"/>,
/// a <see cref="ClientPageable{T}"/>, <see cref="AsyncClientPageable{T}"/>,
/// or a client method that returns one of these types.
/// May be <c>null</c> or empty when no values remain to be returned from
/// the collection.
Expand All @@ -68,8 +67,8 @@ public static ClientPage<T> Create(IReadOnlyList<T> values,

/// <summary>
/// Gets a token that can be used to request the previous page of results
/// from a <see cref="PageableResult{T}"/>,
/// <see cref="AsyncPageableResult{T}"/>, or a client method that returns
/// from a <see cref="ClientPageable{T}"/>,
/// <see cref="AsyncClientPageable{T}"/>, or a client method that returns
/// one of these types.
/// May be <c>null</c> when no page preceeds the current page, or when no
/// token is available for the previous page.
Expand Down
Loading