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

PerformBuildOperation() private method

Performs the build operation.
private PerformBuildOperation ( bool isLocalDeployment, string currentVersionForlocalDeploy = "" ) : bool
isLocalDeployment bool if set to true [is local deployment].
currentVersionForlocalDeploy string The current version forlocal deploy.
return bool
        private bool PerformBuildOperation(bool isLocalDeployment, string currentVersionForlocalDeploy = "")
        {
            bool buildSuccessful = true;
            int stepNumber = 10;

            if (isLocalDeployment)
            {
                if (string.IsNullOrEmpty(currentVersionForlocalDeploy))
                {
                    throw new ArgumentNullException("Unable to get next successful version to deploy.");
                }

                try
                {
                    this.AssignCloudArgsNoBuild(currentVersionForlocalDeploy);
                }
                catch (IOException ex)
                {
                    ex.ShowUIException();
                    return false;
                }

                return true;
            }

            // Initialize
            this.backgroundWorker.ReportProgress(++stepNumber, "Initializing build parameters....");
            using (BuildTasks tasks = new BuildTasks(this.buildArgs))
            {
                try
                {
                    this.backgroundWorker.ReportProgress(++stepNumber, "Creating temporary TFS workspace....");
                    tasks.CreateDedicatedTfsWorkSpace();

                    this.backgroundWorker.ReportProgress(++stepNumber, "Downloading code for TFS label....");
                    tasks.GetTfsLabelCodeToLocal(txtTFSLabelName.Text);

                    this.backgroundWorker.ReportProgress(++stepNumber, "Compiling and building solution.....");
                    if (tasks.ExecMsBuild())
                    {
                        using (AdvancedMessageBox adv = new AdvancedMessageBox("Build suceeded but has warnings. Do you want to continue?", ReportStatus.Information, true))
                        {
                            this.Invoke((MethodInvoker)delegate
                            {
                                if (DialogResult.Cancel == adv.ShowDialog(this))
                                {
                                    this.AssignCloudArgsAfterBuild(tasks.MSbuildLogPath, tasks.TFLogPath, tasks.AzurePackagesPath);
                                    throw new OperationCanceledException("Operation cancelled.");
                                }
                            });
                        }
                    }

                    this.AssignCloudArgsAfterBuild(tasks.MSbuildLogPath, tasks.TFLogPath, tasks.AzurePackagesPath);
                    this.ShowRequiredDialogs(tasks.AzurePackagesPath);
                }
                catch (FormatException formatexception)
                {
                    buildSuccessful = false;
                    this.Invoke((MethodInvoker)(() => formatexception.ShowUIException()));
                    this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                }
                catch (OperationCanceledException exception)
                {
                    buildSuccessful = false;
                    this.Invoke((MethodInvoker)(() => exception.ShowUIException()));
                    this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                }
                catch (Exception exception)
                {
                    buildSuccessful = false;
                    this.Invoke((MethodInvoker)(() => exception.ShowGenericException("Error in building application.")));
                    this.backgroundWorker.ReportProgress(stepNumber, ReportStatus.Fail);
                }
                finally
                {
                    // in case there is an exception and we are came here directly then check for log paths to enable.
                    if (this.msbuildLogPath == null)
                    {
                        this.msbuildLogPath = tasks.MSbuildLogPath;
                    }

                    if (this.teamfoundationExeLogPath == null)
                    {
                        this.teamfoundationExeLogPath = tasks.TFLogPath;
                    }

                    this.backgroundWorker.ReportProgress(++stepNumber, "Deleting temporary TFS workspace....");
                    tasks.DeleteDedicatedTfsWorkSpace();
                }
            }

            // enable ths user to see log paths
            this.Invoke((MethodInvoker)delegate
            {
                this.btnViewBuildLog.Enabled = File.Exists(this.msbuildLogPath);
                this.btnViewTFLog.Enabled = File.Exists(this.teamfoundationExeLogPath);
            });

            return buildSuccessful;
        }