/// <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, VolumeResourceDescription 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", VolumePropertiesConverter.Serialize);
     writer.WriteEndObject();
 }
Пример #2
0
        /// <summary>
        /// Overloaded ToString function for formatting the output on the console.
        /// </summary>
        /// <param name="volumeResourceDescription"> Object of type VolumeResourceDescription </param>
        /// <returns>
        /// Returns formatted string.
        /// </returns>
        public static string ToString(VolumeResourceDescription volumeResourceDescription)
        {
            var strBuilder = new StringBuilder();

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

            return(strBuilder.ToString());
        }
        /// <inheritdoc />
        public Task <VolumeResourceDescription> CreateOrUpdateAsync(
            string volumeResourceName,
            VolumeResourceDescription volumeResourceDescription,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            volumeResourceName.ThrowIfNull(nameof(volumeResourceName));
            volumeResourceDescription.ThrowIfNull(nameof(volumeResourceDescription));
            var requestId = Guid.NewGuid().ToString();
            var url       = "Resources/Volumes/{volumeResourceName}";

            url = url.Replace("{volumeResourceName}", volumeResourceName);
            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())
            {
                VolumeResourceDescriptionConverter.Serialize(new JsonTextWriter(sw), volumeResourceDescription);
                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, VolumeResourceDescriptionConverter.Deserialize, requestId, cancellationToken));
        }
Пример #4
0
 /// <summary>
 /// Creates or updates a volume resource.
 /// </summary>
 /// <remarks>
 /// Creates a volume resource with the specified name, description and
 /// properties. If a volume resource with the same name exists, then it is
 /// updated with the specified description and properties.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Azure resource group name
 /// </param>
 /// <param name='volumeResourceName'>
 /// The identity of the volume.
 /// </param>
 /// <param name='volumeResourceDescription'>
 /// Description for creating a Volume resource.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <VolumeResourceDescription> CreateAsync(this IVolumeOperations operations, string resourceGroupName, string volumeResourceName, VolumeResourceDescription volumeResourceDescription, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(resourceGroupName, volumeResourceName, volumeResourceDescription, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #5
0
 /// <summary>
 /// Creates or updates a volume resource.
 /// </summary>
 /// <remarks>
 /// Creates a volume resource with the specified name, description and
 /// properties. If a volume resource with the same name exists, then it is
 /// updated with the specified description and properties.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Azure resource group name
 /// </param>
 /// <param name='volumeResourceName'>
 /// The identity of the volume.
 /// </param>
 /// <param name='volumeResourceDescription'>
 /// Description for creating a Volume resource.
 /// </param>
 public static VolumeResourceDescription Create(this IVolumeOperations operations, string resourceGroupName, string volumeResourceName, VolumeResourceDescription volumeResourceDescription)
 {
     return(operations.CreateAsync(resourceGroupName, volumeResourceName, volumeResourceDescription).GetAwaiter().GetResult());
 }