Example #1
0
        private async void btnExport_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(txtDestinationFolder.Text))
            {
                MessageBox.Show("Export path is required.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                btnChoosePath_Click(this, null);
                return;
            }

            if (TemplateResult.OutputFilesExist(txtDestinationFolder.Text))
            {
                if (MessageBox.Show("The target export path already contains export files.  Do you want proceed and overwrite the existing files?", "Overwrite Existing Export", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            btnExport.Enabled = false;
            btnCancel.Enabled = false;

            try
            {
                AsmToArmForm      parentForm        = (AsmToArmForm)this.Owner;
                TemplateGenerator templateGenerator = new TemplateGenerator(parentForm.LogProvider, parentForm.StatusProvider, parentForm.TelemetryProvider, parentForm.AppSettingsProviders);
                TemplateResult    templateResult    = await templateGenerator.GenerateTemplate(parentForm.AzureContextSourceASM.AzureSubscription, parentForm.AzureContextTargetARM.AzureSubscription, artifacts, parentForm.TargetResourceGroup, txtDestinationFolder.Text);

                var exportResults = new ExportResultsDialog(templateResult);
                exportResults.ShowDialog(this);
                this.Close();
            }
            catch (Exception ex)
            {
                parentForm.LogProvider.WriteLog("btnExport_Click", "Error generating template : " + ex.ToString());
                MessageBox.Show("Something went wrong when generating the template. Check the log file for details.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnExport.Enabled = true;
                btnCancel.Enabled = true;
            }
        }