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

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

            return(strBuilder.ToString());
        }
Example #3
0
        private static ApplicationResourceDescription CreateApplicationResourceDescription(string imageRegistryServer,
                                                                                           string imageRegistryUsername, string imageRegistryPassword, string imageName, string azurePipelinesUrl,
                                                                                           string azurePipelinesToken, int?replicaCount = null)
        {
            var applicationResourceDescription = new ApplicationResourceDescription
            {
                Location = "eastus",
                Services = new List <ServiceResourceDescription>(new[]
                {
                    new ServiceResourceDescription
                    {
                        Name         = ServiceResourceName,
                        OsType       = "linux",
                        ReplicaCount = replicaCount,
                        CodePackages = new List <ContainerCodePackageProperties>(new[]
                        {
                            new ContainerCodePackageProperties
                            {
                                Name = CodePackageName,
                                ImageRegistryCredential = new ImageRegistryCredential(
                                    imageRegistryServer,
                                    imageRegistryUsername,
                                    imageRegistryPassword),
                                Image = imageName,
                                EnvironmentVariables = new List <EnvironmentVariable>(new[]
                                {
                                    new EnvironmentVariable("AZP_AGENT_NAME", $"agent-{Common.CleanGuid()}"),
                                    new EnvironmentVariable("AZP_URL", azurePipelinesUrl),
                                    new EnvironmentVariable("AZP_TOKEN", azurePipelinesToken)
                                }),
                                Resources = new ResourceRequirements
                                {
                                    Requests = new ResourceRequests(1, 1)
                                }
                            }
                        })
                    }
                })
            };

            return(applicationResourceDescription);
        }
Example #4
0
        /// <inheritdoc />
        public Task CreateApplicationResourceAsync(
            string applicationResourceName,
            ApplicationResourceDescription applicationResourceDescription,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            applicationResourceName.ThrowIfNull(nameof(applicationResourceName));
            applicationResourceDescription.ThrowIfNull(nameof(applicationResourceDescription));
            var requestId = Guid.NewGuid().ToString();
            var url       = "Resources/Applications/{applicationResourceName}";

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

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

            string content;

            using (var sw = new StringWriter())
            {
                ApplicationResourceDescriptionConverter.Serialize(new JsonTextWriter(sw), applicationResourceDescription);
                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));
        }
 /// <summary>
 /// Creates or updates an application resource.
 /// </summary>
 /// <remarks>
 /// Creates an application resource with the specified name, description and
 /// properties. If an application 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='applicationResourceName'>
 /// The identity of the application.
 /// </param>
 /// <param name='applicationResourceDescription'>
 /// Description for creating a Application resource.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ApplicationResourceDescription> CreateAsync(this IApplicationOperations operations, string resourceGroupName, string applicationResourceName, ApplicationResourceDescription applicationResourceDescription, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateWithHttpMessagesAsync(resourceGroupName, applicationResourceName, applicationResourceDescription, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates an application resource.
 /// </summary>
 /// <remarks>
 /// Creates an application resource with the specified name, description and
 /// properties. If an application 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='applicationResourceName'>
 /// The identity of the application.
 /// </param>
 /// <param name='applicationResourceDescription'>
 /// Description for creating a Application resource.
 /// </param>
 public static ApplicationResourceDescription Create(this IApplicationOperations operations, string resourceGroupName, string applicationResourceName, ApplicationResourceDescription applicationResourceDescription)
 {
     return(operations.CreateAsync(resourceGroupName, applicationResourceName, applicationResourceDescription).GetAwaiter().GetResult());
 }