Beispiel #1
0
        private void btnExport_Click_1(object sender, EventArgs e)
        {
            if (splitContainer2.Panel1.Controls.Count == 1)
            {
                IMigratorUserControl migrator = (IMigratorUserControl)splitContainer2.Panel1.Controls[0];

                if (migrator.TemplateGenerator.HasErrors)
                {
                    MessageBox.Show("There are still one or more error(s) with the template generation.  Please resolve all errors before exporting.");
                    return;
                }

                // We are refreshing both the MemoryStreams and the Output Tabs via this call, prior to writing to files
                btnRefreshOutput_Click(this, null);

                migrator.TemplateGenerator.OutputDirectory = txtDestinationFolder.Text;
                migrator.TemplateGenerator.Write();

                // post Telemetry Record to ASMtoARMToolAPI
                if (AppSettingsProvider.AllowTelemetry)
                {
                    StatusProvider.UpdateStatus("BUSY: saving telemetry information");
                    migrator.PostTelemetryRecord();
                }

                StatusProvider.UpdateStatus("Ready");

                var exportResults = new ExportResultsDialog(migrator.TemplateGenerator);
                exportResults.ShowDialog(this);
            }
        }
Beispiel #2
0
        private async Task _AzureContextARM_AfterAzureSubscriptionChange(AzureContext sender)
        {
            ResetForm();

            if (sender.AzureSubscription != null)
            {
                //btnAzureContextARM.Enabled = true;

                TreeNode subscriptionNode = new TreeNode(sender.AzureSubscription.Name);
                treeSource.Nodes.Add(subscriptionNode);
                subscriptionNode.Expand();


                //    if (app.Default.SaveSelection)
                //    {
                //        lblStatus.Text = "BUSY: Reading saved selection";
                //        Application.DoEvents();
                //        _saveSelectionProvider.Read(Guid.Parse(subscriptionid),ref lvwVirtualNetworks, ref lvwStorageAccounts, ref lvwVirtualMachines);
                //    }

                treeSource.Enabled = true;
            }

            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #3
0
        private void btnExport_Click_1(object sender, EventArgs e)
        {
            if (splitContainer2.Panel1.Controls.Count == 1)
            {
                IMigratorUserControl migrator = (IMigratorUserControl)splitContainer2.Panel1.Controls[0];

                if (migrator.TemplateGenerator.HasErrors)
                {
                    tabMigAzMonitoring.SelectTab("tabMessages");
                    MessageBox.Show("There are still one or more error(s) with the template generation.  Please resolve all errors before exporting.");
                    return;
                }

                migrator.TemplateGenerator.OutputDirectory = txtDestinationFolder.Text;

                // We are refreshing both the MemoryStreams and the Output Tabs via this call, prior to writing to files
                btnRefreshOutput_Click(this, null);

                migrator.TemplateGenerator.Write();

                StatusProvider.UpdateStatus("Ready");

                var exportResults = new ExportResultsDialog(migrator.TemplateGenerator);
                exportResults.ShowDialog(this);
            }
        }
Beispiel #4
0
        private async Task targetTreeView1_AfterTargetSelected(TargetTreeView targetTreeView, TreeNode selectedNode)
        {
            try
            {
                if (this.LogProvider != null)
                {
                    LogProvider.WriteLog("Control_AfterTargetSelected", "Start");
                }

                _EventSourceNode = selectedNode;
                await BindPropertyPanel(targetTreeView, selectedNode);

                _EventSourceNode = null;

                if (this.LogProvider != null)
                {
                    LogProvider.WriteLog("Control_AfterTargetSelected", "End");
                }

                if (this.StatusProvider != null)
                {
                    StatusProvider.UpdateStatus("Ready");
                }
            }
            catch (Exception exc)
            {
                UnhandledExceptionDialog unhandledExceptionDialog = new UnhandledExceptionDialog(this.LogProvider, exc);
                unhandledExceptionDialog.ShowDialog();
            }
        }
Beispiel #5
0
        private async void treeTargetARM_AfterSelect(object sender, TreeViewEventArgs e)
        {
            LogProvider.WriteLog("treeARM_AfterSelect", "Start");

            _PropertyPanel.Bind(e.Node);

            LogProvider.WriteLog("treeARM_AfterSelect", "End");
            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #6
0
        private async Task ReadSubscriptionSettings(AzureSubscription azureSubscription)
        {
            // If save selection option is enabled
            if (app.Default.SaveSelection)
            {
                StatusProvider.UpdateStatus("BUSY: Reading saved selection");
                await _saveSelectionProvider.Read(azureSubscription.SubscriptionId, _AzureContextSourceASM.AzureRetriever, AzureContextTargetARM.AzureRetriever, treeSourceASM);

                UpdateExportItemsCount();
            }
        }
Beispiel #7
0
        private void cmbRegion_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbRegion.Enabled == true)
            {
                //Load the Region Items
                // TODO Load_Items();
            }

            // If save selection option is enabled
            if (app.Default.SaveSelection)
            {
                StatusProvider.UpdateStatus("BUSY: Reading saved selection");
                _saveSelectionProvider.Read(cmbRegion.Text, ref lvwVirtualNetworks, ref lvwVirtualMachines);
            }
        }
Beispiel #8
0
        private async void btnExport_Click_1Async(object sender, EventArgs e)
        {
            // We are refreshing both the MemoryStreams and the Output Tabs via this call, prior to writing to files
            if (await RefreshOutput())
            {
                if (this.AzureGenerator != null)
                {
                    this.AzureGenerator.OutputDirectory = txtDestinationFolder.Text;

                    this.AzureGenerator.Write();

                    StatusProvider.UpdateStatus("Ready");

                    var exportResults = new ExportResultsDialog(this.AzureGenerator);
                    exportResults.ShowDialog(this);
                }
            }
        }
Beispiel #9
0
        private void Load_Items()
        {
            LogProvider.WriteLog("Load_Items", "Start");

            treeSourceAWS.Nodes.Clear();
            treeTargetARM.Nodes.Clear();

            TreeNode subscriptionNode = new TreeNode("AWS Subscription");

            treeSourceAWS.Nodes.Add(subscriptionNode);

            AWSRetriever awsRetriever = new AWSRetriever(this.LogProvider, this.StatusProvider);

            awsRetriever.toname(accessKeyTextBox.Text.Trim(), secretKeyTextBox.Text.Trim(), subscriptionNode);

            subscriptionNode.ExpandAll();

            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #10
0
        private async void TargetTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (this.LogProvider != null)
            {
                LogProvider.WriteLog("treeARM_AfterSelect", "Start");
            }

            _EventSourceNode = e.Node;
            await _PropertyPanel.Bind(e.Node);

            _EventSourceNode = null;

            if (this.LogProvider != null)
            {
                LogProvider.WriteLog("treeARM_AfterSelect", "End");
            }

            if (this.StatusProvider != null)
            {
                StatusProvider.UpdateStatus("Ready");
            }
        }
Beispiel #11
0
        private async void treeARM_AfterSelect(object sender, TreeViewEventArgs e)
        {
            LogProvider.WriteLog("treeARM_AfterSelect", "Start");
            _SourceArmNode = e.Node;

            _PropertyPanel.Clear();
            _PropertyPanel.ResourceText = String.Empty;
            if (e.Node.Tag != null)
            {
                if (e.Node.Tag.GetType() == typeof(TreeNode))
                {
                    TreeNode asmTreeNode = (TreeNode)e.Node.Tag;

                    if (asmTreeNode.Tag != null)
                    {
                        _PropertyPanel.ResourceText = e.Node.Text;

                        if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.VirtualNetwork) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.VirtualNetwork))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["VirtualNetwork"];

                            VirtualNetworkProperties properties = new VirtualNetworkProperties();
                            properties.PropertyChanged += Properties_PropertyChanged;
                            properties.Bind(e.Node);
                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.StorageAccount) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.StorageAccount))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["StorageAccount"];

                            StorageAccountProperties properties = new StorageAccountProperties();
                            properties.PropertyChanged += Properties_PropertyChanged;
                            properties.Bind(this._AzureContextTargetARM, e.Node);
                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.VirtualMachine) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.VirtualMachine))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["VirtualMachine"];

                            VirtualMachineProperties properties = new VirtualMachineProperties();
                            properties.LogProvider       = LogProvider;
                            properties.AllowManangedDisk = (await _AzureContextSourceASM.AzureRetriever.GetAzureARMManagedDisks() != null);
                            properties.PropertyChanged  += Properties_PropertyChanged;
                            await properties.Bind(e.Node, this);

                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.NetworkSecurityGroup) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.NetworkSecurityGroup))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["NetworkSecurityGroup"];

                            NetworkSecurityGroupProperties properties = new NetworkSecurityGroupProperties();
                            properties.PropertyChanged += Properties_PropertyChanged;
                            properties.Bind(e.Node, this);
                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                    }
                }
                if (e.Node.Tag.GetType() == typeof(Azure.Asm.Subnet) || e.Node.Tag.GetType() == typeof(Azure.Arm.Subnet))
                {
                    this._PropertyPanel.ResourceImage = imageList1.Images["VirtualNetwork"];

                    SubnetProperties properties = new SubnetProperties();
                    properties.PropertyChanged += Properties_PropertyChanged;
                    properties.Bind(e.Node);
                    _PropertyPanel.PropertyDetailControl = properties;
                }
                else if (e.Node.Tag.GetType() == typeof(Azure.Asm.Disk) || e.Node.Tag.GetType() == typeof(Azure.Arm.Disk))
                {
                    Azure.Asm.Disk asmDisk = (Azure.Asm.Disk)e.Node.Tag;

                    this._PropertyPanel.ResourceImage = imageList1.Images["Disk"];

                    DiskProperties properties = new DiskProperties();
                    properties.LogProvider       = this.LogProvider;
                    properties.AllowManangedDisk = (await _AzureContextSourceASM.AzureRetriever.GetAzureARMManagedDisks() != null);
                    properties.PropertyChanged  += Properties_PropertyChanged;
                    properties.Bind(this, e.Node);
                    _PropertyPanel.PropertyDetailControl = properties;
                }
                else if (e.Node.Tag.GetType() == typeof(Azure.Asm.AvailabilitySet))
                {
                    this._PropertyPanel.ResourceImage = imageList1.Images["AvailabilitySet"];

                    AvailabilitySetProperties properties = new AvailabilitySetProperties();
                    properties.PropertyChanged += Properties_PropertyChanged;
                    properties.Bind(e.Node);
                    _PropertyPanel.PropertyDetailControl = properties;
                }
                else if (e.Node.Tag.GetType() == typeof(ResourceGroup))
                {
                    this._PropertyPanel.ResourceImage = imageList1.Images["ResourceGroup"];

                    ResourceGroupProperties properties = new ResourceGroupProperties();
                    properties.PropertyChanged += Properties_PropertyChanged;
                    await properties.Bind(this, e.Node);

                    _PropertyPanel.PropertyDetailControl = properties;
                }
            }

            _SourceArmNode = null;
            LogProvider.WriteLog("treeARM_AfterSelect", "End");
            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #12
0
        private async void btnRefreshOutput_Click(object sender, EventArgs e)
        {
            SplitterPanel parent = (SplitterPanel)splitContainer2.Panel1;

            if (parent.Controls.Count == 1)
            {
                IMigratorUserControl migrator = (IMigratorUserControl)parent.Controls[0];

                if (migrator.TemplateGenerator.HasErrors)
                {
                    tabMigAzMonitoring.SelectTab("tabMessages");
                    MessageBox.Show("There are still one or more error(s) with the template generation.  Please resolve all errors before exporting.");
                    return;
                }

                await migrator.TemplateGenerator.GenerateStreams();

                await migrator.TemplateGenerator.SerializeStreams();

                foreach (TabPage tabPage in tabOutputResults.TabPages)
                {
                    if (!migrator.TemplateGenerator.TemplateStreams.ContainsKey(tabPage.Name))
                    {
                        tabOutputResults.TabPages.Remove(tabPage);
                    }
                }

                foreach (var templateStream in migrator.TemplateGenerator.TemplateStreams)
                {
                    TabPage tabPage = null;
                    if (!tabOutputResults.TabPages.ContainsKey(templateStream.Key))
                    {
                        tabPage      = new TabPage(templateStream.Key);
                        tabPage.Name = templateStream.Key;
                        tabOutputResults.TabPages.Add(tabPage);

                        if (templateStream.Key.EndsWith(".html"))
                        {
                            WebBrowser webBrowser = new WebBrowser();
                            webBrowser.Width             = tabOutputResults.Width - 15;
                            webBrowser.Height            = tabOutputResults.Height - 30;
                            webBrowser.AllowNavigation   = false;
                            webBrowser.ScrollBarsEnabled = true;
                            tabPage.Controls.Add(webBrowser);
                        }
                        else if (templateStream.Key.EndsWith(".json") || templateStream.Key.EndsWith(".ps1"))
                        {
                            TextBox textBox = new TextBox();
                            textBox.Width      = tabOutputResults.Width - 15;
                            textBox.Height     = tabOutputResults.Height - 30;
                            textBox.ReadOnly   = true;
                            textBox.Multiline  = true;
                            textBox.WordWrap   = false;
                            textBox.ScrollBars = ScrollBars.Both;
                            tabPage.Controls.Add(textBox);
                        }
                    }
                    else
                    {
                        tabPage = tabOutputResults.TabPages[templateStream.Key];
                    }

                    if (tabPage.Controls[0].GetType() == typeof(TextBox))
                    {
                        TextBox textBox = (TextBox)tabPage.Controls[0];
                        templateStream.Value.Position = 0;
                        textBox.Text = new StreamReader(templateStream.Value).ReadToEnd();
                    }
                    else if (tabPage.Controls[0].GetType() == typeof(WebBrowser))
                    {
                        WebBrowser webBrowser = (WebBrowser)tabPage.Controls[0];
                        templateStream.Value.Position = 0;

                        if (webBrowser.Document == null)
                        {
                            webBrowser.DocumentText = new StreamReader(templateStream.Value).ReadToEnd();
                        }
                        else
                        {
                            webBrowser.Document.OpenNew(true);
                            webBrowser.Document.Write(new StreamReader(templateStream.Value).ReadToEnd());
                        }
                    }
                }

                if (tabOutputResults.TabPages.Count != migrator.TemplateGenerator.TemplateStreams.Count)
                {
                    throw new ArgumentException("Count mismatch between tabOutputResults TabPages and Migrator TemplateStreams.  Counts should match after addition/removal above.  tabOutputResults. TabPages Count: " + tabOutputResults.TabPages.Count + "  Migration TemplateStream Count: " + migrator.TemplateGenerator.TemplateStreams.Count);
                }

                // Ensure Tabs are in same order as output streams
                int streamIndex = 0;
                foreach (string templateStreamKey in migrator.TemplateGenerator.TemplateStreams.Keys)
                {
                    int rotationCounter = 0;

                    // This while loop is to bubble the tab to the end, as to rotate the tab sequence to ensure they match the order returned from the stream outputs
                    // The addition/removal of Streams may result in order of existing tabPages being "out of order" to the streams generated, so we may need to consider reordering
                    while (tabOutputResults.TabPages[streamIndex].Name != templateStreamKey)
                    {
                        TabPage currentTabpage = tabOutputResults.TabPages[streamIndex];
                        tabOutputResults.TabPages.Remove(currentTabpage);
                        tabOutputResults.TabPages.Add(currentTabpage);

                        rotationCounter++;

                        if (rotationCounter > migrator.TemplateGenerator.TemplateStreams.Count)
                        {
                            throw new ArgumentException("Rotated through all tabs, unabled to locate tab '" + templateStreamKey + "' while ensuring tab order/sequencing.");
                        }
                    }

                    streamIndex++;
                }


                lblLastOutputRefresh.Text = "Last Refresh Completed: " + DateTime.Now.ToString();
                btnRefreshOutput.Enabled  = false;

                // post Telemetry Record to ASMtoARMToolAPI
                if (AppSettingsProvider.AllowTelemetry)
                {
                    StatusProvider.UpdateStatus("BUSY: saving telemetry information");
                    migrator.PostTelemetryRecord();
                }
            }
        }
Beispiel #13
0
        private async Task <bool> RefreshOutput()
        {
            if (AssertHasTargetErrors())
            {
                return(false);
            }

            IMigrationSourceUserControl migrationSourceControl = this.MigrationSourceControl;

            if (migrationSourceControl == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL MigrationSourceControl Context");
            }

            if (targetAzureContextViewer.ExistingContext == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL Target Existing Azure Context");
            }

            if (targetAzureContextViewer.ExistingContext.AzureSubscription == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL Target Existing Azure Context");
            }

            if (this.AzureGenerator == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL TemplateGenerator");
            }

            if (this.targetAzureContextViewer == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL TargetAzureContextViewer");
            }

            if (this.targetAzureContextViewer.SelectedAzureContext == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL SelectedAzureContext on TargetAzureContextViewer");
            }

            if (this.targetAzureContextViewer.SelectedAzureContext.TokenProvider == null)
            {
                throw new ArgumentException("Unable to Refresh Output:  NULL TokenProvider on SelectedAzureContext");
            }

            if (this.AzureGenerator != null)
            {
                this.AzureGenerator.AccessSASTokenLifetimeSeconds = app.Default.AccessSASTokenLifetimeSeconds;
                this.AzureGenerator.ExportArtifacts          = this.targetTreeView1.ExportArtifacts;
                this.AzureGenerator.OutputDirectory          = this.txtDestinationFolder.Text;
                this.AzureGenerator.TargetAzureTokenProvider = (AzureTokenProvider)this.targetAzureContextViewer.SelectedAzureContext.TokenProvider;

                await this.AzureGenerator.GenerateStreams();

                foreach (TabPage tabPage in tabOutputResults.TabPages)
                {
                    if (!this.AzureGenerator.TemplateStreams.ContainsKey(tabPage.Name))
                    {
                        tabOutputResults.TabPages.Remove(tabPage);
                    }
                }

                foreach (var templateStream in this.AzureGenerator.TemplateStreams)
                {
                    TabPage tabPage = null;
                    if (!tabOutputResults.TabPages.ContainsKey(templateStream.Key))
                    {
                        tabPage      = new TabPage(templateStream.Key);
                        tabPage.Name = templateStream.Key;
                        tabOutputResults.TabPages.Add(tabPage);

                        if (templateStream.Key.EndsWith(".html"))
                        {
                            WebBrowser webBrowser = new WebBrowser();
                            webBrowser.Width             = tabOutputResults.Width - 15;
                            webBrowser.Height            = tabOutputResults.Height - 30;
                            webBrowser.AllowNavigation   = false;
                            webBrowser.ScrollBarsEnabled = true;
                            tabPage.Controls.Add(webBrowser);
                        }
                        else if (templateStream.Key.EndsWith(".json") || templateStream.Key.EndsWith(".ps1"))
                        {
                            TextBox textBox = new TextBox();
                            textBox.Width      = tabOutputResults.Width - 15;
                            textBox.Height     = tabOutputResults.Height - 30;
                            textBox.ReadOnly   = true;
                            textBox.Multiline  = true;
                            textBox.WordWrap   = false;
                            textBox.ScrollBars = ScrollBars.Both;
                            tabPage.Controls.Add(textBox);
                        }
                    }
                    else
                    {
                        tabPage = tabOutputResults.TabPages[templateStream.Key];
                    }

                    if (tabPage.Controls[0].GetType() == typeof(TextBox))
                    {
                        TextBox textBox = (TextBox)tabPage.Controls[0];
                        templateStream.Value.Position = 0;
                        textBox.Text = new StreamReader(templateStream.Value).ReadToEnd();
                    }
                    else if (tabPage.Controls[0].GetType() == typeof(WebBrowser))
                    {
                        WebBrowser webBrowser = (WebBrowser)tabPage.Controls[0];
                        templateStream.Value.Position = 0;

                        if (webBrowser.Document == null)
                        {
                            webBrowser.DocumentText = new StreamReader(templateStream.Value).ReadToEnd();
                        }
                        else
                        {
                            webBrowser.Document.OpenNew(true);
                            webBrowser.Document.Write(new StreamReader(templateStream.Value).ReadToEnd());
                        }
                    }
                }

                if (tabOutputResults.TabPages.Count != this.AzureGenerator.TemplateStreams.Count)
                {
                    throw new ArgumentException("Count mismatch between tabOutputResults TabPages and Migrator TemplateStreams.  Counts should match after addition/removal above.  tabOutputResults. TabPages Count: " + tabOutputResults.TabPages.Count + "  Migration TemplateStream Count: " + this.AzureGenerator.TemplateStreams.Count);
                }

                // Ensure Tabs are in same order as output streams
                int streamIndex = 0;
                foreach (string templateStreamKey in this.AzureGenerator.TemplateStreams.Keys)
                {
                    int rotationCounter = 0;

                    // This while loop is to bubble the tab to the end, as to rotate the tab sequence to ensure they match the order returned from the stream outputs
                    // The addition/removal of Streams may result in order of existing tabPages being "out of order" to the streams generated, so we may need to consider reordering
                    while (tabOutputResults.TabPages[streamIndex].Name != templateStreamKey)
                    {
                        TabPage currentTabpage = tabOutputResults.TabPages[streamIndex];
                        tabOutputResults.TabPages.Remove(currentTabpage);
                        tabOutputResults.TabPages.Add(currentTabpage);

                        rotationCounter++;

                        if (rotationCounter > this.AzureGenerator.TemplateStreams.Count)
                        {
                            throw new ArgumentException("Rotated through all tabs, unabled to locate tab '" + templateStreamKey + "' while ensuring tab order/sequencing.");
                        }
                    }

                    streamIndex++;
                }


                lblLastOutputRefresh.Text = "Last Refresh Completed: " + DateTime.Now.ToString();
                btnRefreshOutput.Enabled  = false;

                // post Telemetry Record to ASMtoARMToolAPI
                if (AppSettingsProvider.AllowTelemetry)
                {
                    StatusProvider.UpdateStatus("BUSY: saving telemetry information");
                    _telemetryProvider.PostTelemetryRecord(_AppSessionGuid, this.MigrationSourceControl.MigrationSourceType, targetAzureContextViewer.ExistingContext.AzureSubscription, this.AzureGenerator);
                }
            }

            StatusProvider.UpdateStatus("Ready");
            return(true);
        }
Beispiel #14
0
        private async Task _AzureContextARM_AfterAzureSubscriptionChange(AzureContext sender)
        {
            ResetForm();

            if (sender.AzureSubscription != null)
            {
                //btnAzureContextARM.Enabled = true;

                TreeNode subscriptionNode = new TreeNode(sender.AzureSubscription.Name);
                treeSource.Nodes.Add(subscriptionNode);
                subscriptionNode.Expand();

                foreach (ResourceGroup armResourceGroup in await _AzureContextARM.AzureRetriever.GetAzureARMResourceGroups())
                {
                }

                List <VirtualNetwork> armVirtualNetworks = await _AzureContextARM.AzureRetriever.GetAzureARMVirtualNetworks();

                foreach (VirtualNetwork armVirtualNetwork in armVirtualNetworks)
                {
                    if (armVirtualNetwork.HasNonGatewaySubnet)
                    {
                        TreeNode parentNode       = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNode, armVirtualNetwork.Location, "Virtual Networks");
                        TreeNode tnVirtualNetwork = new TreeNode(armVirtualNetwork.Name);
                        tnVirtualNetwork.Name = armVirtualNetwork.Name;
                        tnVirtualNetwork.Tag  = armVirtualNetwork;
                        parentNode.Nodes.Add(tnVirtualNetwork);
                        parentNode.Expand();
                    }
                }

                foreach (StorageAccount armStorageAccount in await _AzureContextARM.AzureRetriever.GetAzureARMStorageAccounts())
                {
                    TreeNode parentNode       = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNode, armStorageAccount.PrimaryLocation, "Storage Accounts");
                    TreeNode tnStorageAccount = new TreeNode(armStorageAccount.Name);
                    tnStorageAccount.Name = tnStorageAccount.Text;
                    tnStorageAccount.Tag  = armStorageAccount;
                    parentNode.Nodes.Add(tnStorageAccount);
                    parentNode.Expand();
                }

                foreach (VirtualMachine armVirtualMachine in await _AzureContextARM.AzureRetriever.GetAzureArmVirtualMachines())
                {
                    TreeNode parentNode       = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNode, armVirtualMachine.Location, "Virtual Machines");
                    TreeNode tnVirtualMachine = new TreeNode(armVirtualMachine.Name);
                    tnVirtualMachine.Name = tnVirtualMachine.Text;
                    tnVirtualMachine.Tag  = armVirtualMachine;
                    parentNode.Nodes.Add(tnVirtualMachine);
                    parentNode.Expand();
                }

                subscriptionNode.ExpandAll();

                //    if (app.Default.SaveSelection)
                //    {
                //        lblStatus.Text = "BUSY: Reading saved selection";
                //        Application.DoEvents();
                //        _saveSelectionProvider.Read(Guid.Parse(subscriptionid),ref lvwVirtualNetworks, ref lvwStorageAccounts, ref lvwVirtualMachines);
                //    }

                treeSource.Enabled = true;
            }

            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #15
0
        private async Task AutoSelectDependencies(TreeNode selectedNode)
        {
            if ((app.Default.AutoSelectDependencies) && (selectedNode.Checked) && (selectedNode.Tag != null))
            {
                if (selectedNode.Tag.GetType() == typeof(Azure.Asm.VirtualMachine))
                {
                    Azure.Asm.VirtualMachine asmVirtualMachine = (Azure.Asm.VirtualMachine)selectedNode.Tag;

                    #region process virtual network
                    if (asmVirtualMachine.VirtualNetworkName != string.Empty)
                    {
                        foreach (TreeNode treeNode in treeSourceASM.Nodes.Find(asmVirtualMachine.VirtualNetworkName, true))
                        {
                            if ((treeNode.Tag != null) && (treeNode.Tag.GetType() == typeof(Azure.Asm.VirtualNetwork)))
                            {
                                if (!treeNode.Checked)
                                {
                                    treeNode.Checked = true;
                                }
                            }
                        }
                    }

                    #endregion

                    #region OS Disk Storage Account

                    foreach (TreeNode treeNode in treeSourceASM.Nodes.Find(asmVirtualMachine.OSVirtualHardDisk.StorageAccountName, true))
                    {
                        if ((treeNode.Tag != null) && (treeNode.Tag.GetType() == typeof(Azure.Asm.StorageAccount)))
                        {
                            if (!treeNode.Checked)
                            {
                                treeNode.Checked = true;
                            }
                        }
                    }

                    #endregion

                    #region Data Disk(s) Storage Account(s)

                    foreach (Azure.Asm.Disk dataDisk in asmVirtualMachine.DataDisks)
                    {
                        foreach (TreeNode treeNode in treeSourceASM.Nodes.Find(dataDisk.StorageAccountName, true))
                        {
                            if ((treeNode.Tag != null) && (treeNode.Tag.GetType() == typeof(Azure.Asm.StorageAccount)))
                            {
                                if (!treeNode.Checked)
                                {
                                    treeNode.Checked = true;
                                }
                            }
                        }
                    }

                    #endregion

                    #region Network Security Group

                    if (asmVirtualMachine.NetworkSecurityGroup != null)
                    {
                        foreach (TreeNode treeNode in treeSourceASM.Nodes.Find(asmVirtualMachine.NetworkSecurityGroup.Name, true))
                        {
                            if ((treeNode.Tag != null) && (treeNode.Tag.GetType() == typeof(Azure.Asm.NetworkSecurityGroup)))
                            {
                                if (!treeNode.Checked)
                                {
                                    treeNode.Checked = true;
                                }
                            }
                        }
                    }

                    #endregion
                }

                else if (selectedNode.Tag.GetType() == typeof(Azure.Asm.VirtualNetwork))
                {
                    Azure.Asm.VirtualNetwork asmVirtualNetwork = (Azure.Asm.VirtualNetwork)selectedNode.Tag;

                    foreach (Azure.Asm.Subnet asmSubnet in asmVirtualNetwork.Subnets)
                    {
                        if (asmSubnet.NetworkSecurityGroup != null)
                        {
                            foreach (TreeNode treeNode in treeSourceASM.Nodes.Find(asmSubnet.NetworkSecurityGroup.Name, true))
                            {
                                if ((treeNode.Tag != null) && (treeNode.Tag.GetType() == typeof(Azure.Asm.NetworkSecurityGroup)))
                                {
                                    if (!treeNode.Checked)
                                    {
                                        treeNode.Checked = true;
                                    }
                                }
                            }
                        }
                    }
                }

                StatusProvider.UpdateStatus("Ready");
            }
        }
Beispiel #16
0
        private async Task _AzureContextSourceASM_AfterAzureSubscriptionChange(AzureContext sender)
        {
            ResetForm();

            try
            {
                if (sender.AzureSubscription != null)
                {
                    if (_AzureContextTargetARM.AzureSubscription == null)
                    {
                        await _AzureContextTargetARM.SetSubscriptionContext(_AzureContextSourceASM.AzureSubscription);
                    }

                    azureLoginContextViewerARM.Enabled = true;

                    this.TemplateGenerator.SourceSubscription = _AzureContextSourceASM.AzureSubscription;
                    this.TemplateGenerator.TargetSubscription = _AzureContextTargetARM.AzureSubscription;

                    #region Bind Source ASM Objects

                    TreeNode subscriptionNodeASM = new TreeNode(sender.AzureSubscription.Name);
                    treeSourceASM.Nodes.Add(subscriptionNodeASM);
                    subscriptionNodeASM.Expand();

                    List <Azure.Asm.VirtualNetwork> asmVirtualNetworks = await _AzureContextSourceASM.AzureRetriever.GetAzureAsmVirtualNetworks();

                    foreach (Azure.Asm.VirtualNetwork asmVirtualNetwork in asmVirtualNetworks)
                    {
                        if (asmVirtualNetwork.HasNonGatewaySubnet)
                        {
                            TreeNode parentNode       = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeASM, asmVirtualNetwork.Location, "Virtual Networks");
                            TreeNode tnVirtualNetwork = new TreeNode(asmVirtualNetwork.Name);
                            tnVirtualNetwork.Name = asmVirtualNetwork.Name;
                            tnVirtualNetwork.Tag  = asmVirtualNetwork;
                            parentNode.Nodes.Add(tnVirtualNetwork);
                            parentNode.Expand();
                        }
                    }

                    foreach (Azure.Asm.StorageAccount asmStorageAccount in await _AzureContextSourceASM.AzureRetriever.GetAzureAsmStorageAccounts())
                    {
                        TreeNode parentNode       = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeASM, asmStorageAccount.GeoPrimaryRegion, "Storage Accounts");
                        TreeNode tnStorageAccount = new TreeNode(asmStorageAccount.Name);
                        tnStorageAccount.Name = tnStorageAccount.Text;
                        tnStorageAccount.Tag  = asmStorageAccount;
                        parentNode.Nodes.Add(tnStorageAccount);
                        parentNode.Expand();
                    }

                    List <CloudService> asmCloudServices = await _AzureContextSourceASM.AzureRetriever.GetAzureAsmCloudServices();

                    foreach (CloudService asmCloudService in asmCloudServices)
                    {
                        foreach (Azure.Asm.VirtualMachine asmVirtualMachine in asmCloudService.VirtualMachines)
                        {
                            TreeNode   parentNode             = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeASM, asmCloudService.Location, "Cloud Services");
                            TreeNode[] cloudServiceNodeSearch = parentNode.Nodes.Find(asmCloudService.ServiceName, false);
                            TreeNode   cloudServiceNode       = null;
                            if (cloudServiceNodeSearch.Count() == 1)
                            {
                                cloudServiceNode = cloudServiceNodeSearch[0];
                            }

                            if (cloudServiceNode == null)
                            {
                                cloudServiceNode      = new TreeNode(asmCloudService.ServiceName);
                                cloudServiceNode.Name = asmCloudService.ServiceName;
                                cloudServiceNode.Tag  = asmCloudService;
                                parentNode.Nodes.Add(cloudServiceNode);
                                parentNode.Expand();
                            }

                            TreeNode virtualMachineNode = new TreeNode(asmVirtualMachine.RoleName);
                            virtualMachineNode.Name = asmVirtualMachine.RoleName;
                            virtualMachineNode.Tag  = asmVirtualMachine;
                            cloudServiceNode.Nodes.Add(virtualMachineNode);
                            cloudServiceNode.Expand();
                        }
                    }

                    foreach (Azure.Asm.NetworkSecurityGroup asmNetworkSecurityGroup in await _AzureContextSourceASM.AzureRetriever.GetAzureAsmNetworkSecurityGroups())
                    {
                        TreeNode parentNode       = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeASM, asmNetworkSecurityGroup.Location, "Network Security Groups");
                        TreeNode tnStorageAccount = new TreeNode(asmNetworkSecurityGroup.Name);
                        tnStorageAccount.Name = tnStorageAccount.Text;
                        tnStorageAccount.Tag  = asmNetworkSecurityGroup;
                        parentNode.Nodes.Add(tnStorageAccount);
                        parentNode.Expand();
                    }

                    subscriptionNodeASM.ExpandAll();

                    #endregion

                    #region Bind Source ARM Objects

                    TreeNode subscriptionNodeARM = new TreeNode("ARM Resources Coming Soon!!");
//                    TreeNode subscriptionNodeARM = new TreeNode(sender.AzureSubscription.Name);
                    treeSourceARM.Nodes.Add(subscriptionNodeARM);
                    subscriptionNodeARM.Expand();

                    //foreach (ResourceGroup armResourceGroup in await _AzureContextSourceASM.AzureRetriever.GetAzureARMResourceGroups())
                    //{

                    //}

                    //foreach (Azure.Arm.AvailabilitySet armAvailabilitySet in await _AzureContextSourceASM.AzureRetriever.GetAzureARMAvailabilitySets())
                    //{

                    //}

                    //List<Azure.Arm.VirtualNetwork> armVirtualNetworks = await _AzureContextSourceASM.AzureRetriever.GetAzureARMVirtualNetworks();
                    //foreach (Azure.Arm.VirtualNetwork armVirtualNetwork in armVirtualNetworks)
                    //{
                    //    if (armVirtualNetwork.HasNonGatewaySubnet)
                    //    {
                    //        TreeNode parentNode = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeARM, armVirtualNetwork.Location, "Virtual Networks");
                    //        TreeNode tnVirtualNetwork = new TreeNode(armVirtualNetwork.Name);
                    //        tnVirtualNetwork.Name = armVirtualNetwork.Name;
                    //        tnVirtualNetwork.Tag = armVirtualNetwork;
                    //        parentNode.Nodes.Add(tnVirtualNetwork);
                    //        parentNode.Expand();
                    //    }
                    //}

                    //foreach (Azure.Arm.StorageAccount armStorageAccount in await _AzureContextSourceASM.AzureRetriever.GetAzureARMStorageAccounts())
                    //{
                    //    TreeNode parentNode = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeARM, armStorageAccount.PrimaryLocation, "Storage Accounts");
                    //    TreeNode tnStorageAccount = new TreeNode(armStorageAccount.Name);
                    //    tnStorageAccount.Name = tnStorageAccount.Text;
                    //    tnStorageAccount.Tag = armStorageAccount;
                    //    parentNode.Nodes.Add(tnStorageAccount);
                    //    parentNode.Expand();
                    //}

                    //foreach (Azure.Arm.VirtualMachine armVirtualMachine in await _AzureContextSourceASM.AzureRetriever.GetAzureArmVirtualMachines())
                    //{
                    //    TreeNode parentNode = MigAzTreeView.GetDataCenterTreeViewNode(subscriptionNodeARM, armVirtualMachine.Location, "Virtual Machines");
                    //    TreeNode tnVirtualMachine = new TreeNode(armVirtualMachine.Name);
                    //    tnVirtualMachine.Name = tnVirtualMachine.Text;
                    //    tnVirtualMachine.Tag = armVirtualMachine;
                    //    parentNode.Nodes.Add(tnVirtualMachine);
                    //    parentNode.Expand();
                    //}

                    subscriptionNodeARM.ExpandAll();

                    #endregion

                    await ReadSubscriptionSettings(sender.AzureSubscription);

                    treeSourceASM.Enabled = true;
                    //treeSourceARM.Enabled = true;
                    treeTargetARM.Enabled = true;
                }
            }
            catch (Exception exc)
            {
                UnhandledExceptionDialog unhandledException = new UnhandledExceptionDialog(LogProvider, exc);
                unhandledException.ShowDialog();
            }

            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #17
0
        private void btnRefreshOutput_Click(object sender, EventArgs e)
        {
            SplitterPanel parent = (SplitterPanel)splitContainer2.Panel1;

            if (parent.Controls.Count == 1)
            {
                IMigratorUserControl migrator = (IMigratorUserControl)parent.Controls[0];

                if (migrator.TemplateGenerator.HasErrors)
                {
                    tabMigAzMonitoring.SelectTab("tabMessages");
                    MessageBox.Show("There are still one or more error(s) with the template generation.  Please resolve all errors before exporting.");
                    return;
                }

                migrator.TemplateGenerator.SerializeStreams();

                foreach (TabPage tabPage in tabOutputResults.TabPages)
                {
                    if (!migrator.TemplateGenerator.TemplateStreams.ContainsKey(tabPage.Name))
                    {
                        tabOutputResults.TabPages.Remove(tabPage);
                    }
                }

                foreach (var templateStream in migrator.TemplateGenerator.TemplateStreams)
                {
                    TabPage tabPage = null;
                    if (!tabOutputResults.TabPages.ContainsKey(templateStream.Key))
                    {
                        tabPage      = new TabPage(templateStream.Key);
                        tabPage.Name = templateStream.Key;
                        tabOutputResults.TabPages.Add(tabPage);

                        if (templateStream.Key.EndsWith(".html"))
                        {
                            WebBrowser webBrowser = new WebBrowser();
                            webBrowser.Width             = tabOutputResults.Width - 15;
                            webBrowser.Height            = tabOutputResults.Height - 30;
                            webBrowser.AllowNavigation   = false;
                            webBrowser.ScrollBarsEnabled = true;
                            tabPage.Controls.Add(webBrowser);
                        }
                        else if (templateStream.Key.EndsWith(".json"))
                        {
                            TextBox textBox = new TextBox();
                            textBox.Width      = tabOutputResults.Width - 15;
                            textBox.Height     = tabOutputResults.Height - 30;
                            textBox.ReadOnly   = true;
                            textBox.Multiline  = true;
                            textBox.WordWrap   = false;
                            textBox.ScrollBars = ScrollBars.Both;
                            tabPage.Controls.Add(textBox);
                        }
                    }
                    else
                    {
                        tabPage = tabOutputResults.TabPages[templateStream.Key];
                    }

                    if (tabPage.Controls[0].GetType() == typeof(TextBox))
                    {
                        TextBox textBox = (TextBox)tabPage.Controls[0];
                        templateStream.Value.Position = 0;
                        textBox.Text = new StreamReader(templateStream.Value).ReadToEnd();
                    }
                    else if (tabPage.Controls[0].GetType() == typeof(WebBrowser))
                    {
                        WebBrowser webBrowser = (WebBrowser)tabPage.Controls[0];
                        templateStream.Value.Position = 0;
                        webBrowser.DocumentText       = new StreamReader(templateStream.Value).ReadToEnd();
                    }
                }

                lblLastOutputRefresh.Text = "Last Refresh Completed: " + DateTime.Now.ToString();
                btnRefreshOutput.Enabled  = false;

                // post Telemetry Record to ASMtoARMToolAPI
                if (AppSettingsProvider.AllowTelemetry)
                {
                    StatusProvider.UpdateStatus("BUSY: saving telemetry information");
                    migrator.PostTelemetryRecord();
                }
            }
        }