private void txtTargetName_TextChanged(object sender, EventArgs e) { TextBox txtSender = (TextBox)sender; TreeNode asmNetworkSecurityGroupNode = (TreeNode)_NetworkSecurityGroupNode.Tag; AsmNetworkSecurityGroup asmNetworkSecurityGroup = (AsmNetworkSecurityGroup)asmNetworkSecurityGroupNode.Tag; asmNetworkSecurityGroup.TargetName = txtSender.Text; _NetworkSecurityGroupNode.Text = asmNetworkSecurityGroup.GetFinalTargetName(); }
internal void Bind(TreeNode networkSecurityGroupNode, AsmToArmForm asmToArmForm) { _NetworkSecurityGroupNode = networkSecurityGroupNode; TreeNode asmNetworkSecurityGroupNode = (TreeNode)_NetworkSecurityGroupNode.Tag; AsmNetworkSecurityGroup asmNetworkSecurityGroup = (AsmNetworkSecurityGroup)asmNetworkSecurityGroupNode.Tag; lblSourceName.Text = asmNetworkSecurityGroup.Name; txtTargetName.Text = asmNetworkSecurityGroup.TargetName; }
public async virtual Task <AsmNetworkSecurityGroup> GetAzureAsmNetworkSecurityGroup(string networkSecurityGroupName) { Hashtable networkSecurityGroupInfo = new Hashtable(); networkSecurityGroupInfo.Add("name", networkSecurityGroupName); XmlNode networkSecurityGroupXml = await this.GetAzureAsmResources("NetworkSecurityGroup", networkSecurityGroupInfo); AsmNetworkSecurityGroup asmNetworkSecurityGroup = new AsmNetworkSecurityGroup(_AzureContext, networkSecurityGroupXml.SelectSingleNode("NetworkSecurityGroup")); return(asmNetworkSecurityGroup); }
public async virtual Task <List <AsmNetworkSecurityGroup> > GetAzureAsmNetworkSecurityGroups() { List <AsmNetworkSecurityGroup> networkSecurityGroups = new List <AsmNetworkSecurityGroup>(); XmlDocument x = await this.GetAzureAsmResources("NetworkSecurityGroups", null); foreach (XmlNode networkSecurityGroupNode in (await this.GetAzureAsmResources("NetworkSecurityGroups", null)).SelectNodes("//NetworkSecurityGroup")) { AsmNetworkSecurityGroup asmNetworkSecurityGroup = new AsmNetworkSecurityGroup(_AzureContext, networkSecurityGroupNode); networkSecurityGroups.Add(asmNetworkSecurityGroup); } return(networkSecurityGroups); }
public async void LoadDocuments(string path) { string[] files = Directory.GetFiles(path, "*.xml"); Array.Sort(files); foreach (var filename in files) { var doc = new XmlDocument(); doc.Load(filename); var title = Path.GetFileNameWithoutExtension(filename); var parts = title.Split('-'); string resourceType; var info = new Hashtable(); switch (parts[1].ToLower()) { case "azurelocations": resourceType = "azurelocations"; foreach (XmlNode azureLocationXml in doc.SelectNodes("/Locations/Location")) { _AzureASMLocations.Add(new AsmLocation(_AzureContext, azureLocationXml)); } break; case "cloudservice": resourceType = "CloudService"; info.Add("name", parts[2]); _CloudServices.Add(new AsmCloudService(_AzureContext, doc)); break; case "virtualmachine": resourceType = "VirtualMachine"; info.Add("cloudservicename", parts[2]); info.Add("virtualmachinename", parts[3]); info.Add("deploymentname", parts[4]); info.Add("loadbalancername", String.Empty); info.Add("virtualnetworkname", String.Empty); AsmCloudService parentCloudService = this.GetAzureAsmCloudService(parts[2]).Result; AsmVirtualMachine asmVirtualMachine = new AsmVirtualMachine(_AzureContext, parentCloudService, this._AzureContext.SettingsProvider, doc, info); await asmVirtualMachine.InitializeChildren(); asmVirtualMachine.OSVirtualHardDisk.TargetStorageAccount = asmVirtualMachine.OSVirtualHardDisk.SourceStorageAccount; asmVirtualMachine.TargetVirtualNetwork = asmVirtualMachine.SourceVirtualNetwork; asmVirtualMachine.TargetSubnet = asmVirtualMachine.SourceSubnet; foreach (AsmDisk dataDisk in asmVirtualMachine.DataDisks) { dataDisk.TargetStorageAccount = dataDisk.SourceStorageAccount; } parentCloudService.VirtualMachines.Add(asmVirtualMachine); break; case "storageaccountkeys": resourceType = "StorageAccountKeys"; info.Add("name", parts[2]); this.GetAzureAsmStorageAccount(parts[2]).Result.Keys = new AsmStorageAccountKeys(_AzureContext, doc); break; case "storageaccount": resourceType = "StorageAccount"; info.Add("name", parts[2]); _StorageAccounts.Add(new AsmStorageAccount(_AzureContext, doc)); break; case "virtualnetworks": resourceType = "VirtualNetworks"; foreach (XmlNode virtualnetworksite in doc.SelectNodes("//VirtualNetworkSite")) { AsmVirtualNetwork asmVirtualNetwork = new AsmVirtualNetwork(_AzureContext, virtualnetworksite); await asmVirtualNetwork.InitializeChildrenAsync(); _VirtualNetworks.Add(asmVirtualNetwork); } break; case "clientrootcertificates": resourceType = "ClientRootCertificates"; info.Add("virtualnetworkname", parts[2]); foreach (XmlNode clientRootCertificateXml in doc.SelectNodes("//ClientRootCertificate")) { _ClientRootCertificates.Add(new AsmClientRootCertificate(_AzureContext, _VirtualNetworks[0], clientRootCertificateXml)); } break; case "clientrootcertificate": resourceType = "ClientRootCertificate"; info.Add("virtualnetworkname", parts[2]); info.Add("thumbprint", parts[3]); break; case "virtualnetworkgateway": resourceType = "VirtualNetworkGateway"; info.Add("virtualnetworkname", parts[2]); _VirtualNetworkGateway = new AsmVirtualNetworkGateway(_AzureContext, _VirtualNetworks[0], doc); _VirtualNetworks[0].Gateway = _VirtualNetworkGateway; break; case "virtualnetworkgatewaysharedkey": resourceType = "VirtualNetworkGatewaySharedKey"; info.Add("virtualnetworkname", parts[2]); info.Add("localnetworksitename", parts[3]); break; case "networksecuritygroup": resourceType = "NetworkSecurityGroup"; info.Add("name", parts[2]); _NetworkSecurityGroup = new AsmNetworkSecurityGroup(_AzureContext, doc.SelectSingleNode("NetworkSecurityGroup")); break; case "routetable": resourceType = "RouteTable"; info.Add("name", parts[2]); _AsmRouteTable = new AsmRouteTable(_AzureContext, doc); break; case "reservedips": resourceType = "ReservedIPs"; break; default: throw new Exception(); } SetResponse(resourceType, info, doc); } }
private bool RecursiveHealthCheckNode(TreeNode treeNode) { if (treeNode.Tag != null) { if (treeNode.Tag.GetType() == typeof(ArmResourceGroup)) { ArmResourceGroup armResourceGroup = (ArmResourceGroup)treeNode.Tag; if (armResourceGroup.Location == null) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Location must be selected before exporting."); return(false); } } else if (treeNode.Tag.GetType() == typeof(TreeNode)) // Tag is the sourced ASM TreeNode { TreeNode asmTreeNode = (TreeNode)treeNode.Tag; if (asmTreeNode.Tag != null) { if (asmTreeNode.Tag.GetType() == typeof(AsmNetworkSecurityGroup)) { AsmNetworkSecurityGroup asmNetworkSecurityGroup = (AsmNetworkSecurityGroup)asmTreeNode.Tag; // Validate the Target Name is not blank if (asmNetworkSecurityGroup.TargetName == String.Empty) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Name must be selected before exporting."); return(false); } } else if (asmTreeNode.Tag.GetType() == typeof(AsmVirtualNetwork)) { AsmVirtualNetwork asmVirtualNetwork = (AsmVirtualNetwork)asmTreeNode.Tag; // Validate the Target Name is not blank if (asmVirtualNetwork.TargetName == String.Empty) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Name must be selected before exporting."); return(false); } foreach (TreeNode virtualNetworkNode in treeNode.Parent.Nodes) { TreeNode asmVirtualNetworkNode = (TreeNode)virtualNetworkNode.Tag; AsmVirtualNetwork asmVirtualNetworkCompare = (AsmVirtualNetwork)asmVirtualNetworkNode.Tag; if (asmVirtualNetworkCompare.Name != asmVirtualNetwork.Name && asmVirtualNetworkCompare.TargetName == asmVirtualNetwork.TargetName) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Names must be unique to migrate Virtual Networks."); return(false); } } } else if (asmTreeNode.Tag.GetType() == typeof(AsmVirtualMachine)) { AsmVirtualMachine asmVirtualMachine = (AsmVirtualMachine)asmTreeNode.Tag; if (asmVirtualMachine.TargetName == String.Empty) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Name for Virtual Machine must be specified."); return(false); } if (asmVirtualMachine.TargetAvailabilitySet == null) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Availability Set for Virtual Machine must be specified."); return(false); } if (asmVirtualMachine.TargetVirtualNetwork == null) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Virtual Network for Virtual Machine must be specified."); return(false); } if (asmVirtualMachine.TargetSubnet == null) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Subnet for Virtual Machine must be specified."); return(false); } if (asmVirtualMachine.OSVirtualHardDisk.TargetStorageAccount == null) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target VM OS Disk Storage Account must be specified."); return(false); } } else if (asmTreeNode.Tag.GetType() == typeof(AsmStorageAccount)) { AsmStorageAccount asmStorageAccount = (AsmStorageAccount)asmTreeNode.Tag; if (asmStorageAccount.TargetName == String.Empty) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Storage Account Name must be specified."); return(false); } } } } else if (treeNode.Tag.GetType() == typeof(AsmSubnet)) { AsmSubnet asmSubnet = (AsmSubnet)treeNode.Tag; if (asmSubnet.TargetName == String.Empty) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Subnet Name must be specified."); return(false); } } else if (treeNode.Tag.GetType() == typeof(ArmAvailabilitySet)) { ArmAvailabilitySet armAvailabilitySet = (ArmAvailabilitySet)treeNode.Tag; if (armAvailabilitySet.TargetName == String.Empty) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target Availability Set Name must be specified."); return(false); } } else if (treeNode.Tag.GetType() == typeof(AsmDisk)) { AsmDisk asmDisk = (AsmDisk)treeNode.Tag; if (asmDisk.TargetStorageAccount == null) { treeARM.SelectedNode = treeNode; this.Refresh(); MessageBox.Show("Target VM Data Disk Storage Account must be specified."); return(false); } } } foreach (TreeNode childNode in treeNode.Nodes) { bool nodeResult = RecursiveHealthCheckNode(childNode); if (nodeResult == false) { return(false); } } return(true); }
private async Task AddASMNodeToARMTree(TreeNode asmTreeNode) { TreeNode targetResourceGroupNode = SeekARMChildTreeNode(treeARM.Nodes, _TargetResourceGroup.Name, _TargetResourceGroup.Name, _TargetResourceGroup, true); Type tagType = asmTreeNode.Tag.GetType(); if (tagType == typeof(AsmVirtualNetwork)) { AsmVirtualNetwork asmVirtualNetwork = (AsmVirtualNetwork)asmTreeNode.Tag; TreeNode virtualNetworksNode = SeekARMChildTreeNode(targetResourceGroupNode.Nodes, "Virtual Networks", "Virtual Networks", "Virtual Networks", true); TreeNode virtualNetworkNode = SeekARMChildTreeNode(virtualNetworksNode.Nodes, asmTreeNode.Name, asmVirtualNetwork.GetFinalTargetName(), asmTreeNode, true); foreach (AsmSubnet asmSubnet in asmVirtualNetwork.Subnets) { // Property dialog not made available for Gateway Subnet if (!asmSubnet.IsGatewaySubnet) { TreeNode subnetNode = SeekARMChildTreeNode(virtualNetworkNode.Nodes, asmSubnet.Name, asmSubnet.Name, asmSubnet, true); } } virtualNetworkNode.ExpandAll(); treeARM.SelectedNode = virtualNetworkNode; treeARM.Focus(); } else if (tagType == typeof(AsmStorageAccount)) { AsmStorageAccount asmStorageAccount = (AsmStorageAccount)asmTreeNode.Tag; TreeNode storageAccountsNode = SeekARMChildTreeNode(targetResourceGroupNode.Nodes, "Storage Accounts", "Storage Accounts", "Storage Accounts", true); TreeNode storageAccountNode = SeekARMChildTreeNode(storageAccountsNode.Nodes, asmTreeNode.Name, asmStorageAccount.GetFinalTargetName(), asmTreeNode, true); treeARM.SelectedNode = storageAccountNode; treeARM.Focus(); } else if (tagType == typeof(AsmVirtualMachine)) { AsmVirtualMachine asmVirtualMachine = (AsmVirtualMachine)asmTreeNode.Tag; TreeNode availabilitySets = SeekARMChildTreeNode(targetResourceGroupNode.Nodes, "Availability Sets", "Availability Sets", "Availability Sets", true); TreeNode availabilitySet = SeekARMChildTreeNode(availabilitySets.Nodes, asmVirtualMachine.TargetAvailabilitySet.TargetName, asmVirtualMachine.TargetAvailabilitySet.GetFinalTargetName(), asmVirtualMachine.TargetAvailabilitySet, true); TreeNode virtualMachineNode = SeekARMChildTreeNode(availabilitySet.Nodes, asmVirtualMachine.RoleName, asmVirtualMachine.RoleName, asmTreeNode, true); foreach (AsmDisk asmDataDisk in asmVirtualMachine.DataDisks) { TreeNode dataDiskNode = SeekARMChildTreeNode(virtualMachineNode.Nodes, asmDataDisk.DiskName, asmDataDisk.DiskName, asmDataDisk, true); } foreach (AsmNetworkInterface asmNetworkInterface in asmVirtualMachine.NetworkInterfaces) { TreeNode dataDiskNode = SeekARMChildTreeNode(virtualMachineNode.Nodes, asmNetworkInterface.Name, asmNetworkInterface.Name, asmNetworkInterface, true); } treeARM.SelectedNode = virtualMachineNode; treeARM.Focus(); } else if (tagType == typeof(AsmNetworkSecurityGroup)) { AsmNetworkSecurityGroup asmNetworkSecurityGroup = (AsmNetworkSecurityGroup)asmTreeNode.Tag; TreeNode networkSecurityGroups = SeekARMChildTreeNode(targetResourceGroupNode.Nodes, "Network Security Groups", "Network Security Groups", "Network Security Groups", true); TreeNode networkSecurityGroupNode = SeekARMChildTreeNode(networkSecurityGroups.Nodes, asmNetworkSecurityGroup.Name, asmNetworkSecurityGroup.Name, asmTreeNode, true); treeARM.SelectedNode = networkSecurityGroupNode; treeARM.Focus(); } else { throw new Exception("Unhandled Node Type: " + tagType); } }