示例#1
0
        public static async Task <DeploymentGetResult> GetDeploymentResultWithPolling(AscDeployment deployment, int pollInterval = 3000)
        {
            var isRunning = true;
            DeploymentGetResult deploymentResult = null;

            while (isRunning)
            {
                deploymentResult = await DeploymentManager.GetDeployment(deployment.ResourceGroupName, deployment.DeploymentName, deployment.SubscriptionId);

                switch (deploymentResult.Deployment.Properties.ProvisioningState)
                {
                case "Accepted":
                case "Running":
                    Thread.Sleep(pollInterval);
                    break;

                case "Failed":
                case "Succeeded":
                    isRunning = false;
                    break;
                }
            }
            if (deploymentResult.Deployment.Properties.ProvisioningState == "Failed")
            {
                throw new ApplicationException("Error deploying Azure Resource. " +
                                               "RequestId: " + deploymentResult.RequestId + ", " +
                                               "Id: " + deploymentResult.Deployment.Id + ", " +
                                               "CorrelationId: " + deploymentResult.Deployment.Properties.CorrelationId);
            }
            return(deploymentResult);
        }
示例#2
0
        private static async Task <DeploymentGetResult> CreateStorageAccountARM(string subscriptionId, string resourceGroupName, object parameters)
        {
            var deployment = new AscDeployment
            {
                Template          = File.ReadAllText(HttpContext.Current.Server.MapPath("~/json/storage-account.json")),
                DeploymentName    = "SVC-CAT-" + DateTime.Now.ToString("hh.mm.ss"),
                SubscriptionId    = subscriptionId,
                ResourceGroupName = resourceGroupName,
                Parameters        = JsonConvert.SerializeObject(parameters)
            };

            var result = await DeploymentManager.Deploy(deployment);

            var deploymentResult = await GetDeploymentResultWithPolling(deployment);

            return(deploymentResult);
        }