/// <inheritdoc/>
        protected override void ProcessRecordInternal()
        {
            var fabricName = new FabricName(
                name: this.Name);

            this.ServiceFabricClient.Properties.CreateNameAsync(
                fabricName: fabricName,
                serverTimeout: this.ServerTimeout,
                cancellationToken: this.CancellationToken).GetAwaiter().GetResult();

            Console.WriteLine("Success!");
        }
예제 #2
0
        /// <inheritdoc />
        public Task CreateNameAsync(
            FabricName fabricName,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            fabricName.ThrowIfNull(nameof(fabricName));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "Names/$/Create";
            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())
            {
                NameDescriptionConverter.Serialize(new JsonTextWriter(sw), fabricName);
                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 FabricName object to JSON representing NameDescription as defined in Swagger.
 /// </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, FabricName obj)
 {
     writer.WriteStartObject();
     writer.WriteProperty(obj.ToString(), "Name", JsonWriterExtensions.WriteStringValue);
     writer.WriteEndObject();
 }
 /// <summary>
 /// Returns the JSON representation of the object.
 /// </summary>
 /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
 /// <param name="value">The object to serialize to JSON.</param>
 public static void Serialize(JsonWriter writer, FabricName value)
 {
     writer.WriteValue(value.ToString());
 }