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

            try
            {
                DeploymentHelper deploymentHelper = new DeploymentHelper();

                List<Byte> certificateBytes = GetCertificateBytes(certificateFilePath);

                responseString = deploymentHelper.CreateDeployment( subscriptionId, certificateBytes, 
                                                                    serviceName, deploymentName, 
                                                                    deploymentSlot, label, instanceCount);

                Console.WriteLine();

                Console.WriteLine("Response String: {0}", responseString);

                Console.WriteLine();
            }
            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;
        }
Esempio n. 2
0
        // POST /api/deployment/subscriptionId/serviceName/deploymentName/deploymentSlot/label/instanceCount
        // CreateDeployment
        public string Post(AzureDeployment azureDeployment)
        {
            string requestId = string.Empty;

            try
            {
                Logger.Write("In the DeploymentController.Post method...");

                DeploymentHelper deploymentHelper = new DeploymentHelper();

                Logger.Write(string.Format("SubscriptionId: {0}\tService Name: {1}\tCertificate Byte Length: {2}\tDeployment Name: {3}",
                                            azureDeployment.SubscriptionId, azureDeployment.ServiceName, 
                                            azureDeployment.CertificateBytes.ToArray().Length,  azureDeployment.DeploymentName));

                requestId = deploymentHelper.CreateDeployment(azureDeployment.SubscriptionId, 
                                                              azureDeployment.CertificateBytes, 
                                                              azureDeployment.ServiceName,
                                                              azureDeployment.DeploymentName,
                                                              azureDeployment.DeploymentSlot,
                                                              azureDeployment.Label,
                                                              azureDeployment.InstanceCount);

                Logger.Write("Returned RequestId: " + requestId);
            }
            catch (WebException wex)
            {
                string responseString = string.Empty;

                using (StreamReader responseReader = new StreamReader(wex.Response.GetResponseStream()))
                {
                    responseString = responseReader.ReadToEnd();

                    if (string.IsNullOrWhiteSpace(responseString) != true)
                    {
                        Logger.Write("DeploymentController.Post() WebException Response: " + responseString);
                    }

                    responseReader.Close();
                }

                Logger.Write(string.Format("Error in DeploymentController.Post()  Error: {0}\n{1}", wex.Message,
                                            wex.InnerException != null ? wex.InnerException.Message : string.Empty));

                requestId = string.Empty;

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
            	Logger.Write(string.Format("Error in DeploymentController.Post()  Error: {0}\n{1}", ex.Message, 
                                            ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                requestId = string.Empty;

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return requestId;
        }
        // POST /api/operationstatus
        public OperationStatus Post(OperationStatus opsStatus)
        {
            string status = string.Empty;
            string responseString = string.Empty;

            try
            {
                DeploymentHelper deploymentHelper = new DeploymentHelper();

                responseString = deploymentHelper.GetOperationStatus(opsStatus.SubscriptionId, 
                                                                     opsStatus.CertificateBytes, 
                                                                     opsStatus.RequestId, out status);

                opsStatus.Status = status;
                opsStatus.ResponseString = responseString;
            }
            catch (WebException wex)
            {
                string responseStr = string.Empty;

                using (StreamReader responseReader = new StreamReader(wex.Response.GetResponseStream()))
                {
                    responseStr = responseReader.ReadToEnd();

                    if (string.IsNullOrWhiteSpace(responseString) != true)
                    {
                        Logger.Write("OperationStatusController.Post() WebException Response: " + responseStr);
                    }

                    responseReader.Close();
                }

                Logger.Write(string.Format("Error in OperationStatusController.Post()  Error: {0}\n{1}", wex.Message,
                                            wex.InnerException != null ? wex.InnerException.Message : string.Empty));

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("Error in OperationStatusController.Post()  Error: {0}\n{1}", ex.Message,
                                            ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                opsStatus = null;

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return opsStatus;
        }
Esempio n. 4
0
        public void GetOperationStatusTest()
        {
            DeploymentHelper target = new DeploymentHelper();
            string subscriptionId = "e57cc5fa-5cf7-41c0-a33c-3adaf2944c4a";

            List<Byte> certificateBytes = null; // TODO: Initialize to an appropriate value

            string requestId = "";

            string expected = string.Empty; // TODO: Initialize to an appropriate value
            
            string actual;

            string status = string.Empty;

            actual = target.GetOperationStatus(subscriptionId, certificateBytes, requestId, out status);
            
            Assert.AreEqual(expected, actual);
        }
        public void CreateDeploymentTest()
        {
            DeploymentHelper target = new DeploymentHelper();

            string subscriptionId = "e57cc5fa-5cf7-41c0-a33c-3adaf2944c4a";

            string filePath = @"C:\Development\Certificates\AzureManagementCertificate.cer";

            List<Byte> certificateBytes = CertificateUtility.GetCertificateBytes(filePath);

            string serviceName = "commandlinetest";
            string deploymentName = "TestDeployment";
            
            string deploymentSlot = "staging";

            string label = "Hosted Service Test 2.0";
            
            string expected = string.Empty; 

            string actual;
            
            actual = target.CreateDeployment(subscriptionId, certificateBytes, serviceName, deploymentName, deploymentSlot, label, 2);

            string opsStatus = string.Empty;

            string status = "InProgress";

            while (status == "InProgress")
            {
                opsStatus = target.GetOperationStatus(subscriptionId, certificateBytes, actual, out status);

                Trace.WriteLine("Ops Status = " + status);

                Thread.Sleep(2000);
            }

            Assert.AreEqual(expected, actual);
        }
Esempio n. 6
0
        // DELETE /api/deployment
        public string Delete(AzureDeployment azureDeployment)
        {
            string requestId = string.Empty;

            try
            {
                DeploymentHelper deploymentHelper = new DeploymentHelper();

                requestId = deploymentHelper.DeleteDeployment(azureDeployment.SubscriptionId, 
                                                              azureDeployment.CertificateBytes, 
                                                              azureDeployment.ServiceName, 
                                                              azureDeployment.DeploymentSlot);
            }
            catch (WebException wex)
            {
                string responseString = string.Empty;

                using (StreamReader responseReader = new StreamReader(wex.Response.GetResponseStream()))
                {
                    responseString = responseReader.ReadToEnd();

                    if (string.IsNullOrWhiteSpace(responseString) != true)
                    {
                        Logger.Write("DeploymentController.Delete() WebException Response: " + responseString);
                    }

                    responseReader.Close();
                }

                Logger.Write(string.Format("Error in DeploymentController.Delete()  Error: {0}\n{1}", wex.Message,
                                            wex.InnerException != null ? wex.InnerException.Message : string.Empty));

                requestId = string.Empty;

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("Error in DeploymentController.Post()  Error: {0}\n{1}", ex.Message,
                                            ex.InnerException != null ? ex.InnerException.Message : string.Empty));

                requestId = string.Empty;

                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return requestId;
        }
Esempio n. 7
0
        static OperationStatus GetOperationStatus(OperationStatus operationStatus)
        {
            try
            {
                DeploymentHelper deploymentHelper = new DeploymentHelper();

                string status = string.Empty;

                string responseString = deploymentHelper.GetOperationStatus(operationStatus.SubscriptionId, 
                                                                            operationStatus.CertificateBytes,
                                                                            operationStatus.RequestId, out status);

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

                operationStatus = null;
            }

            return operationStatus;
        }