/// <inheritdoc />
        public Task DeleteRepairTaskAsync(
            RepairTaskDeleteDescription repairTaskDeleteDescription,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            repairTaskDeleteDescription.ThrowIfNull(nameof(repairTaskDeleteDescription));
            var requestId   = Guid.NewGuid().ToString();
            var url         = "$/DeleteRepairTask";
            var queryParams = new List <string>();

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

            string content;

            using (var sw = new StringWriter())
            {
                RepairTaskDeleteDescriptionConverter.Serialize(new JsonTextWriter(sw), repairTaskDeleteDescription);
                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.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }
        /// <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, RepairTaskDeleteDescription obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.TaskId, "TaskId", JsonWriterExtensions.WriteStringValue);
            if (obj.Version != null)
            {
                writer.WriteProperty(obj.Version, "Version", JsonWriterExtensions.WriteStringValue);
            }

            writer.WriteEndObject();
        }
예제 #3
0
        /// <inheritdoc/>
        protected override void ProcessRecordInternal()
        {
            var repairTaskDeleteDescription = new RepairTaskDeleteDescription(
                taskId: this.TaskId,
                version: this.Version);

            if (((this.Force != null) && this.Force) || this.ShouldContinue(string.Empty, string.Empty))
            {
                this.ServiceFabricClient.Repairs.DeleteRepairTaskAsync(
                    repairTaskDeleteDescription: repairTaskDeleteDescription,
                    cancellationToken: this.CancellationToken).GetAwaiter().GetResult();

                Console.WriteLine("Success!");
            }
        }