Ejemplo n.º 1
0
        private async void btnExport_Click(object sender, EventArgs e)
        {
            btnExport.Enabled = false;

            var artefacts = new AsmArtefacts();

            foreach (var selectedItem in lvwStorageAccounts.CheckedItems)
            {
                var listItem = (ListViewItem)selectedItem;
                artefacts.StorageAccounts.Add(listItem.Text);
            }

            foreach (var selectedItem in lvwVirtualNetworks.CheckedItems)
            {
                var listItem = (ListViewItem)selectedItem;
                artefacts.VirtualNetworks.Add(listItem.Text);
            }

            foreach (var selectedItem in lvwVirtualMachines.CheckedItems)
            {
                var listItem = (ListViewItem)selectedItem;
                artefacts.VirtualMachines.Add(
                    new CloudServiceVM
                {
                    CloudService   = listItem.Text,
                    VirtualMachine = listItem.SubItems[1].Text,
                });
            }

            if (!Directory.Exists(txtDestinationFolder.Text))
            {
                MessageBox.Show("The chosen output folder does not exist.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // If save selection option is enabled
                if (app.Default.SaveSelection)
                {
                    lblStatus.Text = "BUSY: Reading saved selection";
                    _saveSelectionProvider.Save(Guid.Parse(subscriptionid), lvwVirtualNetworks, lvwStorageAccounts, lvwVirtualMachines);
                }

                var instructionsPath = Path.Combine(txtDestinationFolder.Text, "DeployInstructions.html");
                var templatePath     = Path.Combine(txtDestinationFolder.Text, "export.json");
                var blobDetailsPath  = Path.Combine(txtDestinationFolder.Text, "copyblobdetails.json");
                var templateWriter   = new StreamWriter(templatePath);
                var blobDetailWriter = new StreamWriter(blobDetailsPath);
                try
                {
                    var messages = await _templateGenerator.GenerateTemplate(subscriptionsAndTenants[subscriptionid], subscriptionid, artefacts, templateWriter, blobDetailWriter);

                    var token         = GetToken(subscriptionsAndTenants[subscriptionid], PromptBehavior.Auto);
                    var exportResults = new ExportResults(_asmRetriever, token, messages, subscriptionid, instructionsPath, templatePath, blobDetailsPath);
                    exportResults.ShowDialog(this);
                }
                catch (Exception ex)
                {
                    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;
        }