DeploymentTracker.App.Windows.PackageDeployment.PerformCloudDeployment C# (CSharp) Method

PerformCloudDeployment() private method

Peforms the cloud deployment.
private PerformCloudDeployment ( ) : bool
return bool
        private bool PerformCloudDeployment()
        {
            bool isSuccessful = true;
            int stepNumber = 20;

            // Get storage primary key in either case
            string storagePrimaryKey = string.Empty;

            try
            {
                using (CloudDeploymentTasks cloudTasks = new CloudDeploymentTasks(this.cloudArgs))
                {
                    // If its upgrade donot create hosted serviceand storage primary keys
                    if (!cloudTasks.IsUpgrade)
                    {
                        if (this.isNewStorage)
                        {
                            this.backgroundWorker.ReportProgress(++stepNumber, "Creating storage account in cloud....");
                            storagePrimaryKey = cloudTasks.InitStorageAccount();
                        }
                        else
                        {
                            this.backgroundWorker.ReportProgress(++stepNumber, "Updating storage account in cloud....");
                            storagePrimaryKey = cloudTasks.GetStoragePrimaryKey();
                        }

                        this.backgroundWorker.ReportProgress(++stepNumber, "Creating hosted service in cloud....");
                        cloudTasks.InitHostedService();
                    }
                    else
                    {
                        this.backgroundWorker.ReportProgress(++stepNumber, "Receiving storage account primary key from cloud....");
                        storagePrimaryKey = cloudTasks.GetStoragePrimaryKey();

                        // If storage primary key is not found implies need to create a storage account
                        if (string.IsNullOrEmpty(storagePrimaryKey))
                        {
                            storagePrimaryKey = cloudTasks.InitStorageAccount();
                        }

                        this.backgroundWorker.ReportProgress(++stepNumber, "Creating hosted service in cloud....");
                    }

                    this.backgroundWorker.ReportProgress(++stepNumber, "Copying package to cloud....");
                    cloudTasks.CopyCspkg(storagePrimaryKey);
                    this.backgroundWorker.ReportProgress(++stepNumber, "Deploying package in cloud....");
                    cloudTasks.DeployPackageInCloud();

                    this.backgroundWorker.ReportProgress(++stepNumber, "Creating service certificates. User action required....");

                    if (cloudTasks.CertificatePaths != null && cloudTasks.CertificatePaths.Any())
                    {
                        foreach (var item in cloudTasks.CertificatePaths)
                        {
                            // doit variable is to bypass STA
                            bool doit = false;
                            string fileName = Path.GetFileName(item);
                            PasswordPrompt prompt = new PasswordPrompt(fileName);
                            this.Invoke((MethodInvoker)delegate
                            {
                                prompt.TopMost = true;
                                prompt.StartPosition = FormStartPosition.CenterParent;
                                if (prompt.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                                {
                                    doit = true;
                                }
                            });

                            if (doit)
                            {
                                cloudTasks.AddCertificateToCloud(item, prompt.GivenPassword);
                            }
                            else
                            {
                                string.Format("Cannot install certificate : {0}. Cancelled by User", fileName).WriteToLog();
                                string.Format("Cannot install certificate : {0}. Cancelled by User", fileName).ShowUIInformation(FormStartPosition.CenterScreen);
                            }
                        }
                    }

                    this.backgroundWorker.ReportProgress(++stepNumber, "Cloud deployment completed successfully....");
                }
            }
            catch (WebException exception)
            {
                isSuccessful = false;
                this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                exception.WriteToLog();
                this.Invoke((MethodInvoker)(() => exception.ShowGenericException("Deployment to Cloud failed.")));
            }
            catch (Exception exception)
            {
                isSuccessful = false;
                this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                exception.WriteToLog();
                this.Invoke((MethodInvoker)(() => exception.ShowGenericException("Deployment to Cloud failed.")));
            }

            return isSuccessful;
        }