Esempio n. 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, PropertyBatchDescriptionList obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            if (obj.Operations != null)
            {
                writer.WriteEnumerableProperty(obj.Operations, "Operations", PropertyBatchOperationConverter.Serialize);
            }

            writer.WriteEndObject();
        }
Esempio n. 2
0
        /// <inheritdoc/>
        protected override void ProcessRecordInternal()
        {
            var propertyBatchDescriptionList = new PropertyBatchDescriptionList(
                operations: this.Operations);

            var result = this.ServiceFabricClient.Properties.SubmitPropertyBatchAsync(
                nameId: this.NameId,
                propertyBatchDescriptionList: propertyBatchDescriptionList,
                serverTimeout: this.ServerTimeout,
                cancellationToken: this.CancellationToken).GetAwaiter().GetResult();

            if (result != null)
            {
                this.WriteObject(this.FormatOutput(result));
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public Task <PropertyBatchInfo> SubmitPropertyBatchAsync(
            string nameId,
            PropertyBatchDescriptionList propertyBatchDescriptionList,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            nameId.ThrowIfNull(nameof(nameId));
            propertyBatchDescriptionList.ThrowIfNull(nameof(propertyBatchDescriptionList));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId = Guid.NewGuid().ToString();
            var url       = "Names/{nameId}/$/GetProperties/$/SubmitBatch";

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

            // Append to queryParams if not null.
            serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
            queryParams.Add("api-version=6.0");
            url += "?" + string.Join("&", queryParams);

            string content;

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

            HttpRequestMessage RequestFunc()
            {
                var request = new HttpRequestMessage()
                {
                    Method  = HttpMethod.Post,
                    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, PropertyBatchInfoConverter.Deserialize, requestId, cancellationToken));
        }