diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClient.cs new file mode 100644 index 000000000000..79ba8701f09f --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClient.cs @@ -0,0 +1,172 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Microsoft.Rest; + using Microsoft.Rest.Serialization; + using Models; + using Newtonsoft.Json; + using System.Collections; + using System.Collections.Generic; + using System.Net; + using System.Net.Http; + + public partial class AzureMessagingWebPubSubServiceClient : ServiceClient, IAzureMessagingWebPubSubServiceClient + { + /// + /// The base URI of the service. + /// + public System.Uri BaseUri { get; set; } + + /// + /// Gets or sets json serialization settings. + /// + public JsonSerializerSettings SerializationSettings { get; private set; } + + /// + /// Gets or sets json deserialization settings. + /// + public JsonSerializerSettings DeserializationSettings { get; private set; } + + /// + /// Gets the IHealthApi. + /// + public virtual IHealthApi HealthApi { get; private set; } + + /// + /// Gets the IWebPubSubOperations. + /// + public virtual IWebPubSubOperations WebPubSub { get; private set; } + + /// + /// Initializes a new instance of the AzureMessagingWebPubSubServiceClient class. + /// + /// + /// HttpClient to be used + /// + /// + /// True: will dispose the provided httpClient on calling AzureMessagingWebPubSubServiceClient.Dispose(). False: will not dispose provided httpClient + public AzureMessagingWebPubSubServiceClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient) + { + Initialize(); + } + + /// + /// Initializes a new instance of the AzureMessagingWebPubSubServiceClient class. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + public AzureMessagingWebPubSubServiceClient(params DelegatingHandler[] handlers) : base(handlers) + { + Initialize(); + } + + /// + /// Initializes a new instance of the AzureMessagingWebPubSubServiceClient class. + /// + /// + /// Optional. The http client handler used to handle http transport. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + public AzureMessagingWebPubSubServiceClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers) + { + Initialize(); + } + + /// + /// Initializes a new instance of the AzureMessagingWebPubSubServiceClient class. + /// + /// + /// Optional. The base URI of the service. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + /// + /// Thrown when a required parameter is null + /// + public AzureMessagingWebPubSubServiceClient(System.Uri baseUri, params DelegatingHandler[] handlers) : this(handlers) + { + if (baseUri == null) + { + throw new System.ArgumentNullException("baseUri"); + } + BaseUri = baseUri; + } + + /// + /// Initializes a new instance of the AzureMessagingWebPubSubServiceClient class. + /// + /// + /// Optional. The base URI of the service. + /// + /// + /// Optional. The http client handler used to handle http transport. + /// + /// + /// Optional. The delegating handlers to add to the http client pipeline. + /// + /// + /// Thrown when a required parameter is null + /// + public AzureMessagingWebPubSubServiceClient(System.Uri baseUri, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) + { + if (baseUri == null) + { + throw new System.ArgumentNullException("baseUri"); + } + BaseUri = baseUri; + } + + /// + /// An optional partial-method to perform custom initialization. + /// + partial void CustomInitialize(); + /// + /// Initializes client properties. + /// + private void Initialize() + { + HealthApi = new HealthApi(this); + WebPubSub = new WebPubSubOperations(this); + BaseUri = new System.Uri("http://localhost"); + SerializationSettings = new JsonSerializerSettings + { + Formatting = Newtonsoft.Json.Formatting.Indented, + DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, + DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, + NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, + ContractResolver = new ReadOnlyJsonContractResolver(), + Converters = new List + { + new Iso8601TimeSpanConverter() + } + }; + DeserializationSettings = new JsonSerializerSettings + { + DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, + DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, + NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, + ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, + ContractResolver = new ReadOnlyJsonContractResolver(), + Converters = new List + { + new Iso8601TimeSpanConverter() + } + }; + CustomInitialize(); + } + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApi.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApi.cs new file mode 100644 index 000000000000..68ef84269fd5 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApi.cs @@ -0,0 +1,165 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Microsoft.Rest; + using Models; + using System.Collections; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + + /// + /// HealthApi operations. + /// + public partial class HealthApi : IServiceOperations, IHealthApi + { + /// + /// Initializes a new instance of the HealthApi class. + /// + /// + /// Reference to the service client. + /// + /// + /// Thrown when a required parameter is null + /// + public HealthApi(AzureMessagingWebPubSubServiceClient client) + { + if (client == null) + { + throw new System.ArgumentNullException("client"); + } + Client = client; + } + + /// + /// Gets a reference to the AzureMessagingWebPubSubServiceClient + /// + public AzureMessagingWebPubSubServiceClient Client { get; private set; } + + /// + /// Get service health status. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task GetServiceStatusWithHttpMessagesAsync(string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "GetServiceStatus", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/health").ToString(); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("HEAD"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApiExtensions.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApiExtensions.cs new file mode 100644 index 000000000000..a56f3fc62029 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApiExtensions.cs @@ -0,0 +1,54 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Models; + using System.Threading; + using System.Threading.Tasks; + + /// + /// Extension methods for HealthApi. + /// + public static partial class HealthApiExtensions + { + /// + /// Get service health status. + /// + /// + /// The operations group for this extension method. + /// + /// + /// The version of the REST APIs. + /// + public static void GetServiceStatus(this IHealthApi operations, string apiVersion = "2021-05-01-preview") + { + operations.GetServiceStatusAsync(apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Get service health status. + /// + /// + /// The operations group for this extension method. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task GetServiceStatusAsync(this IHealthApi operations, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.GetServiceStatusWithHttpMessagesAsync(apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IAzureMessagingWebPubSubServiceClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IAzureMessagingWebPubSubServiceClient.cs new file mode 100644 index 000000000000..008eff90d136 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IAzureMessagingWebPubSubServiceClient.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Models; + using Newtonsoft.Json; + + /// + /// + public partial interface IAzureMessagingWebPubSubServiceClient : System.IDisposable + { + /// + /// The base URI of the service. + /// + System.Uri BaseUri { get; set; } + + /// + /// Gets or sets json serialization settings. + /// + JsonSerializerSettings SerializationSettings { get; } + + /// + /// Gets or sets json deserialization settings. + /// + JsonSerializerSettings DeserializationSettings { get; } + + + /// + /// Gets the IHealthApi. + /// + IHealthApi HealthApi { get; } + + /// + /// Gets the IWebPubSubOperations. + /// + IWebPubSubOperations WebPubSub { get; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IHealthApi.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IHealthApi.cs new file mode 100644 index 000000000000..c33bd8797dbe --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IHealthApi.cs @@ -0,0 +1,42 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Microsoft.Rest; + using Models; + using System.Collections; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + /// + /// HealthApi operations. + /// + public partial interface IHealthApi + { + /// + /// Get service health status. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + Task GetServiceStatusWithHttpMessagesAsync(string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IWebPubSubOperations.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IWebPubSubOperations.cs new file mode 100644 index 000000000000..49a63e25c4f0 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IWebPubSubOperations.cs @@ -0,0 +1,510 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Microsoft.Rest; + using Models; + using System.Collections; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + /// + /// WebPubSubOperations operations. + /// + public partial interface IWebPubSubOperations + { + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task SendToAllWithHttpMessagesAsync(string hub, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task ConnectionExistsWithHttpMessagesAsync(string hub, string connectionId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Close the client connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task CloseClientConnectionWithHttpMessagesAsync(string hub, string connectionId, string reason = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Send content inside request body to the specific connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task SendToConnectionWithHttpMessagesAsync(string hub, string connectionId, string message, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Check if there are any client connections inside the given group + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less + /// than 1025. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task GroupExistsWithHttpMessagesAsync(string hub, string group, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Send content inside request body to a group of connections. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less + /// than 1025. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task SendToGroupWithHttpMessagesAsync(string hub, string group, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Add a connection to the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less + /// than 1025. + /// + /// + /// Target connection Id + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task AddConnectionToGroupWithHttpMessagesAsync(string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Remove a connection from the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less + /// than 1025. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task RemoveConnectionFromGroupWithHttpMessagesAsync(string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Check if there are any client connections connected for the given + /// user. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task UserExistsWithHttpMessagesAsync(string hub, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Send content inside request body to the specific user. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task SendToUserWithHttpMessagesAsync(string hub, string userId, string message, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Add a user to the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less + /// than 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task AddUserToGroupWithHttpMessagesAsync(string hub, string group, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Remove a user from the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less + /// than 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task RemoveUserFromGroupWithHttpMessagesAsync(string hub, string group, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Remove a user from all groups. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task RemoveUserFromAllGroupsWithHttpMessagesAsync(string hub, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Grant permission to the connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', + /// 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, grant the permission to all the targets. If + /// set, grant the permission to the specific target. The meaning of + /// the target depends on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task GrantPermissionWithHttpMessagesAsync(string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Revoke permission for the connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', + /// 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, revoke the permission for all targets. If + /// set, revoke the permission for the specific target. The meaning of + /// the target depends on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task RevokePermissionWithHttpMessagesAsync(string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', + /// 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, get the permission for all targets. If set, + /// get the permission for the specific target. The meaning of the + /// target depends on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + Task CheckPermissionWithHttpMessagesAsync(string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/WebPubSubPermission.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/WebPubSubPermission.cs new file mode 100644 index 000000000000..16de7b38bf7d --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/WebPubSubPermission.cs @@ -0,0 +1,22 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub.Models +{ + + /// + /// Defines values for WebPubSubPermission. + /// + public static class WebPubSubPermission + { + public const string SendToGroup = "sendToGroup"; + public const string JoinLeaveGroup = "joinLeaveGroup"; + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/SdkInfo_AzureMessagingWebPubSubServiceClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/SdkInfo_AzureMessagingWebPubSubServiceClient.cs new file mode 100644 index 000000000000..2dea73e3e24d --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/SdkInfo_AzureMessagingWebPubSubServiceClient.cs @@ -0,0 +1,28 @@ + +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using System; + using System.Collections.Generic; + using System.Linq; + + internal static partial class SdkInfo + { + public static IEnumerable> ApiInfo_AzureMessagingWebPubSubServiceClient + { + get + { + return new Tuple[] + { + new Tuple("AzureMessagingWebPubSubServiceClient", "HealthApi", "2021-05-01-preview"), + new Tuple("AzureMessagingWebPubSubServiceClient", "WebPubSub", "2021-05-01-preview"), + }.AsEnumerable(); + } + } + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubOperations.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubOperations.cs new file mode 100644 index 000000000000..151b867fc2e8 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubOperations.cs @@ -0,0 +1,2708 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Microsoft.Rest; + using Models; + using System.Collections; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + + /// + /// WebPubSubOperations operations. + /// + public partial class WebPubSubOperations : IServiceOperations, IWebPubSubOperations + { + /// + /// Initializes a new instance of the WebPubSubOperations class. + /// + /// + /// Reference to the service client. + /// + /// + /// Thrown when a required parameter is null + /// + public WebPubSubOperations(AzureMessagingWebPubSubServiceClient client) + { + if (client == null) + { + throw new System.ArgumentNullException("client"); + } + Client = client; + } + + /// + /// Gets a reference to the AzureMessagingWebPubSubServiceClient + /// + public AzureMessagingWebPubSubServiceClient Client { get; private set; } + + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task SendToAllWithHttpMessagesAsync(string hub, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (message == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "message"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("excluded", excluded); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("message", message); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "SendToAll", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/:send").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + List _queryParameters = new List(); + if (excluded != null) + { + if (excluded.Count == 0) + { + _queryParameters.Add(string.Format("excluded={0}", System.Uri.EscapeDataString(string.Empty))); + } + else + { + foreach (var _item in excluded) + { + _queryParameters.Add(string.Format("excluded={0}", System.Uri.EscapeDataString("" + _item))); + } + } + } + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("POST"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + if(message != null) + { + _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(message, Client.SerializationSettings); + _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); + _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 202) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task ConnectionExistsWithHttpMessagesAsync(string hub, string connectionId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "ConnectionExists", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("HEAD"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200 && (int)_statusCode != 404) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Close the client connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task CloseClientConnectionWithHttpMessagesAsync(string hub, string connectionId, string reason = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("reason", reason); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "CloseClientConnection", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (reason != null) + { + _queryParameters.Add(string.Format("reason={0}", System.Uri.EscapeDataString(reason))); + } + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("DELETE"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task SendToConnectionWithHttpMessagesAsync(string hub, string connectionId, string message, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + if (message == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "message"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("message", message); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "SendToConnection", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/connections/{connectionId}/:send").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("POST"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + if(message != null) + { + _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(message, Client.SerializationSettings); + _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); + _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 202) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task GroupExistsWithHttpMessagesAsync(string hub, string group, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (group == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "group"); + } + if (group != null) + { + if (group.Length > 1024) + { + throw new ValidationException(ValidationRules.MaxLength, "group", 1024); + } + if (group.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "group", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "GroupExists", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/groups/{group}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{group}", System.Uri.EscapeDataString(group)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("HEAD"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200 && (int)_statusCode != 404) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task SendToGroupWithHttpMessagesAsync(string hub, string group, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (group == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "group"); + } + if (group != null) + { + if (group.Length > 1024) + { + throw new ValidationException(ValidationRules.MaxLength, "group", 1024); + } + if (group.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "group", 1); + } + } + if (message == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "message"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("excluded", excluded); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("message", message); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "SendToGroup", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/groups/{group}/:send").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{group}", System.Uri.EscapeDataString(group)); + List _queryParameters = new List(); + if (excluded != null) + { + if (excluded.Count == 0) + { + _queryParameters.Add(string.Format("excluded={0}", System.Uri.EscapeDataString(string.Empty))); + } + else + { + foreach (var _item in excluded) + { + _queryParameters.Add(string.Format("excluded={0}", System.Uri.EscapeDataString("" + _item))); + } + } + } + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("POST"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + if(message != null) + { + _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(message, Client.SerializationSettings); + _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); + _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 202) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Add a connection to the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target connection Id + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task AddConnectionToGroupWithHttpMessagesAsync(string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (group == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "group"); + } + if (group != null) + { + if (group.Length > 1024) + { + throw new ValidationException(ValidationRules.MaxLength, "group", 1024); + } + if (group.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "group", 1); + } + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "AddConnectionToGroup", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/groups/{group}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{group}", System.Uri.EscapeDataString(group)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("PUT"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200 && (int)_statusCode != 404) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Remove a connection from the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task RemoveConnectionFromGroupWithHttpMessagesAsync(string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (group == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "group"); + } + if (group != null) + { + if (group.Length > 1024) + { + throw new ValidationException(ValidationRules.MaxLength, "group", 1024); + } + if (group.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "group", 1); + } + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "RemoveConnectionFromGroup", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/groups/{group}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{group}", System.Uri.EscapeDataString(group)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("DELETE"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if there are any client connections connected for the given user. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task UserExistsWithHttpMessagesAsync(string hub, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (userId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "userId"); + } + if (userId != null) + { + if (userId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "userId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("userId", userId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "UserExists", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/users/{userId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{userId}", System.Uri.EscapeDataString(userId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("HEAD"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200 && (int)_statusCode != 404) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Send content inside request body to the specific user. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task SendToUserWithHttpMessagesAsync(string hub, string userId, string message, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (userId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "userId"); + } + if (userId != null) + { + if (userId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "userId", 1); + } + } + if (message == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "message"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("userId", userId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("message", message); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "SendToUser", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/users/{userId}/:send").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{userId}", System.Uri.EscapeDataString(userId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("POST"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + if(message != null) + { + _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(message, Client.SerializationSettings); + _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); + _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); + } + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 202) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Add a user to the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task AddUserToGroupWithHttpMessagesAsync(string hub, string group, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (group == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "group"); + } + if (group != null) + { + if (group.Length > 1024) + { + throw new ValidationException(ValidationRules.MaxLength, "group", 1024); + } + if (group.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "group", 1); + } + } + if (userId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "userId"); + } + if (userId != null) + { + if (userId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "userId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("userId", userId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "AddUserToGroup", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/users/{userId}/groups/{group}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{group}", System.Uri.EscapeDataString(group)); + _url = _url.Replace("{userId}", System.Uri.EscapeDataString(userId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("PUT"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200 && (int)_statusCode != 404) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Remove a user from the target group. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task RemoveUserFromGroupWithHttpMessagesAsync(string hub, string group, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (group == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "group"); + } + if (group != null) + { + if (group.Length > 1024) + { + throw new ValidationException(ValidationRules.MaxLength, "group", 1024); + } + if (group.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "group", 1); + } + } + if (userId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "userId"); + } + if (userId != null) + { + if (userId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "userId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("userId", userId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "RemoveUserFromGroup", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/users/{userId}/groups/{group}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{group}", System.Uri.EscapeDataString(group)); + _url = _url.Replace("{userId}", System.Uri.EscapeDataString(userId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("DELETE"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Remove a user from all groups. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task RemoveUserFromAllGroupsWithHttpMessagesAsync(string hub, string userId, string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (userId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "userId"); + } + if (userId != null) + { + if (userId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "userId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("userId", userId); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "RemoveUserFromAllGroups", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/users/{userId}/groups").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{userId}", System.Uri.EscapeDataString(userId)); + List _queryParameters = new List(); + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("DELETE"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Grant permission to the connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, grant the permission to all the targets. If set, + /// grant the permission to the specific target. The meaning of the target + /// depends on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task GrantPermissionWithHttpMessagesAsync(string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (permission == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "permission"); + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("permission", permission); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("targetName", targetName); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "GrantPermission", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/permissions/{permission}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{permission}", System.Uri.EscapeDataString(permission)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (targetName != null) + { + _queryParameters.Add(string.Format("targetName={0}", System.Uri.EscapeDataString(targetName))); + } + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("PUT"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Revoke permission for the connection. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, revoke the permission for all targets. If set, revoke + /// the permission for the specific target. The meaning of the target depends + /// on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task RevokePermissionWithHttpMessagesAsync(string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (permission == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "permission"); + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("permission", permission); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("targetName", targetName); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "RevokePermission", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/permissions/{permission}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{permission}", System.Uri.EscapeDataString(permission)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (targetName != null) + { + _queryParameters.Add(string.Format("targetName={0}", System.Uri.EscapeDataString(targetName))); + } + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("DELETE"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, get the permission for all targets. If set, get the + /// permission for the specific target. The meaning of the target depends on + /// the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// Thrown when a required parameter is null + /// + /// + /// A response object containing the response body and response headers. + /// + public async Task CheckPermissionWithHttpMessagesAsync(string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (hub == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "hub"); + } + if (hub != null) + { + if (!System.Text.RegularExpressions.Regex.IsMatch(hub, "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$")) + { + throw new ValidationException(ValidationRules.Pattern, "hub", "^[A-Za-z][A-Za-z0-9_`,.[\\]]{0,127}$"); + } + } + if (permission == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "permission"); + } + if (connectionId == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "connectionId"); + } + if (connectionId != null) + { + if (connectionId.Length < 1) + { + throw new ValidationException(ValidationRules.MinLength, "connectionId", 1); + } + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("hub", hub); + tracingParameters.Add("permission", permission); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("targetName", targetName); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "CheckPermission", tracingParameters); + } + // Construct URL + var _baseUrl = Client.BaseUri.AbsoluteUri; + var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/hubs/{hub}/permissions/{permission}/connections/{connectionId}").ToString(); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{permission}", System.Uri.EscapeDataString(permission)); + _url = _url.Replace("{connectionId}", System.Uri.EscapeDataString(connectionId)); + List _queryParameters = new List(); + if (targetName != null) + { + _queryParameters.Add(string.Format("targetName={0}", System.Uri.EscapeDataString(targetName))); + } + if (apiVersion != null) + { + _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(apiVersion))); + } + if (_queryParameters.Count > 0) + { + _url += "?" + string.Join("&", _queryParameters); + } + // Create HTTP transport objects + var _httpRequest = new HttpRequestMessage(); + HttpResponseMessage _httpResponse = null; + _httpRequest.Method = new HttpMethod("HEAD"); + _httpRequest.RequestUri = new System.Uri(_url); + // Set Headers + + + if (customHeaders != null) + { + foreach(var _header in customHeaders) + { + if (_httpRequest.Headers.Contains(_header.Key)) + { + _httpRequest.Headers.Remove(_header.Key); + } + _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); + } + } + + // Serialize Request + string _requestContent = null; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 200 && (int)_statusCode != 404) + { + var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + if (_httpResponse.Content != null) { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + } + else { + _responseContent = string.Empty; + } + ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); + ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); + if (_shouldTrace) + { + ServiceClientTracing.Error(_invocationId, ex); + } + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw ex; + } + // Create Result + var _result = new HttpOperationResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubOperationsExtensions.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubOperationsExtensions.cs new file mode 100644 index 000000000000..d1368d26f63e --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubOperationsExtensions.cs @@ -0,0 +1,873 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is +// regenerated. +// + +namespace Azure.Messaging.WebPubSub +{ + using Models; + using System.Collections; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + /// + /// Extension methods for WebPubSubOperations. + /// + public static partial class WebPubSubOperationsExtensions + { + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// The version of the REST APIs. + /// + public static void SendToAll(this IWebPubSubOperations operations, string hub, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview") + { + operations.SendToAllAsync(hub, message, excluded, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task SendToAllAsync(this IWebPubSubOperations operations, string hub, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.SendToAllWithHttpMessagesAsync(hub, message, excluded, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The version of the REST APIs. + /// + public static void ConnectionExists(this IWebPubSubOperations operations, string hub, string connectionId, string apiVersion = "2021-05-01-preview") + { + operations.ConnectionExistsAsync(hub, connectionId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task ConnectionExistsAsync(this IWebPubSubOperations operations, string hub, string connectionId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.ConnectionExistsWithHttpMessagesAsync(hub, connectionId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Close the client connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The version of the REST APIs. + /// + public static void CloseClientConnection(this IWebPubSubOperations operations, string hub, string connectionId, string reason = default(string), string apiVersion = "2021-05-01-preview") + { + operations.CloseClientConnectionAsync(hub, connectionId, reason, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Close the client connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task CloseClientConnectionAsync(this IWebPubSubOperations operations, string hub, string connectionId, string reason = default(string), string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.CloseClientConnectionWithHttpMessagesAsync(hub, connectionId, reason, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + public static void SendToConnection(this IWebPubSubOperations operations, string hub, string connectionId, string message, string apiVersion = "2021-05-01-preview") + { + operations.SendToConnectionAsync(hub, connectionId, message, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The connection Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task SendToConnectionAsync(this IWebPubSubOperations operations, string hub, string connectionId, string message, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.SendToConnectionWithHttpMessagesAsync(hub, connectionId, message, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// The version of the REST APIs. + /// + public static void GroupExists(this IWebPubSubOperations operations, string hub, string group, string apiVersion = "2021-05-01-preview") + { + operations.GroupExistsAsync(hub, group, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task GroupExistsAsync(this IWebPubSubOperations operations, string hub, string group, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.GroupExistsWithHttpMessagesAsync(hub, group, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// The version of the REST APIs. + /// + public static void SendToGroup(this IWebPubSubOperations operations, string hub, string group, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview") + { + operations.SendToGroupAsync(hub, group, message, excluded, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task SendToGroupAsync(this IWebPubSubOperations operations, string hub, string group, string message, IList excluded = default(IList), string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.SendToGroupWithHttpMessagesAsync(hub, group, message, excluded, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Add a connection to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target connection Id + /// + /// + /// The version of the REST APIs. + /// + public static void AddConnectionToGroup(this IWebPubSubOperations operations, string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview") + { + operations.AddConnectionToGroupAsync(hub, group, connectionId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Add a connection to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target connection Id + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task AddConnectionToGroupAsync(this IWebPubSubOperations operations, string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.AddConnectionToGroupWithHttpMessagesAsync(hub, group, connectionId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Remove a connection from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + public static void RemoveConnectionFromGroup(this IWebPubSubOperations operations, string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview") + { + operations.RemoveConnectionFromGroupAsync(hub, group, connectionId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Remove a connection from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task RemoveConnectionFromGroupAsync(this IWebPubSubOperations operations, string hub, string group, string connectionId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.RemoveConnectionFromGroupWithHttpMessagesAsync(hub, group, connectionId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Check if there are any client connections connected for the given user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + public static void UserExists(this IWebPubSubOperations operations, string hub, string userId, string apiVersion = "2021-05-01-preview") + { + operations.UserExistsAsync(hub, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if there are any client connections connected for the given user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task UserExistsAsync(this IWebPubSubOperations operations, string hub, string userId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.UserExistsWithHttpMessagesAsync(hub, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Send content inside request body to the specific user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + public static void SendToUser(this IWebPubSubOperations operations, string hub, string userId, string message, string apiVersion = "2021-05-01-preview") + { + operations.SendToUserAsync(hub, userId, message, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Send content inside request body to the specific user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The payload body. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task SendToUserAsync(this IWebPubSubOperations operations, string hub, string userId, string message, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.SendToUserWithHttpMessagesAsync(hub, userId, message, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Add a user to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + public static void AddUserToGroup(this IWebPubSubOperations operations, string hub, string group, string userId, string apiVersion = "2021-05-01-preview") + { + operations.AddUserToGroupAsync(hub, group, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Add a user to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task AddUserToGroupAsync(this IWebPubSubOperations operations, string hub, string group, string userId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.AddUserToGroupWithHttpMessagesAsync(hub, group, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Remove a user from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + public static void RemoveUserFromGroup(this IWebPubSubOperations operations, string hub, string group, string userId, string apiVersion = "2021-05-01-preview") + { + operations.RemoveUserFromGroupAsync(hub, group, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Remove a user from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target group name, which length should be greater than 0 and less than + /// 1025. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task RemoveUserFromGroupAsync(this IWebPubSubOperations operations, string hub, string group, string userId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.RemoveUserFromGroupWithHttpMessagesAsync(hub, group, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Remove a user from all groups. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + public static void RemoveUserFromAllGroups(this IWebPubSubOperations operations, string hub, string userId, string apiVersion = "2021-05-01-preview") + { + operations.RemoveUserFromAllGroupsAsync(hub, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Remove a user from all groups. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task RemoveUserFromAllGroupsAsync(this IWebPubSubOperations operations, string hub, string userId, string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.RemoveUserFromAllGroupsWithHttpMessagesAsync(hub, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Grant permission to the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, grant the permission to all the targets. If set, + /// grant the permission to the specific target. The meaning of the target + /// depends on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + public static void GrantPermission(this IWebPubSubOperations operations, string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview") + { + operations.GrantPermissionAsync(hub, permission, connectionId, targetName, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Grant permission to the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, grant the permission to all the targets. If set, + /// grant the permission to the specific target. The meaning of the target + /// depends on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task GrantPermissionAsync(this IWebPubSubOperations operations, string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.GrantPermissionWithHttpMessagesAsync(hub, permission, connectionId, targetName, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Revoke permission for the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, revoke the permission for all targets. If set, revoke + /// the permission for the specific target. The meaning of the target depends + /// on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + public static void RevokePermission(this IWebPubSubOperations operations, string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview") + { + operations.RevokePermissionAsync(hub, permission, connectionId, targetName, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Revoke permission for the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, revoke the permission for all targets. If set, revoke + /// the permission for the specific target. The meaning of the target depends + /// on the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task RevokePermissionAsync(this IWebPubSubOperations operations, string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.RevokePermissionWithHttpMessagesAsync(hub, permission, connectionId, targetName, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, get the permission for all targets. If set, get the + /// permission for the specific target. The meaning of the target depends on + /// the specific permission. + /// + /// + /// The version of the REST APIs. + /// + public static void CheckPermission(this IWebPubSubOperations operations, string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview") + { + operations.CheckPermissionAsync(hub, permission, connectionId, targetName, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// The operations group for this extension method. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The permission: current supported actions are joinLeaveGroup and + /// sendToGroup. Possible values include: 'sendToGroup', 'joinLeaveGroup' + /// + /// + /// Target connection Id. + /// + /// + /// Optional. If not set, get the permission for all targets. If set, get the + /// permission for the specific target. The meaning of the target depends on + /// the specific permission. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The cancellation token. + /// + public static async Task CheckPermissionAsync(this IWebPubSubOperations operations, string hub, string permission, string connectionId, string targetName = default(string), string apiVersion = "2021-05-01-preview", CancellationToken cancellationToken = default(CancellationToken)) + { + (await operations.CheckPermissionWithHttpMessagesAsync(hub, permission, connectionId, targetName, apiVersion, null, cancellationToken).ConfigureAwait(false)).Dispose(); + } + + } +}