示例#1
0
        public String CreateDeployment(String subscriptionId, List<Byte> certificateBytes, String serviceName,
                                        String deploymentName, String deploymentSlot, String label, int instanceCount = 1)
        {
            String requestId = string.Empty;

            try
            {
                // Go read the Blob Urls for the Azure Deployment Package and
                // Configuration files.
                List<CloudBlob> blobList = AzureStorageUtility.ListBlobs();

                string configUri = string.Empty;
                string packageUri = string.Empty;

                foreach (CloudBlob blob in blobList)
                {
                    if (blob.Attributes.Uri.ToString().ToLower().EndsWith(".cscfg"))
                    {
                        configUri = blob.Attributes.Uri.ToString();

                        Logger.Write("Config Url: " + configUri);
                    }

                    if (blob.Attributes.Uri.ToString().ToLower().EndsWith(".cspkg"))
                    {
                        packageUri = blob.Attributes.Uri.ToString();

                        Logger.Write("Package Url: " + packageUri);
                    }
                }

                // Construct paths to Configuration File in Blob Storage
                string deploymentPackageFolder = ConfigurationManager.AppSettings["DeploymentPackageFolder"].ToString();

                string fileName = configUri.ToString().Substring(configUri.IndexOf("/" + deploymentPackageFolder + "/") + deploymentPackageFolder.Length + 2);

                Logger.Write("Config File Name: " + fileName);

                string configurationString = AzureStorageUtility.ReadBlobFile(fileName);

                // Strip off first non-viewable character
                configurationString = configurationString.Substring(1);

                Logger.Write("Configuration String: " + configurationString);

                // Change instance count to the selected amount
                AzurePackageManager azPackageMgr = new AzurePackageManager();

                string modifiedConfigurationString = azPackageMgr.ChangeDeploymentInstanceCount(instanceCount, configurationString);

                String uri = String.Format(createDeploymentFormat, subscriptionId, serviceName, deploymentSlot);

                XDocument payload = CreatePayload(deploymentName, packageUri, modifiedConfigurationString, label);

                ServiceManagementOperation operation = new ServiceManagementOperation(certificateBytes);

                requestId = operation.Invoke(uri, payload);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error in CreateDeployment()  Error: {0}", ex.Message));

                requestId = string.Empty;
            }

            return requestId;
        }
示例#2
0
        public String GetOperationStatus(String subscriptionId, List<Byte> certificateBytes, String requestId, out String status)
        {
            status = string.Empty;

            XDocument operationStatus = null;
        
            try
            {
                String uri = String.Format(getOperationStatusFormat, subscriptionId, requestId);

                ServiceManagementOperation operation = new ServiceManagementOperation(certificateBytes);

                operationStatus = operation.Invoke(uri);

                status = operationStatus.Element("Operation").Element("Status").Value;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error in GetOperationStatus()  Error: {0}", ex.Message));

                status = string.Empty;
            }

            return operationStatus.ToString();
        }
示例#3
0
        public String CreateHostedService(String subscriptionId, String thumbprint,
                                           String serviceName, String label,
                                           String description, String location, String affinityGroup)
        {
            String requestId = string.Empty;

            try
            {
                String uri = String.Format(createHostedServiceFormat, subscriptionId);

                XDocument payload = CreatePayload(serviceName, label, description, location, affinityGroup);

                ServiceManagementOperation operation = new ServiceManagementOperation(thumbprint);

                requestId = operation.Invoke(uri, payload);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error in CreateHostedService()  Error: {0}", ex.Message));

                requestId = string.Empty;
            }

            return requestId;
        }
示例#4
0
        public String DeleteDeployment(String subscriptionId, List<Byte> certificateBytes, String serviceName,
                                       String deploymentSlot)
        {
            String requestId = string.Empty;

            try
            {
                String uri = String.Format(createDeploymentFormat, subscriptionId, serviceName, deploymentSlot);

                ServiceManagementOperation operation = new ServiceManagementOperation(certificateBytes);

                requestId = operation.Invoke(uri, true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Error in DeleteDeployment()  Error: {0}", ex.Message));

                requestId = string.Empty;
            }

            return requestId;
        }
示例#5
0
        public HostedService GetHostedService(String subscriptionId, List<Byte> certificateBytes, String serviceName)
        {
            HostedService azureService = null;

            try
            {
                String uri = String.Format(getServiceOperationFormat, subscriptionId, serviceName);

                ServiceManagementOperation operation = new ServiceManagementOperation(certificateBytes);

                XDocument hostedServiceProperties = operation.Invoke(uri);

                XmlSerializer serializer = new XmlSerializer(typeof(Bermuda.AdminLibrary.Models.HostedService));

                MemoryStream memStream = new MemoryStream();

                XmlWriter writer = XmlWriter.Create(memStream);

                hostedServiceProperties.Save(writer);

                writer.Close();

                memStream.Seek(0, SeekOrigin.Begin);

                azureService = (HostedService)serializer.Deserialize(memStream);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("Error in GetHostedService()  Error: {0}", ex.Message));

                azureService = null;
            }

            return azureService;
        }