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; }
// 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; }
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); }