diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/Microsoft.App.DynamicSessions.sln b/sdk/microsoft.app/Microsoft.App.DynamicSessions/Microsoft.App.DynamicSessions.sln new file mode 100644 index 000000000000..1e89be24951a --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/Microsoft.App.DynamicSessions.sln @@ -0,0 +1,50 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.App.DynamicSessions", "src\Microsoft.App.DynamicSessions.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.App.DynamicSessions.Tests", "tests\Microsoft.App.DynamicSessions.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/CodeExecution.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/CodeExecution.cs new file mode 100644 index 000000000000..1ad451e837bc --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/CodeExecution.cs @@ -0,0 +1,355 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + // Data plane generated sub-client. + /// The CodeExecution sub-client. + public partial class CodeExecution + { + private static readonly string[] AuthorizationScopes = new string[] { "https://dynamicsessions.io/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of CodeExecution for mocking. + protected CodeExecution() + { + } + + /// Initializes a new instance of CodeExecution. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The token credential to copy. + /// The management endpoint of the session pool. + /// The API version to use for this operation. + internal CodeExecution(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, TokenCredential tokenCredential, Uri endpoint, string apiVersion) + { + ClientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + _tokenCredential = tokenCredential; + _endpoint = endpoint; + _apiVersion = apiVersion; + } + + /// Get the code execution result. + /// Session code execution id. + /// The user-assigned identifier of the session. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// + public virtual async Task> GetSessionCodeExecutionResourceAsync(string executionId, string identifier, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(executionId, nameof(executionId)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetSessionCodeExecutionResourceAsync(executionId, identifier, context).ConfigureAwait(false); + return Response.FromValue(SessionCodeExecutionResource.FromResponse(response), response); + } + + /// Get the code execution result. + /// Session code execution id. + /// The user-assigned identifier of the session. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// + public virtual Response GetSessionCodeExecutionResource(string executionId, string identifier, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(executionId, nameof(executionId)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetSessionCodeExecutionResource(executionId, identifier, context); + return Response.FromValue(SessionCodeExecutionResource.FromResponse(response), response); + } + + /// + /// [Protocol Method] Get the code execution result. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// Session code execution id. + /// The user-assigned identifier of the session. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetSessionCodeExecutionResourceAsync(string executionId, string identifier, RequestContext context) + { + Argument.AssertNotNullOrEmpty(executionId, nameof(executionId)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("CodeExecution.GetSessionCodeExecutionResource"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionCodeExecutionResourceRequest(executionId, identifier, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Get the code execution result. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// Session code execution id. + /// The user-assigned identifier of the session. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetSessionCodeExecutionResource(string executionId, string identifier, RequestContext context) + { + Argument.AssertNotNullOrEmpty(executionId, nameof(executionId)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("CodeExecution.GetSessionCodeExecutionResource"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionCodeExecutionResourceRequest(executionId, identifier, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Execute code in a session. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The user-assigned identifier of the session. + /// The request to execute code. + /// The id of this execution operation. + /// The cancellation token to use. + /// or is null. + /// + public virtual async Task> ExecuteAsync(WaitUntil waitUntil, string identifier, SessionCodeExecutionRequest codeExecutionRequest, string operationId = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(codeExecutionRequest, nameof(codeExecutionRequest)); + + using RequestContent content = codeExecutionRequest.ToRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Operation response = await ExecuteAsync(waitUntil, identifier, content, operationId, context).ConfigureAwait(false); + return ProtocolOperationHelpers.Convert(response, FetchSessionCodeExecutionResultFromSessionCodeExecutionResource, ClientDiagnostics, "CodeExecution.Execute"); + } + + /// Execute code in a session. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The user-assigned identifier of the session. + /// The request to execute code. + /// The id of this execution operation. + /// The cancellation token to use. + /// or is null. + /// + public virtual Operation Execute(WaitUntil waitUntil, string identifier, SessionCodeExecutionRequest codeExecutionRequest, string operationId = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(codeExecutionRequest, nameof(codeExecutionRequest)); + + using RequestContent content = codeExecutionRequest.ToRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Operation response = Execute(waitUntil, identifier, content, operationId, context); + return ProtocolOperationHelpers.Convert(response, FetchSessionCodeExecutionResultFromSessionCodeExecutionResource, ClientDiagnostics, "CodeExecution.Execute"); + } + + /// + /// [Protocol Method] Execute code in a session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The user-assigned identifier of the session. + /// The content to send as the body of the request. + /// The id of this execution operation. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The representing an asynchronous operation on the service. + /// + public virtual async Task> ExecuteAsync(WaitUntil waitUntil, string identifier, RequestContent content, string operationId = null, RequestContext context = null) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("CodeExecution.Execute"); + scope.Start(); + try + { + using HttpMessage message = CreateExecuteRequest(identifier, content, operationId, context); + return await ProtocolOperationHelpers.ProcessMessageAsync(_pipeline, message, ClientDiagnostics, "CodeExecution.Execute", OperationFinalStateVia.OperationLocation, context, waitUntil).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Execute code in a session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The user-assigned identifier of the session. + /// The content to send as the body of the request. + /// The id of this execution operation. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The representing an asynchronous operation on the service. + /// + public virtual Operation Execute(WaitUntil waitUntil, string identifier, RequestContent content, string operationId = null, RequestContext context = null) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("CodeExecution.Execute"); + scope.Start(); + try + { + using HttpMessage message = CreateExecuteRequest(identifier, content, operationId, context); + return ProtocolOperationHelpers.ProcessMessage(_pipeline, message, ClientDiagnostics, "CodeExecution.Execute", OperationFinalStateVia.OperationLocation, context, waitUntil); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateExecuteRequest(string identifier, RequestContent content, string operationId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier202); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/executions", false); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + if (operationId != null) + { + request.Headers.Add("operation-id", operationId); + } + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetSessionCodeExecutionResourceRequest(string executionId, string identifier, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/executions/", false); + uri.AppendPath(executionId, true); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier202; + private static ResponseClassifier ResponseClassifier202 => _responseClassifier202 ??= new StatusCodeClassifier(stackalloc ushort[] { 202 }); + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + + private SessionCodeExecutionResult FetchSessionCodeExecutionResultFromSessionCodeExecutionResource(Response response) + { + var resultJsonElement = JsonDocument.Parse(response.Content).RootElement.GetProperty("result"); + return SessionCodeExecutionResult.DeserializeSessionCodeExecutionResult(resultJsonElement); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/CodeInputType.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/CodeInputType.cs new file mode 100644 index 000000000000..6d931a411fcf --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/CodeInputType.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Microsoft.App.DynamicSessions +{ + /// Code input type. + public readonly partial struct CodeInputType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public CodeInputType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InlineValue = "Inline"; + private const string InlineBase64Value = "InlineBase64"; + private const string InlineTextValue = "InlineText"; + + /// Inline. + public static CodeInputType Inline { get; } = new CodeInputType(InlineValue); + /// InlineBase64. + public static CodeInputType InlineBase64 { get; } = new CodeInputType(InlineBase64Value); + /// InlineText. + public static CodeInputType InlineText { get; } = new CodeInputType(InlineTextValue); + /// Determines if two values are the same. + public static bool operator ==(CodeInputType left, CodeInputType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(CodeInputType left, CodeInputType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator CodeInputType(string value) => new CodeInputType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is CodeInputType other && Equals(other); + /// + public bool Equals(CodeInputType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/CodeExecution.xml b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/CodeExecution.xml new file mode 100644 index 000000000000..1f7cf7d6e2b1 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/CodeExecution.xml @@ -0,0 +1,291 @@ + + + + + +This sample shows how to call GetSessionCodeExecutionResourceAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier"); +]]> +This sample shows how to call GetSessionCodeExecutionResourceAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier"); +]]> + + + +This sample shows how to call GetSessionCodeExecutionResource. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier"); +]]> +This sample shows how to call GetSessionCodeExecutionResource. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier"); +]]> + + + +This sample shows how to call GetSessionCodeExecutionResourceAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("executionType").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> +This sample shows how to call GetSessionCodeExecutionResourceAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("executionType").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> + + + +This sample shows how to call GetSessionCodeExecutionResource and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("executionType").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> +This sample shows how to call GetSessionCodeExecutionResource and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("id").ToString()); +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("executionType").ToString()); +Console.WriteLine(result.GetProperty("status").ToString()); +]]> + + + +This sample shows how to call ExecuteAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); +Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); +SessionCodeExecutionResult responseData = operation.Value; +]]> +This sample shows how to call ExecuteAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); +Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); +SessionCodeExecutionResult responseData = operation.Value; +]]> +This sample shows how to call ExecuteAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Synchronous, "print(7*9)", 60L); +Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); +SessionCodeExecutionResult responseData = operation.Value; +]]> + + + +This sample shows how to call Execute. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); +Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); +SessionCodeExecutionResult responseData = operation.Value; +]]> +This sample shows how to call Execute. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); +Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); +SessionCodeExecutionResult responseData = operation.Value; +]]> +This sample shows how to call Execute. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Synchronous, "print(7*9)", 60L); +Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); +SessionCodeExecutionResult responseData = operation.Value; +]]> + + + +This sample shows how to call ExecuteAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = RequestContent.Create(new +{ + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, +}); +Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", content); +BinaryData responseData = operation.Value; + +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.ToString()); +]]> +This sample shows how to call ExecuteAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = RequestContent.Create(new +{ + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, +}); +Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", content); +BinaryData responseData = operation.Value; + +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.ToString()); +]]> +This sample shows how to call ExecuteAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = RequestContent.Create(new +{ + codeInputType = "Inline", + executionType = "Synchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, +}); +Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", content); +BinaryData responseData = operation.Value; + +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + +This sample shows how to call Execute and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = RequestContent.Create(new +{ + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, +}); +Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", content); +BinaryData responseData = operation.Value; + +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.ToString()); +]]> +This sample shows how to call Execute and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = RequestContent.Create(new +{ + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, +}); +Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", content); +BinaryData responseData = operation.Value; + +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.ToString()); +]]> +This sample shows how to call Execute and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = RequestContent.Create(new +{ + codeInputType = "Inline", + executionType = "Synchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, +}); +Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", content); +BinaryData responseData = operation.Value; + +JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + \ No newline at end of file diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/ListSessions.xml b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/ListSessions.xml new file mode 100644 index 000000000000..a6a5dd759211 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/ListSessions.xml @@ -0,0 +1,111 @@ + + + + + +This sample shows how to call GetListSessionAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetListSessionAsync(); +]]> +This sample shows how to call GetListSessionAsync with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetListSessionAsync(skip: 1234); +]]> + + + +This sample shows how to call GetListSession. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetListSession(); +]]> +This sample shows how to call GetListSession with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetListSession(skip: 1234); +]]> + + + +This sample shows how to call GetListSessionAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetListSessionAsync(null, null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); +]]> +This sample shows how to call GetListSessionAsync with all parameters and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetListSessionAsync(1234, null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); +Console.WriteLine(result.GetProperty("nextLink").ToString()); +]]> + + + +This sample shows how to call GetListSession and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetListSession(null, null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); +]]> +This sample shows how to call GetListSession with all parameters and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetListSession(1234, null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); +Console.WriteLine(result.GetProperty("nextLink").ToString()); +]]> + + + \ No newline at end of file diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionManagement.xml b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionManagement.xml new file mode 100644 index 000000000000..a354efc73fc8 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionManagement.xml @@ -0,0 +1,155 @@ + + + + + +This sample shows how to call GetSessionManagementAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionManagementAsync(""); +]]> +This sample shows how to call GetSessionManagementAsync with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionManagementAsync(""); +]]> + + + +This sample shows how to call GetSessionManagement. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionManagement(""); +]]> +This sample shows how to call GetSessionManagement with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionManagement(""); +]]> + + + +This sample shows how to call GetSessionManagementAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionManagementAsync("", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("etag").ToString()); +]]> +This sample shows how to call GetSessionManagementAsync with all parameters and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionManagementAsync("", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("etag").ToString()); +]]> + + + +This sample shows how to call GetSessionManagement and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionManagement("", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("etag").ToString()); +]]> +This sample shows how to call GetSessionManagement with all parameters and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionManagement("", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("identifier").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); +Console.WriteLine(result.GetProperty("expireAt").ToString()); +Console.WriteLine(result.GetProperty("etag").ToString()); +]]> + + + +This sample shows how to call DeleteAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.DeleteAsync(""); + +Console.WriteLine(response.Status); +]]> +This sample shows how to call DeleteAsync with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.DeleteAsync(""); + +Console.WriteLine(response.Status); +]]> + + + +This sample shows how to call Delete. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = client.Delete(""); + +Console.WriteLine(response.Status); +]]> +This sample shows how to call Delete with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + +Response response = client.Delete(""); + +Console.WriteLine(response.Status); +]]> + + + \ No newline at end of file diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionPoolMetadata.xml b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionPoolMetadata.xml new file mode 100644 index 000000000000..ac38d5ef7fd2 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionPoolMetadata.xml @@ -0,0 +1,129 @@ + + + + + +This sample shows how to call GetSessionPoolMetadataAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionPoolMetadataAsync(); +]]> +This sample shows how to call GetSessionPoolMetadataAsync with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionPoolMetadataAsync(); +]]> + + + +This sample shows how to call GetSessionPoolMetadata. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionPoolMetadata(); +]]> +This sample shows how to call GetSessionPoolMetadata with all parameters. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionPoolMetadata(); +]]> + + + +This sample shows how to call GetSessionPoolMetadataAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionPoolMetadataAsync(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); +]]> +This sample shows how to call GetSessionPoolMetadataAsync with all parameters and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionPoolMetadataAsync(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); +]]> + + + +This sample shows how to call GetSessionPoolMetadata and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionPoolMetadata(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); +]]> +This sample shows how to call GetSessionPoolMetadata with all parameters and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionPoolMetadata(null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("createdAt").ToString()); +Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); +Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); +]]> + + + \ No newline at end of file diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionResourceFiles.xml b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionResourceFiles.xml new file mode 100644 index 000000000000..b756e760389f --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Docs/SessionResourceFiles.xml @@ -0,0 +1,253 @@ + + + + + +This sample shows how to call GetSessionResourceFileAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionResourceFileAsync("testfile", "testSessionIdentifier"); +]]> + + + +This sample shows how to call GetSessionResourceFile. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionResourceFile("testfile", "testSessionIdentifier"); +]]> + + + +This sample shows how to call GetSessionResourceFileAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetSessionResourceFileAsync("testfile", "testSessionIdentifier", "/", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("type").ToString()); +Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); +]]> + + + +This sample shows how to call GetSessionResourceFile and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetSessionResourceFile("testfile", "testSessionIdentifier", "/", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("type").ToString()); +Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); +]]> + + + +This sample shows how to call DeleteAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.DeleteAsync("testfile", "testSessionIdentifier"); + +Console.WriteLine(response.Status); +]]> + + + +This sample shows how to call Delete. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = client.Delete("testfile", "testSessionIdentifier"); + +Console.WriteLine(response.Status); +]]> + + + +This sample shows how to call UploadAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +UploadRequest body = null; +Response response = await client.UploadAsync("testSessionIdentifier", body); +]]> + + + +This sample shows how to call Upload. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +UploadRequest body = null; +Response response = client.Upload("testSessionIdentifier", body); +]]> + + + +This sample shows how to call UploadAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = null; +Response response = await client.UploadAsync("testSessionIdentifier", content, null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("type").ToString()); +Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); +]]> + + + +This sample shows how to call Upload and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +using RequestContent content = null; +Response response = client.Upload("testSessionIdentifier", content, null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("name").ToString()); +Console.WriteLine(result.GetProperty("type").ToString()); +Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); +]]> + + + +This sample shows how to call GetContentAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetContentAsync("testfile", "testSessionIdentifier"); +]]> + + + +This sample shows how to call GetContent. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetContent("testfile", "testSessionIdentifier"); +]]> + + + +This sample shows how to call GetContentAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = await client.GetContentAsync("testfile", "testSessionIdentifier", "/", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + +This sample shows how to call GetContent and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +Response response = client.GetContent("testfile", "testSessionIdentifier", "/", null); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.ToString()); +]]> + + + +This sample shows how to call GetSessionResourceFilesAsync. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +await foreach (SessionResourceFile item in client.GetSessionResourceFilesAsync("testSessionIdentifier")) +{ +} +]]> + + + +This sample shows how to call GetSessionResourceFiles. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +foreach (SessionResourceFile item in client.GetSessionResourceFiles("testSessionIdentifier")) +{ +} +]]> + + + +This sample shows how to call GetSessionResourceFilesAsync and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +await foreach (BinaryData item in client.GetSessionResourceFilesAsync("testSessionIdentifier", "/", null)) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); +} +]]> + + + +This sample shows how to call GetSessionResourceFiles and parse the result. +"); +TokenCredential credential = new DefaultAzureCredential(); +SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + +foreach (BinaryData item in client.GetSessionResourceFiles("testSessionIdentifier", "/", null)) +{ + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); +} +]]> + + + \ No newline at end of file diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/DynamicSessionsClient.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/DynamicSessionsClient.cs new file mode 100644 index 000000000000..8e25932cc1c8 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/DynamicSessionsClient.cs @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + // Data plane generated client. + /// The DynamicSessions service client. + public partial class DynamicSessionsClient + { + private static readonly string[] AuthorizationScopes = new string[] { "https://dynamicsessions.io/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of DynamicSessionsClient for mocking. + protected DynamicSessionsClient() + { + } + + /// Initializes a new instance of DynamicSessionsClient. + /// The management endpoint of the session pool. + /// A credential used to authenticate to an Azure Service. + /// or is null. + public DynamicSessionsClient(Uri endpoint, TokenCredential credential) : this(endpoint, credential, new DynamicSessionsClientOptions()) + { + } + + /// Initializes a new instance of DynamicSessionsClient. + /// The management endpoint of the session pool. + /// A credential used to authenticate to an Azure Service. + /// The options for configuring the client. + /// or is null. + public DynamicSessionsClient(Uri endpoint, TokenCredential credential, DynamicSessionsClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new DynamicSessionsClientOptions(); + + ClientDiagnostics = new ClientDiagnostics(options, true); + _tokenCredential = credential; + _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), new HttpPipelinePolicy[] { new BearerTokenAuthenticationPolicy(_tokenCredential, AuthorizationScopes) }, new ResponseClassifier()); + _endpoint = endpoint; + } + + /// Initializes a new instance of CodeExecution. + /// The API version to use for this operation. + /// is null. + public virtual CodeExecution GetCodeExecutionClient(string apiVersion = "2024-10-02-preview") + { + Argument.AssertNotNull(apiVersion, nameof(apiVersion)); + + return new CodeExecution(ClientDiagnostics, _pipeline, _tokenCredential, _endpoint, apiVersion); + } + + /// Initializes a new instance of SessionResourceFiles. + /// The API version to use for this operation. + /// is null. + public virtual SessionResourceFiles GetSessionResourceFilesClient(string apiVersion = "2024-10-02-preview") + { + Argument.AssertNotNull(apiVersion, nameof(apiVersion)); + + return new SessionResourceFiles(ClientDiagnostics, _pipeline, _tokenCredential, _endpoint, apiVersion); + } + + /// Initializes a new instance of SessionManagement. + /// The API version to use for this operation. + /// is null. + public virtual SessionManagement GetSessionManagementClient(string apiVersion = "2024-10-02-preview") + { + Argument.AssertNotNull(apiVersion, nameof(apiVersion)); + + return new SessionManagement(ClientDiagnostics, _pipeline, _tokenCredential, _endpoint, apiVersion); + } + + /// Initializes a new instance of ListSessions. + /// The API version to use for this operation. + /// is null. + public virtual ListSessions GetListSessionsClient(string apiVersion = "2024-10-02-preview") + { + Argument.AssertNotNull(apiVersion, nameof(apiVersion)); + + return new ListSessions(ClientDiagnostics, _pipeline, _tokenCredential, _endpoint, apiVersion); + } + + /// Initializes a new instance of SessionPoolMetadata. + /// The API version to use for this operation. + /// is null. + public virtual SessionPoolMetadata GetSessionPoolMetadataClient(string apiVersion = "2024-10-02-preview") + { + Argument.AssertNotNull(apiVersion, nameof(apiVersion)); + + return new SessionPoolMetadata(ClientDiagnostics, _pipeline, _tokenCredential, _endpoint, apiVersion); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/DynamicSessionsClientOptions.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/DynamicSessionsClientOptions.cs new file mode 100644 index 000000000000..31ad50ae5345 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/DynamicSessionsClientOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + /// Client options for DynamicSessionsClient. + public partial class DynamicSessionsClientOptions : ClientOptions + { + private const ServiceVersion LatestVersion = ServiceVersion.V2024_10_02_Preview; + + /// The version of the service to use. + public enum ServiceVersion + { + /// Service version "2024-10-02-preview". + V2024_10_02_Preview = 1, + } + + internal string Version { get; } + + /// Initializes new instance of DynamicSessionsClientOptions. + public DynamicSessionsClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2024_10_02_Preview => "2024-10-02-preview", + _ => throw new NotSupportedException() + }; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ErrorResponse.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ErrorResponse.Serialization.cs new file mode 100644 index 000000000000..8bb9ae55203a --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ErrorResponse.Serialization.cs @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class ErrorResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ErrorResponse)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("error"u8); + JsonSerializer.Serialize(writer, Error); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + ErrorResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ErrorResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeErrorResponse(document.RootElement, options); + } + + internal static ErrorResponse DeserializeErrorResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResponseError error = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("error"u8)) + { + error = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ErrorResponse(error, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(ErrorResponse)} does not support writing '{options.Format}' format."); + } + } + + ErrorResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeErrorResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ErrorResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ErrorResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeErrorResponse(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ErrorResponse.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ErrorResponse.cs new file mode 100644 index 000000000000..365411fe4646 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ErrorResponse.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure; + +namespace Microsoft.App.DynamicSessions +{ + /// A response containing error details. + public partial class ErrorResponse + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The error object. + /// is null. + internal ErrorResponse(ResponseError error) + { + Argument.AssertNotNull(error, nameof(error)); + + Error = error; + } + + /// Initializes a new instance of . + /// The error object. + /// Keeps track of any properties unknown to the library. + internal ErrorResponse(ResponseError error, IDictionary serializedAdditionalRawData) + { + Error = error; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal ErrorResponse() + { + } + + /// The error object. + public ResponseError Error { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ExecutionType.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ExecutionType.cs new file mode 100644 index 000000000000..8a5b0220c472 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ExecutionType.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Microsoft.App.DynamicSessions +{ + /// Execution Type. + public readonly partial struct ExecutionType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ExecutionType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SynchronousValue = "Synchronous"; + private const string AsynchronousValue = "Asynchronous"; + + /// Synchronous. + public static ExecutionType Synchronous { get; } = new ExecutionType(SynchronousValue); + /// Asynchronous. + public static ExecutionType Asynchronous { get; } = new ExecutionType(AsynchronousValue); + /// Determines if two values are the same. + public static bool operator ==(ExecutionType left, ExecutionType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ExecutionType left, ExecutionType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ExecutionType(string value) => new ExecutionType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ExecutionType other && Equals(other); + /// + public bool Equals(ExecutionType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Argument.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Argument.cs new file mode 100644 index 000000000000..b29962ac493f --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Argument.cs @@ -0,0 +1,129 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + internal static class Argument + { + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + + public static void AssertNotNullOrWhiteSpace(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); + } + } + + public static void AssertNotDefault(ref T value, string name) + where T : struct, IEquatable + { + if (value.Equals(default)) + { + throw new ArgumentException("Value cannot be empty.", name); + } + } + + public static void AssertInRange(T value, T minimum, T maximum, string name) + where T : notnull, IComparable + { + if (minimum.CompareTo(value) > 0) + { + throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); + } + if (maximum.CompareTo(value) < 0) + { + throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); + } + } + + public static void AssertEnumDefined(Type enumType, object value, string name) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); + } + } + + public static T CheckNotNull(T value, string name) + where T : class + { + AssertNotNull(value, name); + return value; + } + + public static string CheckNotNullOrEmpty(string value, string name) + { + AssertNotNullOrEmpty(value, name); + return value; + } + + public static void AssertNull(T value, string name, string message = null) + { + if (value != null) + { + throw new ArgumentException(message ?? "Value must be null.", name); + } + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ChangeTrackingDictionary.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 000000000000..2f625026ca9e --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + public bool IsUndefined => _innerDictionary == null; + + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ChangeTrackingList.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 000000000000..d9cfe9c47a7f --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.App.DynamicSessions +{ + internal class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + public bool IsUndefined => _innerList == null; + + public int Count => IsUndefined ? 0 : EnsureList().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ModelSerializationExtensions.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 000000000000..bfaa03837995 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,407 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text.Json; +using System.Xml; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + internal static class ModelSerializationExtensions + { + internal static readonly JsonDocumentOptions JsonDocumentOptions = new JsonDocumentOptions { MaxDepth = 256 }; + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + internal static readonly BinaryData SentinelValue = BinaryData.FromBytes("\"__EMPTY__\""u8.ToArray()); + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + var dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + var list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + var text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty property) + { + throw new JsonException($"A property '{property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + var value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case IUtf8JsonSerializable serializable: + serializable.Write(writer); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + + internal static bool IsSentinelValue(BinaryData value) + { + ReadOnlySpan sentinelSpan = SentinelValue.ToMemory().Span; + ReadOnlySpan valueSpan = value.ToMemory().Span; + return sentinelSpan.SequenceEqual(valueSpan); + } + + internal static class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Azure SDK requires it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; + int size = checked(numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/MultipartFormDataRequestContent.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/MultipartFormDataRequestContent.cs new file mode 100644 index 000000000000..e644801a470a --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/MultipartFormDataRequestContent.cs @@ -0,0 +1,203 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Globalization; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + internal class MultipartFormDataRequestContent : RequestContent + { + private readonly System.Net.Http.MultipartFormDataContent _multipartContent; + private static readonly Random _random = new Random(); + private static readonly char[] _boundaryValues = "0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".ToCharArray(); + + public MultipartFormDataRequestContent() + { + _multipartContent = new System.Net.Http.MultipartFormDataContent(CreateBoundary()); + } + + public string ContentType + { + get + { + return _multipartContent.Headers.ContentType.ToString(); + } + } + + internal HttpContent HttpContent => _multipartContent; + + private static string CreateBoundary() + { + Span chars = new char[70]; + byte[] random = new byte[70]; + _random.NextBytes(random); + int mask = 255 >> 2; + for (int i = 0; i < 70; i++) + { + chars[i] = _boundaryValues[random[i] & mask]; + } + return chars.ToString(); + } + + public void Add(string content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + Add(new StringContent(content), name, filename, contentType); + } + + public void Add(int content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + string value = content.ToString("G", CultureInfo.InvariantCulture); + Add(new StringContent(value), name, filename, contentType); + } + + public void Add(long content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + string value = content.ToString("G", CultureInfo.InvariantCulture); + Add(new StringContent(value), name, filename, contentType); + } + + public void Add(float content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + string value = content.ToString("G", CultureInfo.InvariantCulture); + Add(new StringContent(value), name, filename, contentType); + } + + public void Add(double content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + string value = content.ToString("G", CultureInfo.InvariantCulture); + Add(new StringContent(value), name, filename, contentType); + } + + public void Add(decimal content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + string value = content.ToString("G", CultureInfo.InvariantCulture); + Add(new StringContent(value), name, filename, contentType); + } + + public void Add(bool content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + string value = content ? "true" : "false"; + Add(new StringContent(value), name, filename, contentType); + } + + public void Add(Stream content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + Add(new StreamContent(content), name, filename, contentType); + } + + public void Add(byte[] content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + Add(new ByteArrayContent(content), name, filename, contentType); + } + + public void Add(BinaryData content, string name, string filename = null, string contentType = null) + { + Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(name, nameof(name)); + + Add(new ByteArrayContent(content.ToArray()), name, filename, contentType); + } + + private void Add(HttpContent content, string name, string filename, string contentType) + { + if (filename != null) + { + Argument.AssertNotNullOrEmpty(filename, nameof(filename)); + AddFilenameHeader(content, name, filename); + } + if (contentType != null) + { + Argument.AssertNotNullOrEmpty(contentType, nameof(contentType)); + AddContentTypeHeader(content, contentType); + } + _multipartContent.Add(content, name); + } + + public static void AddFilenameHeader(HttpContent content, string name, string filename) + { + ContentDispositionHeaderValue header = new ContentDispositionHeaderValue("form-data") { Name = name, FileName = filename }; + content.Headers.ContentDisposition = header; + } + + public static void AddContentTypeHeader(HttpContent content, string contentType) + { + MediaTypeHeaderValue header = new MediaTypeHeaderValue(contentType); + content.Headers.ContentType = header; + } + + public override bool TryComputeLength(out long length) + { + if (_multipartContent.Headers.ContentLength is long contentLength) + { + length = contentLength; + return true; + } + length = 0; + return false; + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { +#if NET6_0_OR_GREATER + _multipartContent.CopyTo(stream, default, cancellationToken); +#else +#pragma warning disable AZC0107 + _multipartContent.CopyToAsync(stream).EnsureCompleted(); +#pragma warning restore AZC0107 +#endif + } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { +#if NET6_0_OR_GREATER + await _multipartContent.CopyToAsync(stream, cancellationToken).ConfigureAwait(false); +#else + await _multipartContent.CopyToAsync(stream).ConfigureAwait(false); +#endif + } + + public override void Dispose() + { + _multipartContent.Dispose(); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Optional.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Optional.cs new file mode 100644 index 000000000000..e39a6bf9bdee --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Optional.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace Microsoft.App.DynamicSessions +{ + internal static class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + + public static bool IsDefined(string value) + { + return value != null; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Utf8JsonRequestContent.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Utf8JsonRequestContent.cs new file mode 100644 index 000000000000..fa00656bf0f9 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Internal/Utf8JsonRequestContent.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + internal class Utf8JsonRequestContent : RequestContent + { + private readonly MemoryStream _stream; + private readonly RequestContent _content; + + public Utf8JsonRequestContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/JupyterKernel.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/JupyterKernel.Serialization.cs new file mode 100644 index 000000000000..9e53039cf86b --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/JupyterKernel.Serialization.cs @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class JupyterKernel : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(JupyterKernel)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("version"u8); + writer.WriteStringValue(Version); + writer.WritePropertyName("projectUrl"u8); + writer.WriteStringValue(ProjectUrl.AbsoluteUri); + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + JupyterKernel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(JupyterKernel)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeJupyterKernel(document.RootElement, options); + } + + internal static JupyterKernel DeserializeJupyterKernel(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string version = default; + Uri projectUrl = default; + string description = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("version"u8)) + { + version = property.Value.GetString(); + continue; + } + if (property.NameEquals("projectUrl"u8)) + { + projectUrl = new Uri(property.Value.GetString()); + continue; + } + if (property.NameEquals("description"u8)) + { + description = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new JupyterKernel(name, version, projectUrl, description, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(JupyterKernel)} does not support writing '{options.Format}' format."); + } + } + + JupyterKernel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeJupyterKernel(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(JupyterKernel)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static JupyterKernel FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeJupyterKernel(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/JupyterKernel.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/JupyterKernel.cs new file mode 100644 index 000000000000..f130e7d2732f --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/JupyterKernel.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// Jupyter kernel information. + public partial class JupyterKernel + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Name of the kernel. + /// Version of the kernel. + /// Project URL of the kernel. + /// Description of the kernel. + /// , , or is null. + internal JupyterKernel(string name, string version, Uri projectUrl, string description) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(version, nameof(version)); + Argument.AssertNotNull(projectUrl, nameof(projectUrl)); + Argument.AssertNotNull(description, nameof(description)); + + Name = name; + Version = version; + ProjectUrl = projectUrl; + Description = description; + } + + /// Initializes a new instance of . + /// Name of the kernel. + /// Version of the kernel. + /// Project URL of the kernel. + /// Description of the kernel. + /// Keeps track of any properties unknown to the library. + internal JupyterKernel(string name, string version, Uri projectUrl, string description, IDictionary serializedAdditionalRawData) + { + Name = name; + Version = version; + ProjectUrl = projectUrl; + Description = description; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal JupyterKernel() + { + } + + /// Name of the kernel. + public string Name { get; } + /// Version of the kernel. + public string Version { get; } + /// Project URL of the kernel. + public Uri ProjectUrl { get; } + /// Description of the kernel. + public string Description { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ListSessions.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ListSessions.cs new file mode 100644 index 000000000000..dc96ee82235e --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/ListSessions.cs @@ -0,0 +1,179 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + // Data plane generated sub-client. + /// The ListSessions sub-client. + public partial class ListSessions + { + private static readonly string[] AuthorizationScopes = new string[] { "https://dynamicsessions.io/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of ListSessions for mocking. + protected ListSessions() + { + } + + /// Initializes a new instance of ListSessions. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The token credential to copy. + /// The management endpoint of the session pool. + /// The API version to use for this operation. + internal ListSessions(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, TokenCredential tokenCredential, Uri endpoint, string apiVersion) + { + ClientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + _tokenCredential = tokenCredential; + _endpoint = endpoint; + _apiVersion = apiVersion; + } + + /// List the sessions. + /// The offset for pagination purpose. + /// The cancellation token to use. + /// + public virtual async Task> GetListSessionAsync(int? skip = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetListSessionAsync(skip, context).ConfigureAwait(false); + return Response.FromValue(SessionsListResponse.FromResponse(response), response); + } + + /// List the sessions. + /// The offset for pagination purpose. + /// The cancellation token to use. + /// + public virtual Response GetListSession(int? skip = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetListSession(skip, context); + return Response.FromValue(SessionsListResponse.FromResponse(response), response); + } + + /// + /// [Protocol Method] List the sessions. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The offset for pagination purpose. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetListSessionAsync(int? skip, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("ListSessions.GetListSession"); + scope.Start(); + try + { + using HttpMessage message = CreateGetListSessionRequest(skip, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] List the sessions. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The offset for pagination purpose. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetListSession(int? skip, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("ListSessions.GetListSession"); + scope.Start(); + try + { + using HttpMessage message = CreateGetListSessionRequest(skip, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetListSessionRequest(int? skip, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/listSessions", false); + uri.AppendQuery("api-version", _apiVersion, true); + if (skip != null) + { + uri.AppendQuery("skip", skip.Value, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/MicrosoftAppDynamicSessionsClientBuilderExtensions.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/MicrosoftAppDynamicSessionsClientBuilderExtensions.cs new file mode 100644 index 000000000000..7ef784e1b0cb --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/MicrosoftAppDynamicSessionsClientBuilderExtensions.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core.Extensions; +using Microsoft.App.DynamicSessions; + +namespace Microsoft.Extensions.Azure +{ + /// Extension methods to add to client builder. + public static partial class MicrosoftAppDynamicSessionsClientBuilderExtensions + { + /// Registers a instance. + /// The builder to register with. + /// The management endpoint of the session pool. + public static IAzureClientBuilder AddDynamicSessionsClient(this TBuilder builder, Uri endpoint) + where TBuilder : IAzureClientFactoryBuilderWithCredential + { + return builder.RegisterClientFactory((options, cred) => new DynamicSessionsClient(endpoint, cred, options)); + } + + /// Registers a instance. + /// The builder to register with. + /// The configuration values. + public static IAzureClientBuilder AddDynamicSessionsClient(this TBuilder builder, TConfiguration configuration) + where TBuilder : IAzureClientFactoryBuilderWithConfiguration + { + return builder.RegisterClientFactory(configuration); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/MicrosoftAppDynamicSessionsModelFactory.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/MicrosoftAppDynamicSessionsModelFactory.cs new file mode 100644 index 000000000000..58717a5a9152 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/MicrosoftAppDynamicSessionsModelFactory.cs @@ -0,0 +1,154 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure; + +namespace Microsoft.App.DynamicSessions +{ + /// Model factory for models. + public static partial class MicrosoftAppDynamicSessionsModelFactory + { + /// Initializes a new instance of . + /// Session code execution id. + /// The identifier of the session. + /// The execution type of the code execution request. + /// The status of the code execution operation, indicates whether succeeded or not. + /// The error of this code execution if failed. + /// The result of this code execution operation. + /// A new instance for mocking. + public static SessionCodeExecutionResource SessionCodeExecutionResource(string id = null, string identifier = null, ExecutionType executionType = default, OperationState status = default, ErrorResponse error = null, SessionCodeExecutionResult result = null) + { + return new SessionCodeExecutionResource( + id, + identifier, + executionType, + status, + error, + result, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The error object. + /// A new instance for mocking. + public static ErrorResponse ErrorResponse(ResponseError error = null) + { + return new ErrorResponse(error, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The standard output of the code execution. + /// The standard error of the code execution. + /// The result of the code execution. The type of this field is same as the type of actual result of the code execution after being Json serialized. + /// The execution time of the code in milliseconds. + /// A new instance for mocking. + public static SessionCodeExecutionResult SessionCodeExecutionResult(string stdout = null, string stderr = null, BinaryData executionResult = null, long? executionTimeInMilliseconds = null) + { + return new SessionCodeExecutionResult(stdout, stderr, executionResult, executionTimeInMilliseconds, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The name of the file. + /// The type of the session resource file. + /// The type of the content of this file. + /// The size of the file. + /// The date time in RFC3339 format when the file was last modified. + /// A new instance for mocking. + public static SessionResourceFile SessionResourceFile(string name = null, string type = null, string contentType = null, long? sizeInBytes = null, DateTimeOffset lastModifiedAt = default) + { + return new SessionResourceFile( + name, + type, + contentType, + sizeInBytes, + lastModifiedAt, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The identifier of the session. + /// The date and time when the session was created. + /// The date and time when the session was last accessed. + /// The date and time when the session will expire. + /// The ETag of the session, representing the underlying container ID. + /// A new instance for mocking. + public static Session Session(string identifier = null, DateTimeOffset createdAt = default, DateTimeOffset lastAccessedAt = default, DateTimeOffset expireAt = default, ETag etag = default) + { + return new Session( + identifier, + createdAt, + lastAccessedAt, + expireAt, + etag, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The list of sessions. + /// The link to the next page of sessions. + /// A new instance for mocking. + public static SessionsListResponse SessionsListResponse(IEnumerable sessions = null, Uri nextLink = null) + { + sessions ??= new List(); + + return new SessionsListResponse(sessions?.ToList(), nextLink, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// List of runtimes. + /// List of pre-installed packages. + /// Creation date in RFC3339 format. + /// Last updated date in RFC3339 format. + /// Jupyter kernel information. + /// A new instance for mocking. + public static SessionPoolMetadataResponse SessionPoolMetadataResponse(IEnumerable runtimes = null, IEnumerable preInstalledPackages = null, DateTimeOffset createdAt = default, DateTimeOffset lastUpdatedAt = default, JupyterKernel jupyterKernel = null) + { + runtimes ??= new List(); + preInstalledPackages ??= new List(); + + return new SessionPoolMetadataResponse( + runtimes?.ToList(), + preInstalledPackages?.ToList(), + createdAt, + lastUpdatedAt, + jupyterKernel, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Name of the runtime. + /// Version of the runtime. + /// A new instance for mocking. + public static Runtime Runtime(string name = null, string version = null) + { + return new Runtime(name, version, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Name of the package. + /// Version of the package. + /// A new instance for mocking. + public static Package Package(string name = null, string version = null) + { + return new Package(name, version, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// Name of the kernel. + /// Version of the kernel. + /// Project URL of the kernel. + /// Description of the kernel. + /// A new instance for mocking. + public static JupyterKernel JupyterKernel(string name = null, string version = null, Uri projectUrl = null, string description = null) + { + return new JupyterKernel(name, version, projectUrl, description, serializedAdditionalRawData: null); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Models/MicrosoftAppDynamicSessionsContext.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Models/MicrosoftAppDynamicSessionsContext.cs new file mode 100644 index 000000000000..88c1b45bbcee --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Models/MicrosoftAppDynamicSessionsContext.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.ClientModel.Primitives; + +namespace Microsoft.App.DynamicSessions +{ + /// + /// Context class which will be filled in by the System.ClientModel.SourceGeneration. + /// For more information see 'https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/src/docs/ModelReaderWriterContext.md' + /// + public partial class MicrosoftAppDynamicSessionsContext : ModelReaderWriterContext + { + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/OperationState.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/OperationState.cs new file mode 100644 index 000000000000..d2bcf46d8694 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/OperationState.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Microsoft.App.DynamicSessions +{ + /// Enum describing allowed operation states. + public readonly partial struct OperationState : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OperationState(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string NotStartedValue = "NotStarted"; + private const string RunningValue = "Running"; + private const string SucceededValue = "Succeeded"; + private const string FailedValue = "Failed"; + private const string CanceledValue = "Canceled"; + + /// The operation has not started. + public static OperationState NotStarted { get; } = new OperationState(NotStartedValue); + /// The operation is in progress. + public static OperationState Running { get; } = new OperationState(RunningValue); + /// The operation has completed successfully. + public static OperationState Succeeded { get; } = new OperationState(SucceededValue); + /// The operation has failed. + public static OperationState Failed { get; } = new OperationState(FailedValue); + /// The operation has been canceled by the user. + public static OperationState Canceled { get; } = new OperationState(CanceledValue); + /// Determines if two values are the same. + public static bool operator ==(OperationState left, OperationState right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OperationState left, OperationState right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator OperationState(string value) => new OperationState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OperationState other && Equals(other); + /// + public bool Equals(OperationState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Package.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Package.Serialization.cs new file mode 100644 index 000000000000..4fd8a2c860b8 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Package.Serialization.cs @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class Package : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Package)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("version"u8); + writer.WriteStringValue(Version); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + Package IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Package)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePackage(document.RootElement, options); + } + + internal static Package DeserializePackage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string version = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("version"u8)) + { + version = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new Package(name, version, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(Package)} does not support writing '{options.Format}' format."); + } + } + + Package IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializePackage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Package)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static Package FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializePackage(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Package.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Package.cs new file mode 100644 index 000000000000..467f787b69c4 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Package.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// Package information. + public partial class Package + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Name of the package. + /// Version of the package. + /// or is null. + internal Package(string name, string version) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(version, nameof(version)); + + Name = name; + Version = version; + } + + /// Initializes a new instance of . + /// Name of the package. + /// Version of the package. + /// Keeps track of any properties unknown to the library. + internal Package(string name, string version, IDictionary serializedAdditionalRawData) + { + Name = name; + Version = version; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Package() + { + } + + /// Name of the package. + public string Name { get; } + /// Version of the package. + public string Version { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Runtime.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Runtime.Serialization.cs new file mode 100644 index 000000000000..9e4a50207335 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Runtime.Serialization.cs @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class Runtime : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Runtime)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("version"u8); + writer.WriteStringValue(Version); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + Runtime IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Runtime)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRuntime(document.RootElement, options); + } + + internal static Runtime DeserializeRuntime(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string version = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("version"u8)) + { + version = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new Runtime(name, version, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(Runtime)} does not support writing '{options.Format}' format."); + } + } + + Runtime IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRuntime(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Runtime)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static Runtime FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRuntime(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Runtime.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Runtime.cs new file mode 100644 index 000000000000..38763ab234ef --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Runtime.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// Runtime information. + public partial class Runtime + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Name of the runtime. + /// Version of the runtime. + /// or is null. + internal Runtime(string name, string version) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(version, nameof(version)); + + Name = name; + Version = version; + } + + /// Initializes a new instance of . + /// Name of the runtime. + /// Version of the runtime. + /// Keeps track of any properties unknown to the library. + internal Runtime(string name, string version, IDictionary serializedAdditionalRawData) + { + Name = name; + Version = version; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Runtime() + { + } + + /// Name of the runtime. + public string Name { get; } + /// Version of the runtime. + public string Version { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Session.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Session.Serialization.cs new file mode 100644 index 000000000000..80aa02e1431c --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Session.Serialization.cs @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class Session : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Session)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("identifier"u8); + writer.WriteStringValue(Identifier); + writer.WritePropertyName("createdAt"u8); + writer.WriteStringValue(CreatedAt, "O"); + writer.WritePropertyName("lastAccessedAt"u8); + writer.WriteStringValue(LastAccessedAt, "O"); + writer.WritePropertyName("expireAt"u8); + writer.WriteStringValue(ExpireAt, "O"); + writer.WritePropertyName("etag"u8); + writer.WriteStringValue(Etag.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + Session IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Session)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSession(document.RootElement, options); + } + + internal static Session DeserializeSession(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string identifier = default; + DateTimeOffset createdAt = default; + DateTimeOffset lastAccessedAt = default; + DateTimeOffset expireAt = default; + ETag etag = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("identifier"u8)) + { + identifier = property.Value.GetString(); + continue; + } + if (property.NameEquals("createdAt"u8)) + { + createdAt = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("lastAccessedAt"u8)) + { + lastAccessedAt = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("expireAt"u8)) + { + expireAt = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("etag"u8)) + { + etag = new ETag(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new Session( + identifier, + createdAt, + lastAccessedAt, + expireAt, + etag, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(Session)} does not support writing '{options.Format}' format."); + } + } + + Session IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSession(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Session)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static Session FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSession(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Session.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Session.cs new file mode 100644 index 000000000000..8e13a3ab7049 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/Session.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure; + +namespace Microsoft.App.DynamicSessions +{ + /// The session resource. + public partial class Session + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The identifier of the session. + /// The date and time when the session was created. + /// The date and time when the session was last accessed. + /// The date and time when the session will expire. + /// The ETag of the session, representing the underlying container ID. + /// is null. + internal Session(string identifier, DateTimeOffset createdAt, DateTimeOffset lastAccessedAt, DateTimeOffset expireAt, ETag etag) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + Identifier = identifier; + CreatedAt = createdAt; + LastAccessedAt = lastAccessedAt; + ExpireAt = expireAt; + Etag = etag; + } + + /// Initializes a new instance of . + /// The identifier of the session. + /// The date and time when the session was created. + /// The date and time when the session was last accessed. + /// The date and time when the session will expire. + /// The ETag of the session, representing the underlying container ID. + /// Keeps track of any properties unknown to the library. + internal Session(string identifier, DateTimeOffset createdAt, DateTimeOffset lastAccessedAt, DateTimeOffset expireAt, ETag etag, IDictionary serializedAdditionalRawData) + { + Identifier = identifier; + CreatedAt = createdAt; + LastAccessedAt = lastAccessedAt; + ExpireAt = expireAt; + Etag = etag; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal Session() + { + } + + /// The identifier of the session. + public string Identifier { get; } + /// The date and time when the session was created. + public DateTimeOffset CreatedAt { get; } + /// The date and time when the session was last accessed. + public DateTimeOffset LastAccessedAt { get; } + /// The date and time when the session will expire. + public DateTimeOffset ExpireAt { get; } + /// The ETag of the session, representing the underlying container ID. + public ETag Etag { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionRequest.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionRequest.Serialization.cs new file mode 100644 index 000000000000..72aed7aff2b8 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionRequest.Serialization.cs @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class SessionCodeExecutionRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionCodeExecutionRequest)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("codeInputType"u8); + writer.WriteStringValue(CodeInputType.ToString()); + writer.WritePropertyName("executionType"u8); + writer.WriteStringValue(ExecutionType.ToString()); + writer.WritePropertyName("code"u8); + writer.WriteStringValue(Code); + writer.WritePropertyName("timeoutInSeconds"u8); + writer.WriteNumberValue(TimeoutInSeconds); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SessionCodeExecutionRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionCodeExecutionRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSessionCodeExecutionRequest(document.RootElement, options); + } + + internal static SessionCodeExecutionRequest DeserializeSessionCodeExecutionRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + CodeInputType codeInputType = default; + ExecutionType executionType = default; + string code = default; + long timeoutInSeconds = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("codeInputType"u8)) + { + codeInputType = new CodeInputType(property.Value.GetString()); + continue; + } + if (property.NameEquals("executionType"u8)) + { + executionType = new ExecutionType(property.Value.GetString()); + continue; + } + if (property.NameEquals("code"u8)) + { + code = property.Value.GetString(); + continue; + } + if (property.NameEquals("timeoutInSeconds"u8)) + { + timeoutInSeconds = property.Value.GetInt64(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new SessionCodeExecutionRequest(codeInputType, executionType, code, timeoutInSeconds, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(SessionCodeExecutionRequest)} does not support writing '{options.Format}' format."); + } + } + + SessionCodeExecutionRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionCodeExecutionRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SessionCodeExecutionRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SessionCodeExecutionRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionCodeExecutionRequest(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionRequest.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionRequest.cs new file mode 100644 index 000000000000..b6197c19e287 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionRequest.cs @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// The request to execute code. + public partial class SessionCodeExecutionRequest + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The code input type of the code execution request. + /// The execution type of the code execution request. + /// The string of the code to execute, based on CodeInputType. + /// Code execution timeout in seconds. + /// is null. + public SessionCodeExecutionRequest(CodeInputType codeInputType, ExecutionType executionType, string code, long timeoutInSeconds) + { + Argument.AssertNotNull(code, nameof(code)); + + CodeInputType = codeInputType; + ExecutionType = executionType; + Code = code; + TimeoutInSeconds = timeoutInSeconds; + } + + /// Initializes a new instance of . + /// The code input type of the code execution request. + /// The execution type of the code execution request. + /// The string of the code to execute, based on CodeInputType. + /// Code execution timeout in seconds. + /// Keeps track of any properties unknown to the library. + internal SessionCodeExecutionRequest(CodeInputType codeInputType, ExecutionType executionType, string code, long timeoutInSeconds, IDictionary serializedAdditionalRawData) + { + CodeInputType = codeInputType; + ExecutionType = executionType; + Code = code; + TimeoutInSeconds = timeoutInSeconds; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal SessionCodeExecutionRequest() + { + } + + /// The code input type of the code execution request. + public CodeInputType CodeInputType { get; } + /// The execution type of the code execution request. + public ExecutionType ExecutionType { get; } + /// The string of the code to execute, based on CodeInputType. + public string Code { get; } + /// Code execution timeout in seconds. + public long TimeoutInSeconds { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResource.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResource.Serialization.cs new file mode 100644 index 000000000000..b079aad47923 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResource.Serialization.cs @@ -0,0 +1,207 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class SessionCodeExecutionResource : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionCodeExecutionResource)} does not support writing '{format}' format."); + } + + if (options.Format != "W") + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + writer.WritePropertyName("identifier"u8); + writer.WriteStringValue(Identifier); + writer.WritePropertyName("executionType"u8); + writer.WriteStringValue(ExecutionType.ToString()); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (Optional.IsDefined(Error)) + { + writer.WritePropertyName("error"u8); + writer.WriteObjectValue(Error, options); + } + if (Optional.IsDefined(Result)) + { + writer.WritePropertyName("result"u8); + writer.WriteObjectValue(Result, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SessionCodeExecutionResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionCodeExecutionResource)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSessionCodeExecutionResource(document.RootElement, options); + } + + internal static SessionCodeExecutionResource DeserializeSessionCodeExecutionResource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string identifier = default; + ExecutionType executionType = default; + OperationState status = default; + ErrorResponse error = default; + SessionCodeExecutionResult result = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("identifier"u8)) + { + identifier = property.Value.GetString(); + continue; + } + if (property.NameEquals("executionType"u8)) + { + executionType = new ExecutionType(property.Value.GetString()); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new OperationState(property.Value.GetString()); + continue; + } + if (property.NameEquals("error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + error = ErrorResponse.DeserializeErrorResponse(property.Value, options); + continue; + } + if (property.NameEquals("result"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result = SessionCodeExecutionResult.DeserializeSessionCodeExecutionResult(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new SessionCodeExecutionResource( + id, + identifier, + executionType, + status, + error, + result, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(SessionCodeExecutionResource)} does not support writing '{options.Format}' format."); + } + } + + SessionCodeExecutionResource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionCodeExecutionResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SessionCodeExecutionResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SessionCodeExecutionResource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionCodeExecutionResource(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResource.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResource.cs new file mode 100644 index 000000000000..78ed209c1e62 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResource.cs @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// The session code execution resource. + public partial class SessionCodeExecutionResource + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The identifier of the session. + /// The execution type of the code execution request. + /// The status of the code execution operation, indicates whether succeeded or not. + /// is null. + internal SessionCodeExecutionResource(string identifier, ExecutionType executionType, OperationState status) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + Identifier = identifier; + ExecutionType = executionType; + Status = status; + } + + /// Initializes a new instance of . + /// Session code execution id. + /// The identifier of the session. + /// The execution type of the code execution request. + /// The status of the code execution operation, indicates whether succeeded or not. + /// The error of this code execution if failed. + /// The result of this code execution operation. + /// Keeps track of any properties unknown to the library. + internal SessionCodeExecutionResource(string id, string identifier, ExecutionType executionType, OperationState status, ErrorResponse error, SessionCodeExecutionResult result, IDictionary serializedAdditionalRawData) + { + Id = id; + Identifier = identifier; + ExecutionType = executionType; + Status = status; + Error = error; + Result = result; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal SessionCodeExecutionResource() + { + } + + /// Session code execution id. + public string Id { get; } + /// The identifier of the session. + public string Identifier { get; } + /// The execution type of the code execution request. + public ExecutionType ExecutionType { get; } + /// The status of the code execution operation, indicates whether succeeded or not. + public OperationState Status { get; } + /// The error of this code execution if failed. + public ErrorResponse Error { get; } + /// The result of this code execution operation. + public SessionCodeExecutionResult Result { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResult.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResult.Serialization.cs new file mode 100644 index 000000000000..22e9c70f0758 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResult.Serialization.cs @@ -0,0 +1,194 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class SessionCodeExecutionResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionCodeExecutionResult)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Stdout)) + { + writer.WritePropertyName("stdout"u8); + writer.WriteStringValue(Stdout); + } + if (Optional.IsDefined(Stderr)) + { + writer.WritePropertyName("stderr"u8); + writer.WriteStringValue(Stderr); + } + if (Optional.IsDefined(ExecutionResult)) + { + writer.WritePropertyName("executionResult"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ExecutionResult); +#else + using (JsonDocument document = JsonDocument.Parse(ExecutionResult, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (Optional.IsDefined(ExecutionTimeInMilliseconds)) + { + writer.WritePropertyName("executionTimeInMilliseconds"u8); + writer.WriteNumberValue(ExecutionTimeInMilliseconds.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SessionCodeExecutionResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionCodeExecutionResult)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSessionCodeExecutionResult(document.RootElement, options); + } + + internal static SessionCodeExecutionResult DeserializeSessionCodeExecutionResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string stdout = default; + string stderr = default; + BinaryData executionResult = default; + long? executionTimeInMilliseconds = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("stdout"u8)) + { + stdout = property.Value.GetString(); + continue; + } + if (property.NameEquals("stderr"u8)) + { + stderr = property.Value.GetString(); + continue; + } + if (property.NameEquals("executionResult"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + executionResult = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("executionTimeInMilliseconds"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + executionTimeInMilliseconds = property.Value.GetInt64(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new SessionCodeExecutionResult(stdout, stderr, executionResult, executionTimeInMilliseconds, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(SessionCodeExecutionResult)} does not support writing '{options.Format}' format."); + } + } + + SessionCodeExecutionResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionCodeExecutionResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SessionCodeExecutionResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SessionCodeExecutionResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionCodeExecutionResult(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResult.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResult.cs new file mode 100644 index 000000000000..56244e575e1d --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionCodeExecutionResult.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// The result of the code execution. + public partial class SessionCodeExecutionResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal SessionCodeExecutionResult() + { + } + + /// Initializes a new instance of . + /// The standard output of the code execution. + /// The standard error of the code execution. + /// The result of the code execution. The type of this field is same as the type of actual result of the code execution after being Json serialized. + /// The execution time of the code in milliseconds. + /// Keeps track of any properties unknown to the library. + internal SessionCodeExecutionResult(string stdout, string stderr, BinaryData executionResult, long? executionTimeInMilliseconds, IDictionary serializedAdditionalRawData) + { + Stdout = stdout; + Stderr = stderr; + ExecutionResult = executionResult; + ExecutionTimeInMilliseconds = executionTimeInMilliseconds; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The standard output of the code execution. + public string Stdout { get; } + /// The standard error of the code execution. + public string Stderr { get; } + /// + /// The result of the code execution. The type of this field is same as the type of actual result of the code execution after being Json serialized. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ExecutionResult { get; } + /// The execution time of the code in milliseconds. + public long? ExecutionTimeInMilliseconds { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionManagement.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionManagement.cs new file mode 100644 index 000000000000..d5c9af0cd03f --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionManagement.cs @@ -0,0 +1,275 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + // Data plane generated sub-client. + /// The SessionManagement sub-client. + public partial class SessionManagement + { + private static readonly string[] AuthorizationScopes = new string[] { "https://dynamicsessions.io/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of SessionManagement for mocking. + protected SessionManagement() + { + } + + /// Initializes a new instance of SessionManagement. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The token credential to copy. + /// The management endpoint of the session pool. + /// The API version to use for this operation. + internal SessionManagement(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, TokenCredential tokenCredential, Uri endpoint, string apiVersion) + { + ClientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + _tokenCredential = tokenCredential; + _endpoint = endpoint; + _apiVersion = apiVersion; + } + + /// Get the session. + /// The user-assigned identifier of the session. + /// The cancellation token to use. + /// is null. + /// + public virtual async Task> GetSessionManagementAsync(string identifier, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetSessionManagementAsync(identifier, context).ConfigureAwait(false); + return Response.FromValue(Session.FromResponse(response), response); + } + + /// Get the session. + /// The user-assigned identifier of the session. + /// The cancellation token to use. + /// is null. + /// + public virtual Response GetSessionManagement(string identifier, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetSessionManagement(identifier, context); + return Response.FromValue(Session.FromResponse(response), response); + } + + /// + /// [Protocol Method] Get the session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetSessionManagementAsync(string identifier, RequestContext context) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionManagement.GetSessionManagement"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionManagementRequest(identifier, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Get the session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetSessionManagement(string identifier, RequestContext context) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionManagement.GetSessionManagement"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionManagementRequest(identifier, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // The convenience method is omitted here because it has exactly the same parameter list as the corresponding protocol method + /// + /// [Protocol Method] Delete the session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task DeleteAsync(string identifier, RequestContext context = null) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionManagement.Delete"); + scope.Start(); + try + { + using HttpMessage message = CreateDeleteRequest(identifier, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // The convenience method is omitted here because it has exactly the same parameter list as the corresponding protocol method + /// + /// [Protocol Method] Delete the session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response Delete(string identifier, RequestContext context = null) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionManagement.Delete"); + scope.Start(); + try + { + using HttpMessage message = CreateDeleteRequest(identifier, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetSessionManagementRequest(string identifier, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/session", false); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateDeleteRequest(string identifier, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier204); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/session", false); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + private static ResponseClassifier _responseClassifier204; + private static ResponseClassifier ResponseClassifier204 => _responseClassifier204 ??= new StatusCodeClassifier(stackalloc ushort[] { 204 }); + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadata.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadata.cs new file mode 100644 index 000000000000..8f218dcc61a9 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadata.cs @@ -0,0 +1,171 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + // Data plane generated sub-client. + /// The SessionPoolMetadata sub-client. + public partial class SessionPoolMetadata + { + private static readonly string[] AuthorizationScopes = new string[] { "https://dynamicsessions.io/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of SessionPoolMetadata for mocking. + protected SessionPoolMetadata() + { + } + + /// Initializes a new instance of SessionPoolMetadata. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The token credential to copy. + /// The management endpoint of the session pool. + /// The API version to use for this operation. + internal SessionPoolMetadata(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, TokenCredential tokenCredential, Uri endpoint, string apiVersion) + { + ClientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + _tokenCredential = tokenCredential; + _endpoint = endpoint; + _apiVersion = apiVersion; + } + + /// Get the metadata information. + /// The cancellation token to use. + /// + public virtual async Task> GetSessionPoolMetadataAsync(CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetSessionPoolMetadataAsync(context).ConfigureAwait(false); + return Response.FromValue(SessionPoolMetadataResponse.FromResponse(response), response); + } + + /// Get the metadata information. + /// The cancellation token to use. + /// + public virtual Response GetSessionPoolMetadata(CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetSessionPoolMetadata(context); + return Response.FromValue(SessionPoolMetadataResponse.FromResponse(response), response); + } + + /// + /// [Protocol Method] Get the metadata information. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetSessionPoolMetadataAsync(RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("SessionPoolMetadata.GetSessionPoolMetadata"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionPoolMetadataRequest(context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Get the metadata information. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetSessionPoolMetadata(RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("SessionPoolMetadata.GetSessionPoolMetadata"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionPoolMetadataRequest(context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + internal HttpMessage CreateGetSessionPoolMetadataRequest(RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/metadata", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadataResponse.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadataResponse.Serialization.cs new file mode 100644 index 000000000000..f7a4d9d391c9 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadataResponse.Serialization.cs @@ -0,0 +1,201 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class SessionPoolMetadataResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionPoolMetadataResponse)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("runtimes"u8); + writer.WriteStartArray(); + foreach (var item in Runtimes) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + writer.WritePropertyName("preInstalledPackages"u8); + writer.WriteStartArray(); + foreach (var item in PreInstalledPackages) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + writer.WritePropertyName("createdAt"u8); + writer.WriteStringValue(CreatedAt, "O"); + writer.WritePropertyName("lastUpdatedAt"u8); + writer.WriteStringValue(LastUpdatedAt, "O"); + writer.WritePropertyName("jupyterKernel"u8); + writer.WriteObjectValue(JupyterKernel, options); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SessionPoolMetadataResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionPoolMetadataResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSessionPoolMetadataResponse(document.RootElement, options); + } + + internal static SessionPoolMetadataResponse DeserializeSessionPoolMetadataResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList runtimes = default; + IReadOnlyList preInstalledPackages = default; + DateTimeOffset createdAt = default; + DateTimeOffset lastUpdatedAt = default; + JupyterKernel jupyterKernel = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("runtimes"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(Runtime.DeserializeRuntime(item, options)); + } + runtimes = array; + continue; + } + if (property.NameEquals("preInstalledPackages"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(Package.DeserializePackage(item, options)); + } + preInstalledPackages = array; + continue; + } + if (property.NameEquals("createdAt"u8)) + { + createdAt = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("lastUpdatedAt"u8)) + { + lastUpdatedAt = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("jupyterKernel"u8)) + { + jupyterKernel = JupyterKernel.DeserializeJupyterKernel(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new SessionPoolMetadataResponse( + runtimes, + preInstalledPackages, + createdAt, + lastUpdatedAt, + jupyterKernel, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(SessionPoolMetadataResponse)} does not support writing '{options.Format}' format."); + } + } + + SessionPoolMetadataResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionPoolMetadataResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SessionPoolMetadataResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SessionPoolMetadataResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionPoolMetadataResponse(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadataResponse.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadataResponse.cs new file mode 100644 index 000000000000..7acd28864f39 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionPoolMetadataResponse.cs @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.App.DynamicSessions +{ + /// SessionPool Metadata. + public partial class SessionPoolMetadataResponse + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// List of runtimes. + /// List of pre-installed packages. + /// Creation date in RFC3339 format. + /// Last updated date in RFC3339 format. + /// Jupyter kernel information. + /// , or is null. + internal SessionPoolMetadataResponse(IEnumerable runtimes, IEnumerable preInstalledPackages, DateTimeOffset createdAt, DateTimeOffset lastUpdatedAt, JupyterKernel jupyterKernel) + { + Argument.AssertNotNull(runtimes, nameof(runtimes)); + Argument.AssertNotNull(preInstalledPackages, nameof(preInstalledPackages)); + Argument.AssertNotNull(jupyterKernel, nameof(jupyterKernel)); + + Runtimes = runtimes.ToList(); + PreInstalledPackages = preInstalledPackages.ToList(); + CreatedAt = createdAt; + LastUpdatedAt = lastUpdatedAt; + JupyterKernel = jupyterKernel; + } + + /// Initializes a new instance of . + /// List of runtimes. + /// List of pre-installed packages. + /// Creation date in RFC3339 format. + /// Last updated date in RFC3339 format. + /// Jupyter kernel information. + /// Keeps track of any properties unknown to the library. + internal SessionPoolMetadataResponse(IReadOnlyList runtimes, IReadOnlyList preInstalledPackages, DateTimeOffset createdAt, DateTimeOffset lastUpdatedAt, JupyterKernel jupyterKernel, IDictionary serializedAdditionalRawData) + { + Runtimes = runtimes; + PreInstalledPackages = preInstalledPackages; + CreatedAt = createdAt; + LastUpdatedAt = lastUpdatedAt; + JupyterKernel = jupyterKernel; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal SessionPoolMetadataResponse() + { + } + + /// List of runtimes. + public IReadOnlyList Runtimes { get; } + /// List of pre-installed packages. + public IReadOnlyList PreInstalledPackages { get; } + /// Creation date in RFC3339 format. + public DateTimeOffset CreatedAt { get; } + /// Last updated date in RFC3339 format. + public DateTimeOffset LastUpdatedAt { get; } + /// Jupyter kernel information. + public JupyterKernel JupyterKernel { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFile.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFile.Serialization.cs new file mode 100644 index 000000000000..8e663679522c --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFile.Serialization.cs @@ -0,0 +1,191 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class SessionResourceFile : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionResourceFile)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (Optional.IsDefined(ContentType)) + { + writer.WritePropertyName("contentType"u8); + writer.WriteStringValue(ContentType); + } + if (Optional.IsDefined(SizeInBytes)) + { + writer.WritePropertyName("sizeInBytes"u8); + writer.WriteNumberValue(SizeInBytes.Value); + } + writer.WritePropertyName("lastModifiedAt"u8); + writer.WriteStringValue(LastModifiedAt, "O"); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SessionResourceFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionResourceFile)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSessionResourceFile(document.RootElement, options); + } + + internal static SessionResourceFile DeserializeSessionResourceFile(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string type = default; + string contentType = default; + long? sizeInBytes = default; + DateTimeOffset lastModifiedAt = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("contentType"u8)) + { + contentType = property.Value.GetString(); + continue; + } + if (property.NameEquals("sizeInBytes"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + sizeInBytes = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("lastModifiedAt"u8)) + { + lastModifiedAt = property.Value.GetDateTimeOffset("O"); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new SessionResourceFile( + name, + type, + contentType, + sizeInBytes, + lastModifiedAt, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(SessionResourceFile)} does not support writing '{options.Format}' format."); + } + } + + SessionResourceFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionResourceFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SessionResourceFile)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SessionResourceFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionResourceFile(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFile.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFile.cs new file mode 100644 index 000000000000..5438b780714c --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFile.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Microsoft.App.DynamicSessions +{ + /// Code execution file resource. + public partial class SessionResourceFile + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The name of the file. + /// The type of the session resource file. + /// The date time in RFC3339 format when the file was last modified. + /// or is null. + internal SessionResourceFile(string name, string type, DateTimeOffset lastModifiedAt) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(type, nameof(type)); + + Name = name; + Type = type; + LastModifiedAt = lastModifiedAt; + } + + /// Initializes a new instance of . + /// The name of the file. + /// The type of the session resource file. + /// The type of the content of this file. + /// The size of the file. + /// The date time in RFC3339 format when the file was last modified. + /// Keeps track of any properties unknown to the library. + internal SessionResourceFile(string name, string type, string contentType, long? sizeInBytes, DateTimeOffset lastModifiedAt, IDictionary serializedAdditionalRawData) + { + Name = name; + Type = type; + ContentType = contentType; + SizeInBytes = sizeInBytes; + LastModifiedAt = lastModifiedAt; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal SessionResourceFile() + { + } + + /// The name of the file. + public string Name { get; } + /// The type of the session resource file. + public string Type { get; } + /// The type of the content of this file. + public string ContentType { get; } + /// The size of the file. + public long? SizeInBytes { get; } + /// The date time in RFC3339 format when the file was last modified. + public DateTimeOffset LastModifiedAt { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFiles.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFiles.cs new file mode 100644 index 000000000000..d8e594dd3af7 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionResourceFiles.cs @@ -0,0 +1,722 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Autorest.CSharp.Core; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Microsoft.App.DynamicSessions +{ + // Data plane generated sub-client. + /// The SessionResourceFiles sub-client. + public partial class SessionResourceFiles + { + private static readonly string[] AuthorizationScopes = new string[] { "https://dynamicsessions.io/.default" }; + private readonly TokenCredential _tokenCredential; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// The ClientDiagnostics is used to provide tracing support for the client library. + internal ClientDiagnostics ClientDiagnostics { get; } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual HttpPipeline Pipeline => _pipeline; + + /// Initializes a new instance of SessionResourceFiles for mocking. + protected SessionResourceFiles() + { + } + + /// Initializes a new instance of SessionResourceFiles. + /// The handler for diagnostic messaging in the client. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The token credential to copy. + /// The management endpoint of the session pool. + /// The API version to use for this operation. + internal SessionResourceFiles(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, TokenCredential tokenCredential, Uri endpoint, string apiVersion) + { + ClientDiagnostics = clientDiagnostics; + _pipeline = pipeline; + _tokenCredential = tokenCredential; + _endpoint = endpoint; + _apiVersion = apiVersion; + } + + /// Get the file resource. + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// + public virtual async Task> GetSessionResourceFileAsync(string name, string identifier, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetSessionResourceFileAsync(name, identifier, path, context).ConfigureAwait(false); + return Response.FromValue(SessionResourceFile.FromResponse(response), response); + } + + /// Get the file resource. + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// + public virtual Response GetSessionResourceFile(string name, string identifier, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetSessionResourceFile(name, identifier, path, context); + return Response.FromValue(SessionResourceFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Get the file resource. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetSessionResourceFileAsync(string name, string identifier, string path, RequestContext context) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.GetSessionResourceFile"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionResourceFileRequest(name, identifier, path, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Get the file resource. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetSessionResourceFile(string name, string identifier, string path, RequestContext context) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.GetSessionResourceFile"); + scope.Start(); + try + { + using HttpMessage message = CreateGetSessionResourceFileRequest(name, identifier, path, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // The convenience method is omitted here because it has exactly the same parameter list as the corresponding protocol method + /// + /// [Protocol Method] Delete the file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task DeleteAsync(string name, string identifier, string path = null, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.Delete"); + scope.Start(); + try + { + using HttpMessage message = CreateDeleteRequest(name, identifier, path, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + // The convenience method is omitted here because it has exactly the same parameter list as the corresponding protocol method + /// + /// [Protocol Method] Delete the file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response Delete(string name, string identifier, string path = null, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.Delete"); + scope.Start(); + try + { + using HttpMessage message = CreateDeleteRequest(name, identifier, path, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Upload a file to a session. + /// The user-assigned identifier of the session. + /// Multipart body. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// or is null. + /// + public virtual async Task> UploadAsync(string identifier, UploadRequest body, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(body, nameof(body)); + + using MultipartFormDataRequestContent content = body.ToMultipartRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await UploadAsync(identifier, content, content.ContentType, path, context).ConfigureAwait(false); + return Response.FromValue(SessionResourceFile.FromResponse(response), response); + } + + /// Upload a file to a session. + /// The user-assigned identifier of the session. + /// Multipart body. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// or is null. + /// + public virtual Response Upload(string identifier, UploadRequest body, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(body, nameof(body)); + + using MultipartFormDataRequestContent content = body.ToMultipartRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = Upload(identifier, content, content.ContentType, path, context); + return Response.FromValue(SessionResourceFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Upload a file to a session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The content to send as the body of the request. + /// The content type for the operation. Always multipart/form-data for this operation. Allowed values: "multipart/form-data". + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task UploadAsync(string identifier, RequestContent content, string contentType, string path = null, RequestContext context = null) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.Upload"); + scope.Start(); + try + { + using HttpMessage message = CreateUploadRequest(identifier, content, contentType, path, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Upload a file to a session. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The content to send as the body of the request. + /// The content type for the operation. Always multipart/form-data for this operation. Allowed values: "multipart/form-data". + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response Upload(string identifier, RequestContent content, string contentType, string path = null, RequestContext context = null) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.Upload"); + scope.Start(); + try + { + using HttpMessage message = CreateUploadRequest(identifier, content, contentType, path, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Get the content of the file. + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// + public virtual async Task> GetContentAsync(string name, string identifier, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetContentAsync(name, identifier, path, context).ConfigureAwait(false); + return Response.FromValue(response.Content, response); + } + + /// Get the content of the file. + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// + public virtual Response GetContent(string name, string identifier, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetContent(name, identifier, path, context); + return Response.FromValue(response.Content, response); + } + + /// + /// [Protocol Method] Get the content of the file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task GetContentAsync(string name, string identifier, string path, RequestContext context) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.GetContent"); + scope.Start(); + try + { + using HttpMessage message = CreateGetContentRequest(name, identifier, path, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Get the content of the file. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The name of the file. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response GetContent(string name, string identifier, string path, RequestContext context) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(identifier, nameof(identifier)); + + using var scope = ClientDiagnostics.CreateScope("SessionResourceFiles.GetContent"); + scope.Start(); + try + { + using HttpMessage message = CreateGetContentRequest(name, identifier, path, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// List the file resources. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// is null. + /// + public virtual AsyncPageable GetSessionResourceFilesAsync(string identifier, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSessionResourceFilesRequest(identifier, path, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSessionResourceFilesNextPageRequest(nextLink, identifier, path, context); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => SessionResourceFile.DeserializeSessionResourceFile(e), ClientDiagnostics, _pipeline, "SessionResourceFiles.GetSessionResourceFiles", "value", "nextLink", context); + } + + /// List the file resources. + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The cancellation token to use. + /// is null. + /// + public virtual Pageable GetSessionResourceFiles(string identifier, string path = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + RequestContext context = cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null; + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSessionResourceFilesRequest(identifier, path, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSessionResourceFilesNextPageRequest(nextLink, identifier, path, context); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => SessionResourceFile.DeserializeSessionResourceFile(e), ClientDiagnostics, _pipeline, "SessionResourceFiles.GetSessionResourceFiles", "value", "nextLink", context); + } + + /// + /// [Protocol Method] List the file resources. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The from the service containing a list of objects. Details of the body schema for each item in the collection are in the Remarks section below. + /// + public virtual AsyncPageable GetSessionResourceFilesAsync(string identifier, string path, RequestContext context) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSessionResourceFilesRequest(identifier, path, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSessionResourceFilesNextPageRequest(nextLink, identifier, path, context); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "SessionResourceFiles.GetSessionResourceFiles", "value", "nextLink", context); + } + + /// + /// [Protocol Method] List the file resources. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The user-assigned identifier of the session. + /// The path of the file after uploaded. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The from the service containing a list of objects. Details of the body schema for each item in the collection are in the Remarks section below. + /// + public virtual Pageable GetSessionResourceFiles(string identifier, string path, RequestContext context) + { + Argument.AssertNotNull(identifier, nameof(identifier)); + + HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetSessionResourceFilesRequest(identifier, path, context); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetSessionResourceFilesNextPageRequest(nextLink, identifier, path, context); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => BinaryData.FromString(e.GetRawText()), ClientDiagnostics, _pipeline, "SessionResourceFiles.GetSessionResourceFiles", "value", "nextLink", context); + } + + internal HttpMessage CreateGetSessionResourceFilesRequest(string identifier, string path, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/files", false); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + if (path != null) + { + uri.AppendQuery("path", path, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetSessionResourceFileRequest(string name, string identifier, string path, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/files/", false); + uri.AppendPath(name, true); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + if (path != null) + { + uri.AppendQuery("path", path, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateDeleteRequest(string name, string identifier, string path, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier204); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/files/", false); + uri.AppendPath(name, true); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + if (path != null) + { + uri.AppendQuery("path", path, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateUploadRequest(string identifier, RequestContent content, string contentType, string path, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/files", false); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + if (path != null) + { + uri.AppendQuery("path", path, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", contentType); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetContentRequest(string name, string identifier, string path, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/files/", false); + uri.AppendPath(name, true); + uri.AppendPath("/content", false); + uri.AppendQuery("identifier", identifier, true); + uri.AppendQuery("api-version", _apiVersion, true); + if (path != null) + { + uri.AppendQuery("path", path, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/octet-stream"); + return message; + } + + internal HttpMessage CreateGetSessionResourceFilesNextPageRequest(string nextLink, string identifier, string path, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendRawNextLink(nextLink, false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + private static RequestContext DefaultRequestContext = new RequestContext(); + internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) + { + if (!cancellationToken.CanBeCanceled) + { + return DefaultRequestContext; + } + + return new RequestContext() { CancellationToken = cancellationToken }; + } + + private static ResponseClassifier _responseClassifier200; + private static ResponseClassifier ResponseClassifier200 => _responseClassifier200 ??= new StatusCodeClassifier(stackalloc ushort[] { 200 }); + private static ResponseClassifier _responseClassifier204; + private static ResponseClassifier ResponseClassifier204 => _responseClassifier204 ??= new StatusCodeClassifier(stackalloc ushort[] { 204 }); + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionsListResponse.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionsListResponse.Serialization.cs new file mode 100644 index 000000000000..25816e1f0fcd --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionsListResponse.Serialization.cs @@ -0,0 +1,168 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class SessionsListResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionsListResponse)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("sessions"u8); + writer.WriteStartArray(); + foreach (var item in Sessions) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (Optional.IsDefined(NextLink)) + { + writer.WritePropertyName("nextLink"u8); + writer.WriteStringValue(NextLink.AbsoluteUri); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SessionsListResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SessionsListResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSessionsListResponse(document.RootElement, options); + } + + internal static SessionsListResponse DeserializeSessionsListResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList sessions = default; + Uri nextLink = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("sessions"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(Session.DeserializeSession(item, options)); + } + sessions = array; + continue; + } + if (property.NameEquals("nextLink"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nextLink = new Uri(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new SessionsListResponse(sessions, nextLink, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + default: + throw new FormatException($"The model {nameof(SessionsListResponse)} does not support writing '{options.Format}' format."); + } + } + + SessionsListResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionsListResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SessionsListResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static SessionsListResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeSessionsListResponse(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionsListResponse.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionsListResponse.cs new file mode 100644 index 000000000000..d708d1dcbafb --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/SessionsListResponse.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.App.DynamicSessions +{ + /// The sessions list response. + public partial class SessionsListResponse + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The list of sessions. + /// is null. + internal SessionsListResponse(IEnumerable sessions) + { + Argument.AssertNotNull(sessions, nameof(sessions)); + + Sessions = sessions.ToList(); + } + + /// Initializes a new instance of . + /// The list of sessions. + /// The link to the next page of sessions. + /// Keeps track of any properties unknown to the library. + internal SessionsListResponse(IReadOnlyList sessions, Uri nextLink, IDictionary serializedAdditionalRawData) + { + Sessions = sessions; + NextLink = nextLink; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal SessionsListResponse() + { + } + + /// The list of sessions. + public IReadOnlyList Sessions { get; } + /// The link to the next page of sessions. + public Uri NextLink { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/UploadRequest.Serialization.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/UploadRequest.Serialization.cs new file mode 100644 index 000000000000..7f8e590b1210 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/UploadRequest.Serialization.cs @@ -0,0 +1,175 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace Microsoft.App.DynamicSessions +{ + public partial class UploadRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UploadRequest)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("file"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(global::System.BinaryData.FromStream(File)); +#else + using (JsonDocument document = JsonDocument.Parse(BinaryData.FromStream(File), ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + UploadRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UploadRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUploadRequest(document.RootElement, options); + } + + internal static UploadRequest DeserializeUploadRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Stream file = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file"u8)) + { + file = BinaryData.FromString(property.Value.GetRawText()).ToStream(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UploadRequest(file, serializedAdditionalRawData); + } + + private BinaryData SerializeMultipart(ModelReaderWriterOptions options) + { + using MultipartFormDataRequestContent content = ToMultipartRequestContent(); + using MemoryStream stream = new MemoryStream(); + content.WriteTo(stream); + if (stream.Position > int.MaxValue) + { + return BinaryData.FromStream(stream); + } + else + { + return new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position)); + } + } + + internal virtual MultipartFormDataRequestContent ToMultipartRequestContent() + { + MultipartFormDataRequestContent content = new MultipartFormDataRequestContent(); + content.Add(File, "file", "file", "application/octet-stream"); + return content; + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, MicrosoftAppDynamicSessionsContext.Default); + case "MFD": + return SerializeMultipart(options); + default: + throw new FormatException($"The model {nameof(UploadRequest)} does not support writing '{options.Format}' format."); + } + } + + UploadRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUploadRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UploadRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "MFD"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UploadRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUploadRequest(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/UploadRequest.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/UploadRequest.cs new file mode 100644 index 000000000000..e4101c59cecf --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Generated/UploadRequest.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.IO; + +namespace Microsoft.App.DynamicSessions +{ + /// The UploadRequest. + public partial class UploadRequest + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The file to upload. + /// is null. + public UploadRequest(Stream file) + { + Argument.AssertNotNull(file, nameof(file)); + + File = file; + } + + /// Initializes a new instance of . + /// The file to upload. + /// Keeps track of any properties unknown to the library. + internal UploadRequest(Stream file, IDictionary serializedAdditionalRawData) + { + File = file; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal UploadRequest() + { + } + + /// The file to upload. + public Stream File { get; } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Microsoft.App.DynamicSessions.csproj b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Microsoft.App.DynamicSessions.csproj new file mode 100644 index 000000000000..66908b681557 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Microsoft.App.DynamicSessions.csproj @@ -0,0 +1,19 @@ + + + This is the Microsoft.App.DynamicSessions client library for developing .NET applications with rich experience. + Azure SDK Code Generation Microsoft.App.DynamicSessions for Azure Data Plane + 1.0.0-beta.1 + Microsoft.App.DynamicSessions + $(RequiredTargetFrameworks) + true + + + + + + + + + + + diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Properties/AssemblyInfo.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..30c11b3b63b9 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/src/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.App.DynamicSessions.Tests, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")] diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_CodeExecution.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_CodeExecution.cs new file mode 100644 index 000000000000..8e0115b4ae8f --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_CodeExecution.cs @@ -0,0 +1,342 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Microsoft.App.DynamicSessions.Samples +{ + public partial class Samples_CodeExecution + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetCompleted() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("executionType").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetCompleted_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("executionType").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetCompleted_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetCompleted_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetRunning() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("executionType").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetRunning_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("id").ToString()); + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("executionType").ToString()); + Console.WriteLine(result.GetProperty("status").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetRunning_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionCodeExecutionResource("testExecutionId", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionCodeExecutionResource_GetSessionCodeExecutionResource_CodeExecutionGetRunning_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionCodeExecutionResourceAsync("testExecutionId", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_CodeExecution_Execute_CodeExecutionExecuteAsyncCompleted() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = RequestContent.Create(new + { + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, + }); + Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", content); + BinaryData responseData = operation.Value; + + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_CodeExecution_Execute_CodeExecutionExecuteAsyncCompleted_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = RequestContent.Create(new + { + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, + }); + Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", content); + BinaryData responseData = operation.Value; + + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_CodeExecution_Execute_CodeExecutionExecuteAsyncCompleted_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); + Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); + SessionCodeExecutionResult responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_CodeExecution_Execute_CodeExecutionExecuteAsyncCompleted_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); + Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); + SessionCodeExecutionResult responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_CodeExecution_Execute_CodeExecutionExecuteAsyncRunning() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = RequestContent.Create(new + { + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, + }); + Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", content); + BinaryData responseData = operation.Value; + + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_CodeExecution_Execute_CodeExecutionExecuteAsyncRunning_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = RequestContent.Create(new + { + codeInputType = "Inline", + executionType = "Asynchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, + }); + Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", content); + BinaryData responseData = operation.Value; + + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_CodeExecution_Execute_CodeExecutionExecuteAsyncRunning_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); + Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); + SessionCodeExecutionResult responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_CodeExecution_Execute_CodeExecutionExecuteAsyncRunning_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Asynchronous, "print(7*9)", 60L); + Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); + SessionCodeExecutionResult responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_CodeExecution_Execute_CodeExecutionExecuteSync() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = RequestContent.Create(new + { + codeInputType = "Inline", + executionType = "Synchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, + }); + Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", content); + BinaryData responseData = operation.Value; + + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_CodeExecution_Execute_CodeExecutionExecuteSync_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = RequestContent.Create(new + { + codeInputType = "Inline", + executionType = "Synchronous", + code = "print(7*9)", + timeoutInSeconds = 60L, + }); + Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", content); + BinaryData responseData = operation.Value; + + JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_CodeExecution_Execute_CodeExecutionExecuteSync_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Synchronous, "print(7*9)", 60L); + Operation operation = client.Execute(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); + SessionCodeExecutionResult responseData = operation.Value; + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_CodeExecution_Execute_CodeExecutionExecuteSync_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + CodeExecution client = new DynamicSessionsClient(endpoint, credential).GetCodeExecutionClient(apiVersion: "2024-10-02-preview"); + + SessionCodeExecutionRequest codeExecutionRequest = new SessionCodeExecutionRequest(CodeInputType.Inline, ExecutionType.Synchronous, "print(7*9)", 60L); + Operation operation = await client.ExecuteAsync(WaitUntil.Completed, "testSessionIdentifier", codeExecutionRequest); + SessionCodeExecutionResult responseData = operation.Value; + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_ListSessions.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_ListSessions.cs new file mode 100644 index 000000000000..f3a2822f4a46 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_ListSessions.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Microsoft.App.DynamicSessions.Samples +{ + public partial class Samples_ListSessions + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ListSessions_GetListSession_ShortVersion() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetListSession(null, null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ListSessions_GetListSession_ShortVersion_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetListSessionAsync(null, null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ListSessions_GetListSession_ShortVersion_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetListSession(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ListSessions_GetListSession_ShortVersion_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetListSessionAsync(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ListSessions_GetListSession_AllParameters() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetListSession(1234, null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); + Console.WriteLine(result.GetProperty("nextLink").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ListSessions_GetListSession_AllParameters_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetListSessionAsync(1234, null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("sessions")[0].GetProperty("etag").ToString()); + Console.WriteLine(result.GetProperty("nextLink").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_ListSessions_GetListSession_AllParameters_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetListSession(skip: 1234); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_ListSessions_GetListSession_AllParameters_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + ListSessions client = new DynamicSessionsClient(endpoint, credential).GetListSessionsClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetListSessionAsync(skip: 1234); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionManagement.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionManagement.cs new file mode 100644 index 000000000000..28c0ff307a34 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionManagement.cs @@ -0,0 +1,188 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Microsoft.App.DynamicSessions.Samples +{ + public partial class Samples_SessionManagement + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionManagement_GetSessionManagement_ShortVersion() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionManagement("", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("etag").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionManagement_GetSessionManagement_ShortVersion_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionManagementAsync("", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("etag").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionManagement_GetSessionManagement_ShortVersion_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionManagement(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionManagement_GetSessionManagement_ShortVersion_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionManagementAsync(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionManagement_GetSessionManagement_AllParameters() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionManagement("", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("etag").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionManagement_GetSessionManagement_AllParameters_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionManagementAsync("", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("identifier").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastAccessedAt").ToString()); + Console.WriteLine(result.GetProperty("expireAt").ToString()); + Console.WriteLine(result.GetProperty("etag").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionManagement_GetSessionManagement_AllParameters_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionManagement(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionManagement_GetSessionManagement_AllParameters_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionManagementAsync(""); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionManagement_Delete_ShortVersion() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = client.Delete(""); + + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionManagement_Delete_ShortVersion_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.DeleteAsync(""); + + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionManagement_Delete_AllParameters() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = client.Delete(""); + + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionManagement_Delete_AllParameters_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionManagement client = new DynamicSessionsClient(endpoint, credential).GetSessionManagementClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.DeleteAsync(""); + + Console.WriteLine(response.Status); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionPoolMetadata.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionPoolMetadata.cs new file mode 100644 index 000000000000..a7b88f02ebac --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionPoolMetadata.cs @@ -0,0 +1,156 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Microsoft.App.DynamicSessions.Samples +{ + public partial class Samples_SessionPoolMetadata + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionPoolMetadata_GetSessionPoolMetadata_ShortVersion() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionPoolMetadata(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionPoolMetadata_GetSessionPoolMetadata_ShortVersion_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionPoolMetadataAsync(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionPoolMetadata_GetSessionPoolMetadata_ShortVersion_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionPoolMetadata(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionPoolMetadata_GetSessionPoolMetadata_ShortVersion_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionPoolMetadataAsync(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionPoolMetadata_GetSessionPoolMetadata_AllParameters() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionPoolMetadata(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionPoolMetadata_GetSessionPoolMetadata_AllParameters_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionPoolMetadataAsync(null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("runtimes")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("preInstalledPackages")[0].GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("createdAt").ToString()); + Console.WriteLine(result.GetProperty("lastUpdatedAt").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("version").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("projectUrl").ToString()); + Console.WriteLine(result.GetProperty("jupyterKernel").GetProperty("description").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionPoolMetadata_GetSessionPoolMetadata_AllParameters_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionPoolMetadata(); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionPoolMetadata_GetSessionPoolMetadata_AllParameters_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionPoolMetadata client = new DynamicSessionsClient(endpoint, credential).GetSessionPoolMetadataClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionPoolMetadataAsync(); + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionResourceFiles.cs b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionResourceFiles.cs new file mode 100644 index 000000000000..f1aa68e5c63d --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Generated/Samples/Samples_SessionResourceFiles.cs @@ -0,0 +1,268 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using NUnit.Framework; + +namespace Microsoft.App.DynamicSessions.Samples +{ + public partial class Samples_SessionResourceFiles + { + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFile_GetSessionResourceFile_SessionResourceFilesGet() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionResourceFile("testfile", "testSessionIdentifier", "/", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFile_GetSessionResourceFile_SessionResourceFilesGet_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionResourceFileAsync("testfile", "testSessionIdentifier", "/", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFile_GetSessionResourceFile_SessionResourceFilesGet_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetSessionResourceFile("testfile", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFile_GetSessionResourceFile_SessionResourceFilesGet_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetSessionResourceFileAsync("testfile", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFile_Delete_SessionResourceFilesDelete() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = client.Delete("testfile", "testSessionIdentifier"); + + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFile_Delete_SessionResourceFilesDelete_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.DeleteAsync("testfile", "testSessionIdentifier"); + + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFiles_Upload_SessionResourceFilesUpload() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = null; + Response response = client.Upload("testSessionIdentifier", content, null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFiles_Upload_SessionResourceFilesUpload_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + using RequestContent content = null; + Response response = await client.UploadAsync("testSessionIdentifier", content, null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFiles_Upload_SessionResourceFilesUpload_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + UploadRequest body = null; + Response response = client.Upload("testSessionIdentifier", body); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFiles_Upload_SessionResourceFilesUpload_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + UploadRequest body = null; + Response response = await client.UploadAsync("testSessionIdentifier", body); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFiles_GetContent_SessionResourceFilesGetContent() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetContent("testfile", "testSessionIdentifier", "/", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFiles_GetContent_SessionResourceFilesGetContent_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetContentAsync("testfile", "testSessionIdentifier", "/", null); + + JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; + Console.WriteLine(result.ToString()); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFiles_GetContent_SessionResourceFilesGetContent_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = client.GetContent("testfile", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFiles_GetContent_SessionResourceFilesGetContent_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + Response response = await client.GetContentAsync("testfile", "testSessionIdentifier"); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFile_GetSessionResourceFiles_SessionResourceFilesList() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + foreach (BinaryData item in client.GetSessionResourceFiles("testSessionIdentifier", "/", null)) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFile_GetSessionResourceFiles_SessionResourceFilesList_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + await foreach (BinaryData item in client.GetSessionResourceFilesAsync("testSessionIdentifier", "/", null)) + { + JsonElement result = JsonDocument.Parse(item.ToStream()).RootElement; + Console.WriteLine(result.GetProperty("name").ToString()); + Console.WriteLine(result.GetProperty("type").ToString()); + Console.WriteLine(result.GetProperty("lastModifiedAt").ToString()); + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SessionResourceFile_GetSessionResourceFiles_SessionResourceFilesList_Convenience() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + foreach (SessionResourceFile item in client.GetSessionResourceFiles("testSessionIdentifier")) + { + } + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SessionResourceFile_GetSessionResourceFiles_SessionResourceFilesList_Convenience_Async() + { + Uri endpoint = new Uri(""); + TokenCredential credential = new DefaultAzureCredential(); + SessionResourceFiles client = new DynamicSessionsClient(endpoint, credential).GetSessionResourceFilesClient(apiVersion: "2024-10-02-preview"); + + await foreach (SessionResourceFile item in client.GetSessionResourceFilesAsync("testSessionIdentifier")) + { + } + } + } +} diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Microsoft.App.DynamicSessions.Tests.csproj b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Microsoft.App.DynamicSessions.Tests.csproj new file mode 100644 index 000000000000..060a1cce65bd --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tests/Microsoft.App.DynamicSessions.Tests.csproj @@ -0,0 +1,19 @@ + + + $(RequiredTargetFrameworks) + + $(NoWarn);CS1591 + + + + + + + + + + + + + + diff --git a/sdk/microsoft.app/Microsoft.App.DynamicSessions/tsp-location.yaml b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tsp-location.yaml new file mode 100644 index 000000000000..79be09c4da17 --- /dev/null +++ b/sdk/microsoft.app/Microsoft.App.DynamicSessions/tsp-location.yaml @@ -0,0 +1,4 @@ +directory: specification/app/Microsoft.App.DynamicSessions +commit: 1b59d8d593ff1c9ac005d76960b3d9e79aa92be3 +repo: Azure/azure-rest-api-specs +additionalDirectories: