Пример #1
0
 /// <summary>
 /// Serializes the object to JSON.
 /// </summary>
 /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
 /// <param name="obj">The object to serialize to JSON.</param>
 internal static void Serialize(JsonWriter writer, GatewayResourceDescription obj)
 {
     // Required properties are always serialized, optional properties are serialized when not null.
     writer.WriteStartObject();
     writer.WriteProperty(obj.Name, "name", JsonWriterExtensions.WriteStringValue);
     writer.WriteProperty(obj.Properties, "properties", GatewayPropertiesConverter.Serialize);
     writer.WriteEndObject();
 }
Пример #2
0
        /// <summary>
        /// Overloaded ToString function for formatting the output on the console.
        /// </summary>
        /// <param name="gatewayResourceDescription"> Object of type GatewayResourceDescription </param>
        /// <returns>
        /// Returns formatted string.
        /// </returns>
        public static string ToString(GatewayResourceDescription gatewayResourceDescription)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "Name", gatewayResourceDescription.Name));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "Description", gatewayResourceDescription.Properties.Description));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "Status", gatewayResourceDescription.Properties.Status));
            strBuilder.Append(Environment.NewLine);
            strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "StatusDetails", gatewayResourceDescription.Properties.StatusDetails));
            strBuilder.Append(Environment.NewLine);

            return(strBuilder.ToString());
        }
Пример #3
0
        /// <inheritdoc />
        public Task <GatewayResourceDescription> CreateOrUpdateAsync(
            string gatewayResourceName,
            GatewayResourceDescription gatewayResourceDescription,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            gatewayResourceName.ThrowIfNull(nameof(gatewayResourceName));
            gatewayResourceDescription.ThrowIfNull(nameof(gatewayResourceDescription));
            var requestId = Guid.NewGuid().ToString();
            var url       = "Resources/Gateways/{gatewayResourceName}";

            url = url.Replace("{gatewayResourceName}", gatewayResourceName);
            var queryParams = new List <string>();

            // Append to queryParams if not null.
            queryParams.Add("api-version=6.4-preview");
            url += "?" + string.Join("&", queryParams);

            string content;

            using (var sw = new StringWriter())
            {
                GatewayResourceDescriptionConverter.Serialize(new JsonTextWriter(sw), gatewayResourceDescription);
                content = sw.ToString();
            }

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Put,
                    Content = new StringContent(content, Encoding.UTF8),
                };

                request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
                return(request);
            }

            return(this.httpClient.SendAsyncGetResponse(RequestFunc, url, GatewayResourceDescriptionConverter.Deserialize, requestId, cancellationToken));
        }
 /// <summary>
 /// Creates or updates a gateway resource.
 /// </summary>
 /// <remarks>
 /// Creates a gateway resource with the specified name, description and
 /// properties. If a gateway resource with the same name exists, then it is
 /// updated with the specified description and properties. Use gateway
 /// resources to create a gateway for public connectivity for services within
 /// your application.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Azure resource group name
 /// </param>
 /// <param name='gatewayResourceName'>
 /// The identity of the gateway.
 /// </param>
 /// <param name='gatewayResourceDescription'>
 /// Description for creating a Gateway resource.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <GatewayResourceDescription> CreateAsync(this IGatewayOperations operations, string resourceGroupName, string gatewayResourceName, GatewayResourceDescription gatewayResourceDescription, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(resourceGroupName, gatewayResourceName, gatewayResourceDescription, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates a gateway resource.
 /// </summary>
 /// <remarks>
 /// Creates a gateway resource with the specified name, description and
 /// properties. If a gateway resource with the same name exists, then it is
 /// updated with the specified description and properties. Use gateway
 /// resources to create a gateway for public connectivity for services within
 /// your application.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Azure resource group name
 /// </param>
 /// <param name='gatewayResourceName'>
 /// The identity of the gateway.
 /// </param>
 /// <param name='gatewayResourceDescription'>
 /// Description for creating a Gateway resource.
 /// </param>
 public static GatewayResourceDescription Create(this IGatewayOperations operations, string resourceGroupName, string gatewayResourceName, GatewayResourceDescription gatewayResourceDescription)
 {
     return(operations.CreateAsync(resourceGroupName, gatewayResourceName, gatewayResourceDescription).GetAwaiter().GetResult());
 }