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..c5c55485d58a --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClient.cs @@ -0,0 +1,4142 @@ +// +// 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; + using System.Threading; + using System.Threading.Tasks; + + public partial class AzureMessagingWebPubSubServiceClient : ServiceClient, IAzureMessagingWebPubSubServiceClient + { + /// + /// The base URI of the service. + /// + internal string 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; } + + /// + /// 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(); + } + + /// + /// An optional partial-method to perform custom initialization. + /// + partial void CustomInitialize(); + /// + /// Initializes client properties. + /// + private void Initialize() + { + BaseUri = "{Endpoint}"; + 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(); + } + /// + /// Generate token for the client to connect Azure Web PubSub service. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// User Id. + /// + /// + /// Roles that the connection with the generated token will have. + /// + /// + /// The expire time of the generated token. + /// + /// + /// Headers that will be added to request. + /// + /// + /// The cancellation token. + /// + /// + /// Thrown when the operation returned an invalid status code + /// + /// + /// Thrown when unable to deserialize the response + /// + /// + /// 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> GetClientAccessTokenWithHttpMessagesAsync(string endpoint, string hub, string apiVersion, string userId = default(string), IList roles = default(IList), int? minutesToExpire = 60, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + tracingParameters.Add("hub", hub); + tracingParameters.Add("userId", userId); + tracingParameters.Add("roles", roles); + tracingParameters.Add("minutesToExpire", minutesToExpire); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "GetClientAccessToken", tracingParameters); + } + // Construct URL + var _baseUrl = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/:generateToken"; + _url = _url.Replace("{Endpoint}", endpoint); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + List _queryParameters = new List(); + if (userId != null) + { + _queryParameters.Add(string.Format("userId={0}", System.Uri.EscapeDataString(userId))); + } + if (roles != null) + { + if (roles.Count == 0) + { + _queryParameters.Add(string.Format("role={0}", System.Uri.EscapeDataString(string.Empty))); + } + else + { + foreach (var _item in roles) + { + _queryParameters.Add(string.Format("role={0}", System.Uri.EscapeDataString("" + _item))); + } + } + } + if (minutesToExpire != null) + { + _queryParameters.Add(string.Format("minutesToExpire={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(minutesToExpire, SerializationSettings).Trim('"')))); + } + 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; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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; + // Deserialize Response + if ((int)_statusCode == 200) + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + try + { + _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); + } + } + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Close the connections in the hub. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections in the hub. + /// + /// + /// The reason closing the client connection. + /// + /// + /// 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> CloseAllConnectionsWithHttpMessagesAsync(string endpoint, string hub, string apiVersion, IList excluded = default(IList), string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + tracingParameters.Add("hub", hub); + tracingParameters.Add("excluded", excluded); + tracingParameters.Add("reason", reason); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "CloseAllConnections", tracingParameters); + } + // Construct URL + var _baseUrl = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/:closeConnections"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 (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("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; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// 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 endpoint, string hub, string apiVersion, string message, IList excluded = default(IList), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + 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("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/:send"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 = SafeJsonConvert.SerializeObject(message, 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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string connectionId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Close the client connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The reason closing the client connection. + /// + /// + /// 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> CloseConnectionWithHttpMessagesAsync(string endpoint, string hub, string connectionId, string apiVersion, string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + tracingParameters.Add("hub", hub); + tracingParameters.Add("connectionId", connectionId); + tracingParameters.Add("reason", reason); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "CloseConnection", tracingParameters); + } + // Construct URL + var _baseUrl = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// 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 endpoint, string hub, string connectionId, string apiVersion, string message, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + 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("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/connections/{connectionId}/:send"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 = SafeJsonConvert.SerializeObject(message, 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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string group, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/groups/{group}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Close connections in the specific group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// Exclude these connectionIds when closing the connections in the group. + /// + /// + /// The reason closing the client connection. + /// + /// + /// 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> CloseGroupConnectionsWithHttpMessagesAsync(string endpoint, string hub, string group, string apiVersion, IList excluded = default(IList), string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + tracingParameters.Add("hub", hub); + tracingParameters.Add("group", group); + tracingParameters.Add("excluded", excluded); + tracingParameters.Add("reason", reason); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "CloseGroupConnections", tracingParameters); + } + // Construct URL + var _baseUrl = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/groups/{group}/:closeConnections"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 (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("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; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// 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 endpoint, string hub, string group, string apiVersion, string message, IList excluded = default(IList), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + 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("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/groups/{group}/:send"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 = SafeJsonConvert.SerializeObject(message, 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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Add a connection to the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string group, string connectionId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/groups/{group}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Remove a connection from the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string group, string connectionId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/groups/{group}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if there are any client connections connected for the given user. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/users/{userId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Close connections for the specific user. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections for the user. + /// + /// + /// The reason closing the client connection. + /// + /// + /// 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> CloseUserConnectionsWithHttpMessagesAsync(string endpoint, string hub, string userId, string apiVersion, IList excluded = default(IList), string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + tracingParameters.Add("hub", hub); + tracingParameters.Add("userId", userId); + tracingParameters.Add("excluded", excluded); + tracingParameters.Add("reason", reason); + tracingParameters.Add("apiVersion", apiVersion); + tracingParameters.Add("cancellationToken", cancellationToken); + ServiceClientTracing.Enter(_invocationId, this, "CloseUserConnections", tracingParameters); + } + // Construct URL + var _baseUrl = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/users/{userId}/:closeConnections"; + _url = _url.Replace("{Endpoint}", endpoint); + _url = _url.Replace("{hub}", System.Uri.EscapeDataString(hub)); + _url = _url.Replace("{userId}", System.Uri.EscapeDataString(userId)); + 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 (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("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; + // Send Request + if (_shouldTrace) + { + ServiceClientTracing.SendRequest(_invocationId, _httpRequest); + } + cancellationToken.ThrowIfCancellationRequested(); + _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Send content inside request body to the specific user. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// 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 endpoint, string hub, string userId, string apiVersion, string message, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + 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("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/users/{userId}/:send"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 = SafeJsonConvert.SerializeObject(message, 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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Add a user to the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string group, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/users/{userId}/groups/{group}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Remove a user from the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string group, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/users/{userId}/groups/{group}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Remove a user from all groups. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 endpoint, string hub, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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 (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/users/{userId}/groups"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Grant permission to the connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + /// + /// 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 endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/permissions/{permission}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Revoke permission for the connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + /// + /// 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 endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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 = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/permissions/{permission}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); + if (_shouldTrace) + { + ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); + } + HttpStatusCode _statusCode = _httpResponse.StatusCode; + cancellationToken.ThrowIfCancellationRequested(); + string _responseContent = null; + if ((int)_statusCode != 204) + { + var ex = new ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + /// + /// 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> HasPermissionWithHttpMessagesAsync(string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) + { + if (endpoint == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "endpoint"); + } + 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); + } + } + if (apiVersion == null) + { + throw new ValidationException(ValidationRules.CannotBeNull, "apiVersion"); + } + // Tracing + bool _shouldTrace = ServiceClientTracing.IsEnabled; + string _invocationId = null; + if (_shouldTrace) + { + _invocationId = ServiceClientTracing.NextInvocationId.ToString(); + Dictionary tracingParameters = new Dictionary(); + tracingParameters.Add("endpoint", endpoint); + 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, "HasPermission", tracingParameters); + } + // Construct URL + var _baseUrl = BaseUri; + var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "api/hubs/{hub}/permissions/{permission}/connections/{connectionId}"; + _url = _url.Replace("{Endpoint}", endpoint); + _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 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 ErrorDetailException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); + try + { + _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + ErrorDetail _errorBody = SafeJsonConvert.DeserializeObject(_responseContent, DeserializationSettings); + if (_errorBody != null) + { + ex.Body = _errorBody; + } + } + catch (JsonException) + { + // Ignore the exception + } + 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 HttpOperationHeaderResponse(); + _result.Request = _httpRequest; + _result.Response = _httpResponse; + try + { + _result.Headers = _httpResponse.GetHeadersAsJson().ToObject(JsonSerializer.Create(DeserializationSettings)); + } + catch (JsonException ex) + { + _httpRequest.Dispose(); + if (_httpResponse != null) + { + _httpResponse.Dispose(); + } + throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson().ToString(), ex); + } + if (_shouldTrace) + { + ServiceClientTracing.Exit(_invocationId, _result); + } + return _result; + } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClientExtensions.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClientExtensions.cs new file mode 100644 index 000000000000..0a085d17b895 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/AzureMessagingWebPubSubServiceClientExtensions.cs @@ -0,0 +1,1277 @@ +// +// 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 AzureMessagingWebPubSubServiceClient. + /// + public static partial class AzureMessagingWebPubSubServiceClientExtensions + { + /// + /// Generate token for the client to connect Azure Web PubSub service. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// User Id. + /// + /// + /// Roles that the connection with the generated token will have. + /// + /// + /// The expire time of the generated token. + /// + public static ClientTokenResponse GetClientAccessToken(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string apiVersion, string userId = default(string), IList roles = default(IList), int? minutesToExpire = 60) + { + return operations.GetClientAccessTokenAsync(endpoint, hub, apiVersion, userId, roles, minutesToExpire).GetAwaiter().GetResult(); + } + + /// + /// Generate token for the client to connect Azure Web PubSub service. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// User Id. + /// + /// + /// Roles that the connection with the generated token will have. + /// + /// + /// The expire time of the generated token. + /// + /// + /// The cancellation token. + /// + public static async Task GetClientAccessTokenAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string apiVersion, string userId = default(string), IList roles = default(IList), int? minutesToExpire = 60, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.GetClientAccessTokenWithHttpMessagesAsync(endpoint, hub, apiVersion, userId, roles, minutesToExpire, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Body; + } + } + + /// + /// Close the connections in the hub. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections in the hub. + /// + /// + /// The reason closing the client connection. + /// + public static CloseAllConnectionsHeaders CloseAllConnections(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string apiVersion, IList excluded = default(IList), string reason = default(string)) + { + return operations.CloseAllConnectionsAsync(endpoint, hub, apiVersion, excluded, reason).GetAwaiter().GetResult(); + } + + /// + /// Close the connections in the hub. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections in the hub. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The cancellation token. + /// + public static async Task CloseAllConnectionsAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string apiVersion, IList excluded = default(IList), string reason = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.CloseAllConnectionsWithHttpMessagesAsync(endpoint, hub, apiVersion, excluded, reason, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + public static SendToAllHeaders SendToAll(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string apiVersion, string message, IList excluded = default(IList)) + { + return operations.SendToAllAsync(endpoint, hub, apiVersion, message, excluded).GetAwaiter().GetResult(); + } + + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// The cancellation token. + /// + public static async Task SendToAllAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string apiVersion, string message, IList excluded = default(IList), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.SendToAllWithHttpMessagesAsync(endpoint, hub, apiVersion, message, excluded, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 ConnectionExistsHeaders ConnectionExists(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string connectionId, string apiVersion) + { + return operations.ConnectionExistsAsync(endpoint, hub, connectionId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string connectionId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.ConnectionExistsWithHttpMessagesAsync(endpoint, hub, connectionId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Close the client connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The reason closing the client connection. + /// + public static CloseConnectionHeaders CloseConnection(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string connectionId, string apiVersion, string reason = default(string)) + { + return operations.CloseConnectionAsync(endpoint, hub, connectionId, apiVersion, reason).GetAwaiter().GetResult(); + } + + /// + /// Close the client connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The cancellation token. + /// + public static async Task CloseConnectionAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string connectionId, string apiVersion, string reason = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.CloseConnectionWithHttpMessagesAsync(endpoint, hub, connectionId, apiVersion, reason, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + public static SendToConnectionHeaders SendToConnection(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string connectionId, string apiVersion, string message) + { + return operations.SendToConnectionAsync(endpoint, hub, connectionId, apiVersion, message).GetAwaiter().GetResult(); + } + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// The cancellation token. + /// + public static async Task SendToConnectionAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string connectionId, string apiVersion, string message, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.SendToConnectionWithHttpMessagesAsync(endpoint, hub, connectionId, apiVersion, message, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 GroupExistsHeaders GroupExists(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string apiVersion) + { + return operations.GroupExistsAsync(endpoint, hub, group, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.GroupExistsWithHttpMessagesAsync(endpoint, hub, group, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Close connections in the specific group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// Exclude these connectionIds when closing the connections in the group. + /// + /// + /// The reason closing the client connection. + /// + public static CloseGroupConnectionsHeaders CloseGroupConnections(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string apiVersion, IList excluded = default(IList), string reason = default(string)) + { + return operations.CloseGroupConnectionsAsync(endpoint, hub, group, apiVersion, excluded, reason).GetAwaiter().GetResult(); + } + + /// + /// Close connections in the specific group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// Exclude these connectionIds when closing the connections in the group. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The cancellation token. + /// + public static async Task CloseGroupConnectionsAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string apiVersion, IList excluded = default(IList), string reason = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.CloseGroupConnectionsWithHttpMessagesAsync(endpoint, hub, group, apiVersion, excluded, reason, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// Excluded connection Ids + /// + public static SendToGroupHeaders SendToGroup(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string apiVersion, string message, IList excluded = default(IList)) + { + return operations.SendToGroupAsync(endpoint, hub, group, apiVersion, message, excluded).GetAwaiter().GetResult(); + } + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// The cancellation token. + /// + public static async Task SendToGroupAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string apiVersion, string message, IList excluded = default(IList), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.SendToGroupWithHttpMessagesAsync(endpoint, hub, group, apiVersion, message, excluded, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Add a connection to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 AddConnectionToGroupHeaders AddConnectionToGroup(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string connectionId, string apiVersion) + { + return operations.AddConnectionToGroupAsync(endpoint, hub, group, connectionId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Add a connection to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string connectionId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.AddConnectionToGroupWithHttpMessagesAsync(endpoint, hub, group, connectionId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Remove a connection from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 RemoveConnectionFromGroupHeaders RemoveConnectionFromGroup(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string connectionId, string apiVersion) + { + return operations.RemoveConnectionFromGroupAsync(endpoint, hub, group, connectionId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Remove a connection from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string connectionId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.RemoveConnectionFromGroupWithHttpMessagesAsync(endpoint, hub, group, connectionId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Check if there are any client connections connected for the given user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 UserExistsHeaders UserExists(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion) + { + return operations.UserExistsAsync(endpoint, hub, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Check if there are any client connections connected for the given user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.UserExistsWithHttpMessagesAsync(endpoint, hub, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Close connections for the specific user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections for the user. + /// + /// + /// The reason closing the client connection. + /// + public static CloseUserConnectionsHeaders CloseUserConnections(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion, IList excluded = default(IList), string reason = default(string)) + { + return operations.CloseUserConnectionsAsync(endpoint, hub, userId, apiVersion, excluded, reason).GetAwaiter().GetResult(); + } + + /// + /// Close connections for the specific user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections for the user. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The cancellation token. + /// + public static async Task CloseUserConnectionsAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion, IList excluded = default(IList), string reason = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.CloseUserConnectionsWithHttpMessagesAsync(endpoint, hub, userId, apiVersion, excluded, reason, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Send content inside request body to the specific user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + public static SendToUserHeaders SendToUser(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion, string message) + { + return operations.SendToUserAsync(endpoint, hub, userId, apiVersion, message).GetAwaiter().GetResult(); + } + + /// + /// Send content inside request body to the specific user. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and only + /// contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// The cancellation token. + /// + public static async Task SendToUserAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion, string message, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.SendToUserWithHttpMessagesAsync(endpoint, hub, userId, apiVersion, message, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Add a user to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 AddUserToGroupHeaders AddUserToGroup(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string userId, string apiVersion) + { + return operations.AddUserToGroupAsync(endpoint, hub, group, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Add a user to the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string userId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.AddUserToGroupWithHttpMessagesAsync(endpoint, hub, group, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Remove a user from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 RemoveUserFromGroupHeaders RemoveUserFromGroup(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string userId, string apiVersion) + { + return operations.RemoveUserFromGroupAsync(endpoint, hub, group, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Remove a user from the target group. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string group, string userId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.RemoveUserFromGroupWithHttpMessagesAsync(endpoint, hub, group, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Remove a user from all groups. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 RemoveUserFromAllGroupsHeaders RemoveUserFromAllGroups(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion) + { + return operations.RemoveUserFromAllGroupsAsync(endpoint, hub, userId, apiVersion).GetAwaiter().GetResult(); + } + + /// + /// Remove a user from all groups. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string userId, string apiVersion, CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.RemoveUserFromAllGroupsWithHttpMessagesAsync(endpoint, hub, userId, apiVersion, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Grant permission to the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + public static GrantPermissionHeaders GrantPermission(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string)) + { + return operations.GrantPermissionAsync(endpoint, hub, permission, connectionId, apiVersion, targetName).GetAwaiter().GetResult(); + } + + /// + /// Grant permission to the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + /// + /// The cancellation token. + /// + public static async Task GrantPermissionAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.GrantPermissionWithHttpMessagesAsync(endpoint, hub, permission, connectionId, apiVersion, targetName, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Revoke permission for the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + public static RevokePermissionHeaders RevokePermission(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string)) + { + return operations.RevokePermissionAsync(endpoint, hub, permission, connectionId, apiVersion, targetName).GetAwaiter().GetResult(); + } + + /// + /// Revoke permission for the connection. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + /// + /// The cancellation token. + /// + public static async Task RevokePermissionAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.RevokePermissionWithHttpMessagesAsync(endpoint, hub, permission, connectionId, apiVersion, targetName, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + public static HasPermissionHeaders HasPermission(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string)) + { + return operations.HasPermissionAsync(endpoint, hub, permission, connectionId, apiVersion, targetName).GetAwaiter().GetResult(); + } + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// The operations group for this extension method. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter standing + /// for the group name. + /// + /// + /// The cancellation token. + /// + public static async Task HasPermissionAsync(this IAzureMessagingWebPubSubServiceClient operations, string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), CancellationToken cancellationToken = default(CancellationToken)) + { + using (var _result = await operations.HasPermissionWithHttpMessagesAsync(endpoint, hub, permission, connectionId, apiVersion, targetName, null, cancellationToken).ConfigureAwait(false)) + { + return _result.Headers; + } + } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApiClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApiClient.cs deleted file mode 100644 index 643451170521..000000000000 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/HealthApiClient.cs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.Messaging.WebPubSub -{ - /// The HealthApi service client. - internal partial class HealthApiClient - { - private readonly HttpPipeline _pipeline; - private readonly string _endpoint; - private readonly string _apiVersion; - internal ClientDiagnostics ClientDiagnostics { get; } - /// The HTTP pipeline for sending and receiving REST requests and responses. - public virtual HttpPipeline Pipeline => _pipeline; - - /// Initializes a new instance of HealthApiClient for mocking. - protected HealthApiClient() - { - } - - /// Initializes a new instance of HealthApiClient. - /// HTTP or HTTPS endpoint for the Web PubSub service instance. - /// The options for configuring the client. - /// is null. - public HealthApiClient(string endpoint, WebPubSubServiceClientOptions options = null) - { - Argument.AssertNotNull(endpoint, nameof(endpoint)); - options ??= new WebPubSubServiceClientOptions(); - - ClientDiagnostics = new ClientDiagnostics(options); - _pipeline = HttpPipelineBuilder.Build(options, Array.Empty(), Array.Empty(), new ResponseClassifier()); - _endpoint = endpoint; - _apiVersion = options.Version; - } - - /// Get service health status. - /// The request context, which can override default behaviors on the request on a per-call basis. -#pragma warning disable AZC0002 - public virtual async Task GetServiceStatusAsync(RequestContext context = null) -#pragma warning restore AZC0002 - { - using var scope = ClientDiagnostics.CreateScope("HealthApiClient.GetServiceStatus"); - scope.Start(); - try - { - using HttpMessage message = CreateGetServiceStatusRequest(context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Get service health status. - /// The request context, which can override default behaviors on the request on a per-call basis. -#pragma warning disable AZC0002 - public virtual Response GetServiceStatus(RequestContext context = null) -#pragma warning restore AZC0002 - { - using var scope = ClientDiagnostics.CreateScope("HealthApiClient.GetServiceStatus"); - scope.Start(); - try - { - using HttpMessage message = CreateGetServiceStatusRequest(context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - internal HttpMessage CreateGetServiceStatusRequest(RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Head; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/health", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - message.ResponseClassifier = ResponseClassifier200.Instance; - return message; - } - - private sealed class ResponseClassifier200 : ResponseClassifier - { - private static ResponseClassifier _instance; - public static ResponseClassifier Instance => _instance ??= new ResponseClassifier200(); - public override bool IsErrorResponse(HttpMessage message) - { - return message.Response.Status switch - { - 200 => false, - _ => true - }; - } - } - } -} 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..685a035fc3e1 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/IAzureMessagingWebPubSubServiceClient.cs @@ -0,0 +1,614 @@ +// +// 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 Newtonsoft.Json; + using System.Collections; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + /// + /// + public partial interface IAzureMessagingWebPubSubServiceClient : System.IDisposable + { + /// + /// The base URI of the service. + /// + + /// + /// Gets or sets json serialization settings. + /// + JsonSerializerSettings SerializationSettings { get; } + + /// + /// Gets or sets json deserialization settings. + /// + JsonSerializerSettings DeserializationSettings { get; } + + + /// + /// Generate token for the client to connect Azure Web PubSub service. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// User Id. + /// + /// + /// Roles that the connection with the generated token will have. + /// + /// + /// The expire time of the generated token. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> GetClientAccessTokenWithHttpMessagesAsync(string endpoint, string hub, string apiVersion, string userId = default(string), IList roles = default(IList), int? minutesToExpire = 60, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Close the connections in the hub. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections in the + /// hub. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> CloseAllConnectionsWithHttpMessagesAsync(string endpoint, string hub, string apiVersion, IList excluded = default(IList), string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Broadcast content inside request body to all the connected client + /// connections. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// Excluded connection Ids. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> SendToAllWithHttpMessagesAsync(string endpoint, string hub, string apiVersion, string message, IList excluded = default(IList), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Check if the connection with the given connectionId exists. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> ConnectionExistsWithHttpMessagesAsync(string endpoint, string hub, string connectionId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Close the client connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// Target connection Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> CloseConnectionWithHttpMessagesAsync(string endpoint, string hub, string connectionId, string apiVersion, string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Send content inside request body to the specific connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> SendToConnectionWithHttpMessagesAsync(string endpoint, string hub, string connectionId, string apiVersion, string message, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Check if there are any client connections inside the given group + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> GroupExistsWithHttpMessagesAsync(string endpoint, string hub, string group, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Close connections in the specific group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// Exclude these connectionIds when closing the connections in the + /// group. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> CloseGroupConnectionsWithHttpMessagesAsync(string endpoint, string hub, string group, string apiVersion, IList excluded = default(IList), string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Send content inside request body to a group of connections. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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 payload body. + /// + /// + /// Excluded connection Ids + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> SendToGroupWithHttpMessagesAsync(string endpoint, string hub, string group, string apiVersion, string message, IList excluded = default(IList), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Add a connection to the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> AddConnectionToGroupWithHttpMessagesAsync(string endpoint, string hub, string group, string connectionId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Remove a connection from the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> RemoveConnectionFromGroupWithHttpMessagesAsync(string endpoint, string hub, string group, string connectionId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Check if there are any client connections connected for the given + /// user. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> UserExistsWithHttpMessagesAsync(string endpoint, string hub, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Close connections for the specific user. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// Exclude these connectionIds when closing the connections for the + /// user. + /// + /// + /// The reason closing the client connection. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> CloseUserConnectionsWithHttpMessagesAsync(string endpoint, string hub, string userId, string apiVersion, IList excluded = default(IList), string reason = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Send content inside request body to the specific user. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// Target hub name, which should start with alphabetic characters and + /// only contain alpha-numeric characters or underscore. + /// + /// + /// The user Id. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The payload body. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> SendToUserWithHttpMessagesAsync(string endpoint, string hub, string userId, string apiVersion, string message, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Add a user to the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> AddUserToGroupWithHttpMessagesAsync(string endpoint, string hub, string group, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Remove a user from the target group. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> RemoveUserFromGroupWithHttpMessagesAsync(string endpoint, string hub, string group, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Remove a user from all groups. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + Task> RemoveUserFromAllGroupsWithHttpMessagesAsync(string endpoint, string hub, string userId, string apiVersion, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Grant permission to the connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter + /// standing for the group name. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> GrantPermissionWithHttpMessagesAsync(string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Revoke permission for the connection. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter + /// standing for the group name. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> RevokePermissionWithHttpMessagesAsync(string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Check if a connection has permission to the specified action. + /// + /// + /// HTTP or HTTPS endpoint for the Web PubSub service instance. + /// + /// + /// 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. + /// + /// + /// The version of the REST APIs. + /// + /// + /// The meaning of the target depends on the specific permission. For + /// joinLeaveGroup and sendToGroup, targetName is a required parameter + /// standing for the group name. + /// + /// + /// The headers that will be added to request. + /// + /// + /// The cancellation token. + /// + Task> HasPermissionWithHttpMessagesAsync(string endpoint, string hub, string permission, string connectionId, string apiVersion, string targetName = default(string), Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)); + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/AddConnectionToGroupHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/AddConnectionToGroupHeaders.cs new file mode 100644 index 000000000000..25f4168acd47 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/AddConnectionToGroupHeaders.cs @@ -0,0 +1,51 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for AddConnectionToGroup operation. + /// + public partial class AddConnectionToGroupHeaders + { + /// + /// Initializes a new instance of the AddConnectionToGroupHeaders + /// class. + /// + public AddConnectionToGroupHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the AddConnectionToGroupHeaders + /// class. + /// + public AddConnectionToGroupHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/AddUserToGroupHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/AddUserToGroupHeaders.cs new file mode 100644 index 000000000000..a562549543b2 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/AddUserToGroupHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for AddUserToGroup operation. + /// + public partial class AddUserToGroupHeaders + { + /// + /// Initializes a new instance of the AddUserToGroupHeaders class. + /// + public AddUserToGroupHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the AddUserToGroupHeaders class. + /// + public AddUserToGroupHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ClientTokenResponse.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ClientTokenResponse.cs new file mode 100644 index 000000000000..0aeccb549665 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ClientTokenResponse.cs @@ -0,0 +1,53 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// The response object containing the token for the client + /// + public partial class ClientTokenResponse + { + /// + /// Initializes a new instance of the ClientTokenResponse class. + /// + public ClientTokenResponse() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the ClientTokenResponse class. + /// + /// The token value for the WebSocket client to + /// connect to the service + public ClientTokenResponse(string token = default(string)) + { + Token = token; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets or sets the token value for the WebSocket client to connect to + /// the service + /// + [JsonProperty(PropertyName = "token")] + public string Token { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseAllConnectionsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseAllConnectionsHeaders.cs new file mode 100644 index 000000000000..7dcba3a81111 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseAllConnectionsHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for CloseAllConnections operation. + /// + public partial class CloseAllConnectionsHeaders + { + /// + /// Initializes a new instance of the CloseAllConnectionsHeaders class. + /// + public CloseAllConnectionsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the CloseAllConnectionsHeaders class. + /// + public CloseAllConnectionsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseConnectionHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseConnectionHeaders.cs new file mode 100644 index 000000000000..4e2f82c8738a --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseConnectionHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for CloseConnection operation. + /// + public partial class CloseConnectionHeaders + { + /// + /// Initializes a new instance of the CloseConnectionHeaders class. + /// + public CloseConnectionHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the CloseConnectionHeaders class. + /// + public CloseConnectionHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseGroupConnectionsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseGroupConnectionsHeaders.cs new file mode 100644 index 000000000000..2b9900e42f69 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseGroupConnectionsHeaders.cs @@ -0,0 +1,51 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for CloseGroupConnections operation. + /// + public partial class CloseGroupConnectionsHeaders + { + /// + /// Initializes a new instance of the CloseGroupConnectionsHeaders + /// class. + /// + public CloseGroupConnectionsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the CloseGroupConnectionsHeaders + /// class. + /// + public CloseGroupConnectionsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseUserConnectionsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseUserConnectionsHeaders.cs new file mode 100644 index 000000000000..70dfb81161f2 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/CloseUserConnectionsHeaders.cs @@ -0,0 +1,51 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for CloseUserConnections operation. + /// + public partial class CloseUserConnectionsHeaders + { + /// + /// Initializes a new instance of the CloseUserConnectionsHeaders + /// class. + /// + public CloseUserConnectionsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the CloseUserConnectionsHeaders + /// class. + /// + public CloseUserConnectionsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ConnectionExistsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ConnectionExistsHeaders.cs new file mode 100644 index 000000000000..e97c80d17703 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ConnectionExistsHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for ConnectionExists operation. + /// + public partial class ConnectionExistsHeaders + { + /// + /// Initializes a new instance of the ConnectionExistsHeaders class. + /// + public ConnectionExistsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the ConnectionExistsHeaders class. + /// + public ConnectionExistsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ErrorDetail.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ErrorDetail.cs new file mode 100644 index 000000000000..e252acc6c934 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ErrorDetail.cs @@ -0,0 +1,87 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Collections; + using System.Collections.Generic; + using System.Linq; + + /// + /// The error object. + /// + public partial class ErrorDetail + { + /// + /// Initializes a new instance of the ErrorDetail class. + /// + public ErrorDetail() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the ErrorDetail class. + /// + /// One of a server-defined set of error + /// codes. + /// A human-readable representation of the + /// error. + /// The target of the error. + /// An array of details about specific errors + /// that led to this reported error. + public ErrorDetail(string code = default(string), string message = default(string), string target = default(string), IList details = default(IList), InnerError inner = default(InnerError)) + { + Code = code; + Message = message; + Target = target; + Details = details; + Inner = inner; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets or sets one of a server-defined set of error codes. + /// + [JsonProperty(PropertyName = "code")] + public string Code { get; set; } + + /// + /// Gets or sets a human-readable representation of the error. + /// + [JsonProperty(PropertyName = "message")] + public string Message { get; set; } + + /// + /// Gets or sets the target of the error. + /// + [JsonProperty(PropertyName = "target")] + public string Target { get; set; } + + /// + /// Gets or sets an array of details about specific errors that led to + /// this reported error. + /// + [JsonProperty(PropertyName = "details")] + public IList Details { get; set; } + + /// + /// + [JsonProperty(PropertyName = "inner")] + public InnerError Inner { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ErrorDetailException.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ErrorDetailException.cs new file mode 100644 index 000000000000..40bb458e45c9 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/ErrorDetailException.cs @@ -0,0 +1,61 @@ +// +// 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 +{ + using Microsoft.Rest; + + /// + /// Exception thrown for an invalid response with ErrorDetail information. + /// + public partial class ErrorDetailException : RestException + { + /// + /// Gets information about the associated HTTP request. + /// + public HttpRequestMessageWrapper Request { get; set; } + + /// + /// Gets information about the associated HTTP response. + /// + public HttpResponseMessageWrapper Response { get; set; } + + /// + /// Gets or sets the body object. + /// + public ErrorDetail Body { get; set; } + + /// + /// Initializes a new instance of the ErrorDetailException class. + /// + public ErrorDetailException() + { + } + + /// + /// Initializes a new instance of the ErrorDetailException class. + /// + /// The exception message. + public ErrorDetailException(string message) + : this(message, null) + { + } + + /// + /// Initializes a new instance of the ErrorDetailException class. + /// + /// The exception message. + /// Inner exception. + public ErrorDetailException(string message, System.Exception innerException) + : base(message, innerException) + { + } + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GetClientAccessTokenHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GetClientAccessTokenHeaders.cs new file mode 100644 index 000000000000..dc00c080516c --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GetClientAccessTokenHeaders.cs @@ -0,0 +1,51 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for GetClientAccessToken operation. + /// + public partial class GetClientAccessTokenHeaders + { + /// + /// Initializes a new instance of the GetClientAccessTokenHeaders + /// class. + /// + public GetClientAccessTokenHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the GetClientAccessTokenHeaders + /// class. + /// + public GetClientAccessTokenHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GrantPermissionHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GrantPermissionHeaders.cs new file mode 100644 index 000000000000..fc946fa707d2 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GrantPermissionHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for GrantPermission operation. + /// + public partial class GrantPermissionHeaders + { + /// + /// Initializes a new instance of the GrantPermissionHeaders class. + /// + public GrantPermissionHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the GrantPermissionHeaders class. + /// + public GrantPermissionHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GroupExistsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GroupExistsHeaders.cs new file mode 100644 index 000000000000..f0fb419c2ab6 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/GroupExistsHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for GroupExists operation. + /// + public partial class GroupExistsHeaders + { + /// + /// Initializes a new instance of the GroupExistsHeaders class. + /// + public GroupExistsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the GroupExistsHeaders class. + /// + public GroupExistsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/HasPermissionHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/HasPermissionHeaders.cs new file mode 100644 index 000000000000..a1357d67ea17 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/HasPermissionHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for HasPermission operation. + /// + public partial class HasPermissionHeaders + { + /// + /// Initializes a new instance of the HasPermissionHeaders class. + /// + public HasPermissionHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the HasPermissionHeaders class. + /// + public HasPermissionHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/InnerError.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/InnerError.cs new file mode 100644 index 000000000000..3509e0a6e791 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/InnerError.cs @@ -0,0 +1,56 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + public partial class InnerError + { + /// + /// Initializes a new instance of the InnerError class. + /// + public InnerError() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the InnerError class. + /// + /// A more specific error code than was provided by + /// the containing error. + public InnerError(string code = default(string), InnerError inner = default(InnerError)) + { + Code = code; + Inner = inner; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// Gets or sets a more specific error code than was provided by the + /// containing error. + /// + [JsonProperty(PropertyName = "code")] + public string Code { get; set; } + + /// + /// + [JsonProperty(PropertyName = "inner")] + public InnerError Inner { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveConnectionFromGroupHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveConnectionFromGroupHeaders.cs new file mode 100644 index 000000000000..3a63c8cc877f --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveConnectionFromGroupHeaders.cs @@ -0,0 +1,51 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for RemoveConnectionFromGroup operation. + /// + public partial class RemoveConnectionFromGroupHeaders + { + /// + /// Initializes a new instance of the RemoveConnectionFromGroupHeaders + /// class. + /// + public RemoveConnectionFromGroupHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the RemoveConnectionFromGroupHeaders + /// class. + /// + public RemoveConnectionFromGroupHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveUserFromAllGroupsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveUserFromAllGroupsHeaders.cs new file mode 100644 index 000000000000..4ce40c636db6 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveUserFromAllGroupsHeaders.cs @@ -0,0 +1,51 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for RemoveUserFromAllGroups operation. + /// + public partial class RemoveUserFromAllGroupsHeaders + { + /// + /// Initializes a new instance of the RemoveUserFromAllGroupsHeaders + /// class. + /// + public RemoveUserFromAllGroupsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the RemoveUserFromAllGroupsHeaders + /// class. + /// + public RemoveUserFromAllGroupsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveUserFromGroupHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveUserFromGroupHeaders.cs new file mode 100644 index 000000000000..d1b10af00fea --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RemoveUserFromGroupHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for RemoveUserFromGroup operation. + /// + public partial class RemoveUserFromGroupHeaders + { + /// + /// Initializes a new instance of the RemoveUserFromGroupHeaders class. + /// + public RemoveUserFromGroupHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the RemoveUserFromGroupHeaders class. + /// + public RemoveUserFromGroupHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RevokePermissionHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RevokePermissionHeaders.cs new file mode 100644 index 000000000000..272c1ee5aad8 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/RevokePermissionHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for RevokePermission operation. + /// + public partial class RevokePermissionHeaders + { + /// + /// Initializes a new instance of the RevokePermissionHeaders class. + /// + public RevokePermissionHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the RevokePermissionHeaders class. + /// + public RevokePermissionHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToAllHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToAllHeaders.cs new file mode 100644 index 000000000000..6e1c02972c86 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToAllHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for SendToAll operation. + /// + public partial class SendToAllHeaders + { + /// + /// Initializes a new instance of the SendToAllHeaders class. + /// + public SendToAllHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the SendToAllHeaders class. + /// + public SendToAllHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToConnectionHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToConnectionHeaders.cs new file mode 100644 index 000000000000..c6cad3bba301 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToConnectionHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for SendToConnection operation. + /// + public partial class SendToConnectionHeaders + { + /// + /// Initializes a new instance of the SendToConnectionHeaders class. + /// + public SendToConnectionHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the SendToConnectionHeaders class. + /// + public SendToConnectionHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToGroupHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToGroupHeaders.cs new file mode 100644 index 000000000000..5dc2ac73721a --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToGroupHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for SendToGroup operation. + /// + public partial class SendToGroupHeaders + { + /// + /// Initializes a new instance of the SendToGroupHeaders class. + /// + public SendToGroupHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the SendToGroupHeaders class. + /// + public SendToGroupHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToUserHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToUserHeaders.cs new file mode 100644 index 000000000000..d1541deec02f --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/SendToUserHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for SendToUser operation. + /// + public partial class SendToUserHeaders + { + /// + /// Initializes a new instance of the SendToUserHeaders class. + /// + public SendToUserHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the SendToUserHeaders class. + /// + public SendToUserHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/UserExistsHeaders.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/UserExistsHeaders.cs new file mode 100644 index 000000000000..e6379f802e4f --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/Models/UserExistsHeaders.cs @@ -0,0 +1,49 @@ +// +// 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 +{ + using Newtonsoft.Json; + using System.Linq; + + /// + /// Defines headers for UserExists operation. + /// + public partial class UserExistsHeaders + { + /// + /// Initializes a new instance of the UserExistsHeaders class. + /// + public UserExistsHeaders() + { + CustomInit(); + } + + /// + /// Initializes a new instance of the UserExistsHeaders class. + /// + public UserExistsHeaders(string errorCode = default(string)) + { + ErrorCode = errorCode; + CustomInit(); + } + + /// + /// An initialization method that performs custom operations like setting defaults + /// + partial void CustomInit(); + + /// + /// + [JsonProperty(PropertyName = "x-ms-error-code")] + public string ErrorCode { get; set; } + + } +} 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..19aac80fffa6 --- /dev/null +++ b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/SdkInfo_AzureMessagingWebPubSubServiceClient.cs @@ -0,0 +1,46 @@ + +// +// 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", "AddConnectionToGroup", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "AddUserToGroup", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "CloseAllConnections", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "CloseConnection", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "CloseGroupConnections", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "CloseUserConnections", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "ConnectionExists", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "GetClientAccessToken", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "GrantPermission", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "GroupExists", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "HasPermission", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "RemoveConnectionFromGroup", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "RemoveUserFromAllGroups", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "RemoveUserFromGroup", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "RevokePermission", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "SendToAll", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "SendToConnection", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "SendToGroup", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "SendToUser", "2021-10-01"), + new Tuple("AzureMessagingWebPubSubServiceClient", "UserExists", "2021-10-01"), + }.AsEnumerable(); + } + } + } +} diff --git a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubServiceClient.cs b/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubServiceClient.cs deleted file mode 100644 index a0176e038bad..000000000000 --- a/sdk/webpubsub/Azure.Messaging.WebPubSub/src/Generated/WebPubSubServiceClient.cs +++ /dev/null @@ -1,2114 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.Messaging.WebPubSub -{ - /// The WebPubSubService service client. - public partial class WebPubSubServiceClient - { - private readonly HttpPipeline _pipeline; - private readonly string _endpoint; - private readonly string _hub; - private readonly string _apiVersion; - internal ClientDiagnostics ClientDiagnostics { get; } - /// The HTTP pipeline for sending and receiving REST requests and responses. - public virtual HttpPipeline Pipeline => _pipeline; - - /// Initializes a new instance of WebPubSubServiceClient for mocking. - protected WebPubSubServiceClient() - { - } - - /// Generate token for the client to connect Azure Web PubSub service. - /// User Id. - /// Roles that the connection with the generated token will have. - /// The expire time of the generated token. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// - /// Schema for Response Body: - /// { - /// token: string - /// } - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task GenerateClientTokenImplAsync(string userId = null, IEnumerable role = null, int? minutesToExpire = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.GenerateClientTokenImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateGenerateClientTokenImplRequest(userId, role, minutesToExpire, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Generate token for the client to connect Azure Web PubSub service. - /// User Id. - /// Roles that the connection with the generated token will have. - /// The expire time of the generated token. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// - /// Schema for Response Body: - /// { - /// token: string - /// } - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response GenerateClientTokenImpl(string userId = null, IEnumerable role = null, int? minutesToExpire = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.GenerateClientTokenImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateGenerateClientTokenImplRequest(userId, role, minutesToExpire, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close the connections in the hub. - /// Exclude these connectionIds when closing the connections in the hub. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task CloseAllConnectionsAsync(IEnumerable excluded = null, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseAllConnections"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseAllConnectionsRequest(excluded, reason, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close the connections in the hub. - /// Exclude these connectionIds when closing the connections in the hub. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response CloseAllConnections(IEnumerable excluded = null, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseAllConnections"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseAllConnectionsRequest(excluded, reason, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Broadcast content inside request body to all the connected client connections. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// Excluded connection Ids. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task SendToAllAsync(RequestContent content, ContentType contentType, IEnumerable excluded = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToAll"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToAllRequest(content, contentType, excluded, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Broadcast content inside request body to all the connected client connections. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// Excluded connection Ids. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response SendToAll(RequestContent content, ContentType contentType, IEnumerable excluded = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToAll"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToAllRequest(content, contentType, excluded, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if the connection with the given connectionId exists. - /// The connection Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task ConnectionExistsImplAsync(string connectionId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.ConnectionExistsImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateConnectionExistsImplRequest(connectionId, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if the connection with the given connectionId exists. - /// The connection Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response ConnectionExistsImpl(string connectionId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.ConnectionExistsImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateConnectionExistsImplRequest(connectionId, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close the client connection. - /// Target connection Id. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task CloseConnectionAsync(string connectionId, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseConnection"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseConnectionRequest(connectionId, reason, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close the client connection. - /// Target connection Id. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response CloseConnection(string connectionId, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseConnection"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseConnectionRequest(connectionId, reason, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Send content inside request body to the specific connection. - /// The connection Id. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task SendToConnectionAsync(string connectionId, RequestContent content, ContentType contentType, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(connectionId, nameof(connectionId)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToConnection"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToConnectionRequest(connectionId, content, contentType, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Send content inside request body to the specific connection. - /// The connection Id. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response SendToConnection(string connectionId, RequestContent content, ContentType contentType, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(connectionId, nameof(connectionId)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToConnection"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToConnectionRequest(connectionId, content, contentType, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if there are any client connections inside the given group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task GroupExistsImplAsync(string group, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.GroupExistsImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateGroupExistsImplRequest(group, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if there are any client connections inside the given group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response GroupExistsImpl(string group, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.GroupExistsImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateGroupExistsImplRequest(group, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close connections in the specific group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// Exclude these connectionIds when closing the connections in the group. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task CloseGroupConnectionsAsync(string group, IEnumerable excluded = null, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseGroupConnections"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseGroupConnectionsRequest(group, excluded, reason, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close connections in the specific group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// Exclude these connectionIds when closing the connections in the group. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response CloseGroupConnections(string group, IEnumerable excluded = null, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseGroupConnections"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseGroupConnectionsRequest(group, excluded, reason, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Send content inside request body to a group of connections. - /// Target group name, which length should be greater than 0 and less than 1025. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// Excluded connection Ids. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task SendToGroupAsync(string group, RequestContent content, ContentType contentType, IEnumerable excluded = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToGroup"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToGroupRequest(group, content, contentType, excluded, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Send content inside request body to a group of connections. - /// Target group name, which length should be greater than 0 and less than 1025. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// Excluded connection Ids. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response SendToGroup(string group, RequestContent content, ContentType contentType, IEnumerable excluded = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToGroup"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToGroupRequest(group, content, contentType, excluded, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Add a connection to the target group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// Target connection Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task AddConnectionToGroupAsync(string group, string connectionId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.AddConnectionToGroup"); - scope.Start(); - try - { - using HttpMessage message = CreateAddConnectionToGroupRequest(group, connectionId, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Add a connection to the target group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// Target connection Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response AddConnectionToGroup(string group, string connectionId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.AddConnectionToGroup"); - scope.Start(); - try - { - using HttpMessage message = CreateAddConnectionToGroupRequest(group, connectionId, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Remove a connection from the target group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// Target connection Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task RemoveConnectionFromGroupAsync(string group, string connectionId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.RemoveConnectionFromGroup"); - scope.Start(); - try - { - using HttpMessage message = CreateRemoveConnectionFromGroupRequest(group, connectionId, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Remove a connection from the target group. - /// Target group name, which length should be greater than 0 and less than 1025. - /// Target connection Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response RemoveConnectionFromGroup(string group, string connectionId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(group, nameof(group)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.RemoveConnectionFromGroup"); - scope.Start(); - try - { - using HttpMessage message = CreateRemoveConnectionFromGroupRequest(group, connectionId, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if there are any client connections connected for the given user. - /// Target user Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task UserExistsImplAsync(string userId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.UserExistsImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateUserExistsImplRequest(userId, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if there are any client connections connected for the given user. - /// Target user Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response UserExistsImpl(string userId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.UserExistsImpl"); - scope.Start(); - try - { - using HttpMessage message = CreateUserExistsImplRequest(userId, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close connections for the specific user. - /// The user Id. - /// Exclude these connectionIds when closing the connections for the user. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task CloseUserConnectionsAsync(string userId, IEnumerable excluded = null, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseUserConnections"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseUserConnectionsRequest(userId, excluded, reason, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Close connections for the specific user. - /// The user Id. - /// Exclude these connectionIds when closing the connections for the user. - /// The reason closing the client connection. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response CloseUserConnections(string userId, IEnumerable excluded = null, string reason = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CloseUserConnections"); - scope.Start(); - try - { - using HttpMessage message = CreateCloseUserConnectionsRequest(userId, excluded, reason, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Send content inside request body to the specific user. - /// The user Id. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task SendToUserAsync(string userId, RequestContent content, ContentType contentType, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToUser"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToUserRequest(userId, content, contentType, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Send content inside request body to the specific user. - /// The user Id. - /// The content to send as the body of the request. - /// Upload file type. Allowed values: "application/json" | "application/octet-stream". - /// The request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response SendToUser(string userId, RequestContent content, ContentType contentType, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - Argument.AssertNotNull(content, nameof(content)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.SendToUser"); - scope.Start(); - try - { - using HttpMessage message = CreateSendToUserRequest(userId, content, contentType, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Remove a user from all groups. - /// Target user Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual async Task RemoveUserFromAllGroupsAsync(string userId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.RemoveUserFromAllGroups"); - scope.Start(); - try - { - using HttpMessage message = CreateRemoveUserFromAllGroupsRequest(userId, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Remove a user from all groups. - /// Target user Id. - /// The request context, which can override default behaviors on the request on a per-call basis. - /// is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - public virtual Response RemoveUserFromAllGroups(string userId, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(userId, nameof(userId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.RemoveUserFromAllGroups"); - scope.Start(); - try - { - using HttpMessage message = CreateRemoveUserFromAllGroupsRequest(userId, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Grant permission to the connection. - /// The permission: current supported actions are joinLeaveGroup and sendToGroup. Allowed values: "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 request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task GrantPermissionAsync(string permission, string connectionId, string targetName = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(permission, nameof(permission)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.GrantPermission"); - scope.Start(); - try - { - using HttpMessage message = CreateGrantPermissionRequest(permission, connectionId, targetName, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Grant permission to the connection. - /// The permission: current supported actions are joinLeaveGroup and sendToGroup. Allowed values: "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 request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response GrantPermission(string permission, string connectionId, string targetName = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(permission, nameof(permission)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.GrantPermission"); - scope.Start(); - try - { - using HttpMessage message = CreateGrantPermissionRequest(permission, connectionId, targetName, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Revoke permission for the connection. - /// The permission: current supported actions are joinLeaveGroup and sendToGroup. Allowed values: "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 request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task RevokePermissionAsync(string permission, string connectionId, string targetName = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(permission, nameof(permission)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.RevokePermission"); - scope.Start(); - try - { - using HttpMessage message = CreateRevokePermissionRequest(permission, connectionId, targetName, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Revoke permission for the connection. - /// The permission: current supported actions are joinLeaveGroup and sendToGroup. Allowed values: "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 request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response RevokePermission(string permission, string connectionId, string targetName = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(permission, nameof(permission)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.RevokePermission"); - scope.Start(); - try - { - using HttpMessage message = CreateRevokePermissionRequest(permission, connectionId, targetName, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if a connection has permission to the specified action. - /// The permission: current supported actions are joinLeaveGroup and sendToGroup. Allowed values: "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 request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual async Task CheckPermissionAsync(string permission, string connectionId, string targetName = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(permission, nameof(permission)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CheckPermission"); - scope.Start(); - try - { - using HttpMessage message = CreateCheckPermissionRequest(permission, connectionId, targetName, context); - return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// Check if a connection has permission to the specified action. - /// The permission: current supported actions are joinLeaveGroup and sendToGroup. Allowed values: "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 request context, which can override default behaviors on the request on a per-call basis. - /// or is null. - /// - /// Schema for Response Error: - /// { - /// code: string, - /// message: string, - /// target: string, - /// details: [ErrorDetail], - /// inner: { - /// code: string, - /// inner: InnerError - /// } - /// } - /// - /// - /// -#pragma warning disable AZC0002 - internal virtual Response CheckPermission(string permission, string connectionId, string targetName = null, RequestContext context = null) -#pragma warning restore AZC0002 - { - Argument.AssertNotNull(permission, nameof(permission)); - Argument.AssertNotNull(connectionId, nameof(connectionId)); - - using var scope = ClientDiagnostics.CreateScope("WebPubSubServiceClient.CheckPermission"); - scope.Start(); - try - { - using HttpMessage message = CreateCheckPermissionRequest(permission, connectionId, targetName, context); - return _pipeline.ProcessMessage(message, context); - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - internal HttpMessage CreateGenerateClientTokenImplRequest(string userId, IEnumerable role, int? minutesToExpire, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/:generateToken", false); - if (userId != null) - { - uri.AppendQuery("userId", userId, true); - } - if (role != null) - { - foreach (var param in role) - { - uri.AppendQuery("role", param, true); - } - } - if (minutesToExpire != null) - { - uri.AppendQuery("minutesToExpire", minutesToExpire.Value, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200.Instance; - return message; - } - - internal HttpMessage CreateCloseAllConnectionsRequest(IEnumerable excluded, string reason, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/:closeConnections", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - if (reason != null) - { - uri.AppendQuery("reason", reason, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateSendToAllRequest(RequestContent content, ContentType contentType, IEnumerable excluded, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/:send", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", contentType.ToString()); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateSendToAllRequest(RequestContent content, IEnumerable excluded, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/:send", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", "text/plain"); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateConnectionExistsImplRequest(string connectionId, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Head; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200404.Instance; - return message; - } - - internal HttpMessage CreateCloseConnectionRequest(string connectionId, string reason, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - if (reason != null) - { - uri.AppendQuery("reason", reason, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateSendToConnectionRequest(string connectionId, RequestContent content, ContentType contentType, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - uri.AppendPath("/:send", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", contentType.ToString()); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateSendToConnectionRequest(string connectionId, RequestContent content, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - uri.AppendPath("/:send", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", "text/plain"); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateGroupExistsImplRequest(string group, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Head; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200404.Instance; - return message; - } - - internal HttpMessage CreateCloseGroupConnectionsRequest(string group, IEnumerable excluded, string reason, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendPath("/:closeConnections", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - if (reason != null) - { - uri.AppendQuery("reason", reason, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateSendToGroupRequest(string group, RequestContent content, ContentType contentType, IEnumerable excluded, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendPath("/:send", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", contentType.ToString()); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateSendToGroupRequest(string group, RequestContent content, IEnumerable excluded, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendPath("/:send", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", "text/plain"); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateAddConnectionToGroupRequest(string group, string connectionId, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Put; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200404.Instance; - return message; - } - - internal HttpMessage CreateRemoveConnectionFromGroupRequest(string group, string connectionId, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateUserExistsImplRequest(string userId, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Head; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200404.Instance; - return message; - } - - internal HttpMessage CreateCloseUserConnectionsRequest(string userId, IEnumerable excluded, string reason, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendPath("/:closeConnections", false); - if (excluded != null) - { - foreach (var param in excluded) - { - uri.AppendQuery("excluded", param, true); - } - } - if (reason != null) - { - uri.AppendQuery("reason", reason, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateSendToUserRequest(string userId, RequestContent content, ContentType contentType, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendPath("/:send", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", contentType.ToString()); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateSendToUserRequest(string userId, RequestContent content, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendPath("/:send", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - request.Headers.Add("Content-Type", "text/plain"); - request.Content = content; - message.ResponseClassifier = ResponseClassifier202.Instance; - return message; - } - - internal HttpMessage CreateAddUserToGroupRequest(string userId, string group, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Put; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200404.Instance; - return message; - } - - internal HttpMessage CreateRemoveUserFromGroupRequest(string userId, string group, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendPath("/groups/", false); - uri.AppendPath(group, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateRemoveUserFromAllGroupsRequest(string userId, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/users/", false); - uri.AppendPath(userId, true); - uri.AppendPath("/groups", false); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateGrantPermissionRequest(string permission, string connectionId, string targetName, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Put; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/permissions/", false); - uri.AppendPath(permission, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - if (targetName != null) - { - uri.AppendQuery("targetName", targetName, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200.Instance; - return message; - } - - internal HttpMessage CreateRevokePermissionRequest(string permission, string connectionId, string targetName, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Delete; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/permissions/", false); - uri.AppendPath(permission, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - if (targetName != null) - { - uri.AppendQuery("targetName", targetName, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier204.Instance; - return message; - } - - internal HttpMessage CreateCheckPermissionRequest(string permission, string connectionId, string targetName, RequestContext context) - { - var message = _pipeline.CreateMessage(context); - var request = message.Request; - request.Method = RequestMethod.Head; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(_endpoint, false); - uri.AppendPath("/api/hubs/", false); - uri.AppendPath(_hub, true); - uri.AppendPath("/permissions/", false); - uri.AppendPath(permission, true); - uri.AppendPath("/connections/", false); - uri.AppendPath(connectionId, true); - if (targetName != null) - { - uri.AppendQuery("targetName", targetName, true); - } - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json, text/json"); - message.ResponseClassifier = ResponseClassifier200404.Instance; - return message; - } - - private sealed class ResponseClassifier200 : ResponseClassifier - { - private static ResponseClassifier _instance; - public static ResponseClassifier Instance => _instance ??= new ResponseClassifier200(); - public override bool IsErrorResponse(HttpMessage message) - { - return message.Response.Status switch - { - 200 => false, - _ => true - }; - } - } - private sealed class ResponseClassifier204 : ResponseClassifier - { - private static ResponseClassifier _instance; - public static ResponseClassifier Instance => _instance ??= new ResponseClassifier204(); - public override bool IsErrorResponse(HttpMessage message) - { - return message.Response.Status switch - { - 204 => false, - _ => true - }; - } - } - private sealed class ResponseClassifier202 : ResponseClassifier - { - private static ResponseClassifier _instance; - public static ResponseClassifier Instance => _instance ??= new ResponseClassifier202(); - public override bool IsErrorResponse(HttpMessage message) - { - return message.Response.Status switch - { - 202 => false, - _ => true - }; - } - } - private sealed class ResponseClassifier200404 : ResponseClassifier - { - private static ResponseClassifier _instance; - public static ResponseClassifier Instance => _instance ??= new ResponseClassifier200404(); - public override bool IsErrorResponse(HttpMessage message) - { - return message.Response.Status switch - { - 200 => false, - 404 => false, - _ => true - }; - } - } - } -}