Exemple #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, CreateComposeDeploymentDescription obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.DeploymentName, "DeploymentName", JsonWriterExtensions.WriteStringValue);
            writer.WriteProperty(obj.ComposeFileContent, "ComposeFileContent", JsonWriterExtensions.WriteStringValue);
            if (obj.RegistryCredential != null)
            {
                writer.WriteProperty(obj.RegistryCredential, "RegistryCredential", RegistryCredentialConverter.Serialize);
            }

            writer.WriteEndObject();
        }
Exemple #2
0
        /// <inheritdoc/>
        protected override void ProcessRecordInternal()
        {
            var registryCredential = new RegistryCredential(
                registryUserName: this.RegistryUserName,
                registryPassword: this.RegistryPassword,
                passwordEncrypted: this.PasswordEncrypted);

            var createComposeDeploymentDescription = new CreateComposeDeploymentDescription(
                deploymentName: this.DeploymentName,
                composeFileContent: this.ComposeFileContent,
                registryCredential: registryCredential);

            this.ServiceFabricClient.ComposeDeployments.CreateComposeDeploymentAsync(
                createComposeDeploymentDescription: createComposeDeploymentDescription,
                serverTimeout: this.ServerTimeout,
                cancellationToken: this.CancellationToken).GetAwaiter().GetResult();

            Console.WriteLine("Success!");
        }
Exemple #3
0
        /// <inheritdoc />
        public Task CreateComposeDeploymentAsync(
            CreateComposeDeploymentDescription createComposeDeploymentDescription,
            long?serverTimeout = 60,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            createComposeDeploymentDescription.ThrowIfNull(nameof(createComposeDeploymentDescription));
            serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
            var requestId   = Guid.NewGuid().ToString();
            var url         = "ComposeDeployments/$/Create";
            var queryParams = new List <string>();

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

            string content;

            using (var sw = new StringWriter())
            {
                CreateComposeDeploymentDescriptionConverter.Serialize(new JsonTextWriter(sw), createComposeDeploymentDescription);
                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.SendAsync(RequestFunc, url, requestId, cancellationToken));
        }