| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.ResourceManager.Network.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.ResourceManager.Network |
| | 18 | | { |
| | 19 | | /// <summary> Returns the list of currently active sessions on the Bastion. </summary> |
| | 20 | | public partial class ServiceGetActiveSessionsOperation : Operation<AsyncPageable<BastionActiveSession>>, IOperationS |
| | 21 | | { |
| | 22 | | private readonly ArmOperationHelpers<AsyncPageable<BastionActiveSession>> _operation; |
| | 23 | | private readonly Func<string, Task<Response>> _nextPageFunc; |
| 0 | 24 | | internal ServiceGetActiveSessionsOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request r |
| | 25 | | { |
| 0 | 26 | | _operation = new ArmOperationHelpers<AsyncPageable<BastionActiveSession>>(this, clientDiagnostics, pipeline, |
| 0 | 27 | | _nextPageFunc = nextPageFunc; |
| 0 | 28 | | } |
| | 29 | | /// <inheritdoc /> |
| 0 | 30 | | public override string Id => _operation.Id; |
| | 31 | |
|
| | 32 | | /// <inheritdoc /> |
| 0 | 33 | | public override AsyncPageable<BastionActiveSession> Value => _operation.Value; |
| | 34 | |
|
| | 35 | | /// <inheritdoc /> |
| 0 | 36 | | public override bool HasCompleted => _operation.HasCompleted; |
| | 37 | |
|
| | 38 | | /// <inheritdoc /> |
| 0 | 39 | | public override bool HasValue => _operation.HasValue; |
| | 40 | |
|
| | 41 | | /// <inheritdoc /> |
| 0 | 42 | | public override Response GetRawResponse() => _operation.GetRawResponse(); |
| | 43 | |
|
| | 44 | | /// <inheritdoc /> |
| 0 | 45 | | public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus( |
| | 46 | |
|
| | 47 | | /// <inheritdoc /> |
| 0 | 48 | | public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operati |
| | 49 | |
|
| | 50 | | /// <inheritdoc /> |
| 0 | 51 | | public override ValueTask<Response<AsyncPageable<BastionActiveSession>>> WaitForCompletionAsync(CancellationToke |
| | 52 | |
|
| | 53 | | /// <inheritdoc /> |
| 0 | 54 | | public override ValueTask<Response<AsyncPageable<BastionActiveSession>>> WaitForCompletionAsync(TimeSpan polling |
| | 55 | |
|
| | 56 | | AsyncPageable<BastionActiveSession> IOperationSource<AsyncPageable<BastionActiveSession>>.CreateResult(Response |
| | 57 | | { |
| | 58 | | BastionActiveSessionListResult firstPageResult; |
| 0 | 59 | | using var document = JsonDocument.Parse(response.ContentStream); |
| 0 | 60 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 61 | | { |
| 0 | 62 | | firstPageResult = null; |
| | 63 | | } |
| | 64 | | else |
| | 65 | | { |
| 0 | 66 | | firstPageResult = BastionActiveSessionListResult.DeserializeBastionActiveSessionListResult(document.Root |
| | 67 | | } |
| 0 | 68 | | Page<BastionActiveSession> firstPage = Page.FromValues(firstPageResult.Value, firstPageResult.NextLink, resp |
| | 69 | |
|
| 0 | 70 | | return PageableHelpers.CreateAsyncEnumerable(_ => Task.FromResult(firstPage), (nextLink, _) => GetNextPage(n |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | async ValueTask<AsyncPageable<BastionActiveSession>> IOperationSource<AsyncPageable<BastionActiveSession>>.Creat |
| | 74 | | { |
| | 75 | | BastionActiveSessionListResult firstPageResult; |
| 0 | 76 | | using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).Confi |
| 0 | 77 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 78 | | { |
| 0 | 79 | | firstPageResult = null; |
| | 80 | | } |
| | 81 | | else |
| | 82 | | { |
| 0 | 83 | | firstPageResult = BastionActiveSessionListResult.DeserializeBastionActiveSessionListResult(document.Root |
| | 84 | | } |
| 0 | 85 | | Page<BastionActiveSession> firstPage = Page.FromValues(firstPageResult.Value, firstPageResult.NextLink, resp |
| | 86 | |
|
| 0 | 87 | | return PageableHelpers.CreateAsyncEnumerable(_ => Task.FromResult(firstPage), (nextLink, _) => GetNextPage(n |
| 0 | 88 | | } |
| | 89 | |
|
| | 90 | | private async Task<Page<BastionActiveSession>> GetNextPage(string nextLink, CancellationToken cancellationToken) |
| | 91 | | { |
| 0 | 92 | | Response response = await _nextPageFunc(nextLink).ConfigureAwait(false); |
| | 93 | | BastionActiveSessionListResult nextPageResult; |
| 0 | 94 | | using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).Confi |
| 0 | 95 | | if (document.RootElement.ValueKind == JsonValueKind.Null) |
| | 96 | | { |
| 0 | 97 | | nextPageResult = null; |
| | 98 | | } |
| | 99 | | else |
| | 100 | | { |
| 0 | 101 | | nextPageResult = BastionActiveSessionListResult.DeserializeBastionActiveSessionListResult(document.RootE |
| | 102 | | } |
| 0 | 103 | | return Page.FromValues(nextPageResult.Value, nextPageResult.NextLink, response); |
| 0 | 104 | | } |
| | 105 | | } |
| | 106 | | } |