Beispiel #1
0
        static string CreateDeployment(string subscriptionId, string serviceName,
                                       string label, string deploymentName,
                                       string deploymentSlot, string certificateFilePath,
                                       int instanceCount)
        {
            string responseString = string.Empty;

            // Uri operationUri = new Uri("http://localhost:4652/api/deployment");
            Uri operationUri = new Uri("http://localhost:8080/api/deployment");
            // Uri operationUri = new Uri("http://ec2-23-23-186-66.compute-1.amazonaws.com/BermudaAdmin/api/deployment");

            HttpWebRequest httpWebRequest = CreateHttpWebRequest(operationUri, "POST");

            AzureDeployment azureDeployment = new AzureDeployment();

            azureDeployment.SubscriptionId = subscriptionId;
            azureDeployment.ServiceName    = serviceName;
            azureDeployment.Label          = label;
            azureDeployment.DeploymentName = deploymentName;
            azureDeployment.DeploymentSlot = deploymentSlot;

            try
            {
                azureDeployment.CertificateBytes = GetCertificateBytes(certificateFilePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error: {0}\n{1}", ex.Message,
                                                ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                responseString = string.Empty;
            }

            try
            {
                azureDeployment.InstanceCount = instanceCount;

                string jsonString = string.Empty;

                MemoryStream memStream = new MemoryStream();

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AzureDeployment));

                serializer.WriteObject(memStream, azureDeployment);

                memStream.Position = 0;

                StreamReader sr = new StreamReader(memStream);

                jsonString = sr.ReadToEnd();

                sr.Close();

                Byte[] postData = Encoding.UTF8.GetBytes(jsonString);

                httpWebRequest.ContentLength = postData.Length;

                using (Stream requestStream = httpWebRequest.GetRequestStream())
                {
                    requestStream.Write(postData, 0, postData.Length);
                }

                using (HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse())
                {
                    using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        responseString = streamReader.ReadToEnd();

                        Console.WriteLine(responseString);

                        streamReader.Close();
                        response.Close();
                    }
                }
            }
            catch (WebException wex)
            {
                using (StreamReader exReader = new StreamReader(wex.Response.GetResponseStream()))
                {
                    responseString = exReader.ReadToEnd();

                    exReader.Close();

                    Console.WriteLine(responseString);
                }

                Console.WriteLine(string.Format("Error: {0}\n{1}", wex.Message,
                                                wex.InnerException != null ? wex.InnerException.Message : string.Empty));
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error: {0}\n{1}", ex.Message,
                                                ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                responseString = string.Empty;
            }

            return(responseString);
        }
Beispiel #2
0
        static string CreateDeployment(string subscriptionId, string serviceName,
                                       string label, string deploymentName,
                                       string deploymentSlot, string certificateFilePath,
                                       int instanceCount)
        {
            string responseString = string.Empty;

            // Uri operationUri = new Uri("http://localhost:4652/api/deployment");
            Uri operationUri = new Uri("http://localhost:8080/api/deployment");
            // Uri operationUri = new Uri("http://ec2-23-23-186-66.compute-1.amazonaws.com/BermudaAdmin/api/deployment");

            HttpWebRequest httpWebRequest = CreateHttpWebRequest(operationUri, "POST");

            AzureDeployment azureDeployment = new AzureDeployment();

            azureDeployment.SubscriptionId = subscriptionId;
            azureDeployment.ServiceName = serviceName;
            azureDeployment.Label = label;
            azureDeployment.DeploymentName = deploymentName;
            azureDeployment.DeploymentSlot = deploymentSlot;

            try
            {
                azureDeployment.CertificateBytes = GetCertificateBytes(certificateFilePath);
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error: {0}\n{1}", ex.Message,
                                  ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                responseString = string.Empty;
            }

            try
            {
                azureDeployment.InstanceCount = instanceCount;

                string jsonString = string.Empty;

                MemoryStream memStream = new MemoryStream();

                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AzureDeployment));

                serializer.WriteObject(memStream, azureDeployment);

                memStream.Position = 0;

                StreamReader sr = new StreamReader(memStream);

                jsonString = sr.ReadToEnd();

                sr.Close();

                Byte[] postData = Encoding.UTF8.GetBytes(jsonString);

                httpWebRequest.ContentLength = postData.Length;

                using (Stream requestStream = httpWebRequest.GetRequestStream())
                {
                    requestStream.Write(postData, 0, postData.Length);
                }

                using (HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse())
                {
                    using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        responseString = streamReader.ReadToEnd();

                        Console.WriteLine(responseString);

                        streamReader.Close();
                        response.Close();
                    }
                }
            }
            catch (WebException wex)
            {
                using (StreamReader exReader = new StreamReader(wex.Response.GetResponseStream()))
                {
                    responseString = exReader.ReadToEnd();

                    exReader.Close();

                    Console.WriteLine(responseString);
                }

                Console.WriteLine(string.Format("Error: {0}\n{1}", wex.Message,
                                  wex.InnerException != null ? wex.InnerException.Message : string.Empty));
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Error: {0}\n{1}", ex.Message,
                                  ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                responseString = string.Empty;
            }

            return responseString;
        }