Ejemplo n.º 1
0
        public void Read(string AWSRegion, ref ListView lvwVirtualNetworks, ref ListView lvwVirtualMachines)
        {
            try
            {
                StreamReader saveSelectionReader = new StreamReader(filePath);
                string       jsontext            = saveSelectionReader.ReadToEnd();
                saveSelectionReader.Close();

                saveSelections = JsonConvert.DeserializeObject <List <SaveSelection> >(jsontext);
            }
            catch
            {
                // If file does not exist, or invalid, starts a new object
                saveSelections = new List <SaveSelection>();
            }

            if (saveSelections.Exists(x => x.AWSRegion == AWSRegion))
            {
                SaveSelection saveSelection = saveSelections.Find(x => x.AWSRegion == AWSRegion);

                foreach (string virtualNetwork in saveSelection.VirtualNetworks)
                {
                    lvwVirtualNetworks.FindItemWithText(virtualNetwork).Checked = true;
                }


                foreach (SaveSelectioVirtualMachine saveSelectionVirtualMachine in saveSelection.VirtualMachines)
                {
                    int startAt = lvwVirtualMachines.FindItemWithText(saveSelectionVirtualMachine.InstanceId).Index;
                    lvwVirtualMachines.FindItemWithText(saveSelectionVirtualMachine.InstanceName, true, startAt).Checked = true;
                }
            }
        }
 public void SaveScreenShot()
 {
     Model.CurrentTopLeft     = _currentTopLeft;
     Model.CurrentBottomRight = _currentBottomRight;
     SaveSelection?.Invoke(this, EventArgs.Empty);
     ImageLocation = Model.NewImageLocation;
     DialogResult  = DialogResult.OK;
 }
Ejemplo n.º 3
0
        public void Save(string AWSRegion, ListView lvwVirtualNetworks, ListView lvwVirtualMachines)
        {
            string jsontext = "";

            try
            {
                StreamReader saveSelectionReader = new StreamReader(filePath);
                jsontext = saveSelectionReader.ReadToEnd();
                saveSelectionReader.Close();

                saveSelections = JsonConvert.DeserializeObject <List <SaveSelection> >(jsontext);

                // If save selection for this subscription alredy exists, remove it
                if (saveSelections.Exists(x => x.AWSRegion == AWSRegion))
                {
                    saveSelections.Remove(saveSelections.Find(x => x.AWSRegion == AWSRegion));
                }
            }
            catch
            {
                // If file does not exist, or invalid, starts a new object
                saveSelections = new List <SaveSelection>();
            }

            SaveSelection saveSelection = new SaveSelection();

            saveSelection.AWSRegion = AWSRegion;

            saveSelection.VirtualNetworks = new List <string>();
            foreach (ListViewItem virtualNetwork in lvwVirtualNetworks.CheckedItems)
            {
                saveSelection.VirtualNetworks.Add(virtualNetwork.Text);
            }


            saveSelection.VirtualMachines = new List <SaveSelectioVirtualMachine>();
            foreach (ListViewItem virtualMachine in lvwVirtualMachines.CheckedItems)
            {
                SaveSelectioVirtualMachine saveSelectionVirtualMachine = new SaveSelectioVirtualMachine();
                saveSelectionVirtualMachine.InstanceId   = virtualMachine.SubItems[0].Text;
                saveSelectionVirtualMachine.InstanceName = virtualMachine.SubItems[1].Text;

                saveSelection.VirtualMachines.Add(saveSelectionVirtualMachine);
            }

            saveSelections.Add(saveSelection);

            // save blob copy details file
            jsontext = JsonConvert.SerializeObject(saveSelections, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });

            StreamWriter saveSelectionWriter = new StreamWriter(filePath);

            saveSelectionWriter.Write(jsontext);
            saveSelectionWriter.Close();
        }
Ejemplo n.º 4
0
        public void Read(Guid subscriptionId, ref ListView lvwVirtualNetworks, ref ListView lvwStorageAccounts, ref ListView lvwVirtualMachines)
        {
            try
            {
                StreamReader saveSelectionReader = new StreamReader(filePath);
                string       jsontext            = saveSelectionReader.ReadToEnd();
                saveSelectionReader.Close();

                saveSelections = JsonConvert.DeserializeObject <List <SaveSelection> >(jsontext);
            }
            catch
            {
                // If file does not exist, or invalid, starts a new object
                saveSelections = new List <SaveSelection>();
            }

            if (saveSelections.Exists(x => x.SubscriptionId == subscriptionId))
            {
                SaveSelection saveSelection = saveSelections.Find(x => x.SubscriptionId == subscriptionId);

                foreach (string virtualNetwork in saveSelection.VirtualNetworks)
                {
                    lvwVirtualNetworks.FindItemWithText(virtualNetwork).Checked = true;
                }

                foreach (string storageAccount in saveSelection.StorageAccounts)
                {
                    lvwStorageAccounts.FindItemWithText(storageAccount).Checked = true;
                }

                foreach (SaveSelectioVirtualMachine saveSelectionVirtualMachine in saveSelection.VirtualMachines)
                {
                    int startAt = lvwVirtualMachines.FindItemWithText(saveSelectionVirtualMachine.CloudService).Index;
                    lvwVirtualMachines.FindItemWithText(saveSelectionVirtualMachine.VirtualMachine, true, startAt).Checked = true;
                }
            }
        }
        public async Task Save(Guid subscriptionId, List <TreeNode> selectedNodes)
        {
            string jsontext = String.Empty;

            try
            {
                StreamReader saveSelectionReader = new StreamReader(filePath);
                jsontext = saveSelectionReader.ReadToEnd();
                saveSelectionReader.Close();

                saveSelections = JsonConvert.DeserializeObject <List <SaveSelection> >(jsontext);

                // If save selection for this subscription alredy exists, remove it
                if (saveSelections.Exists(x => x.SubscriptionId == subscriptionId))
                {
                    saveSelections.Remove(saveSelections.Find(x => x.SubscriptionId == subscriptionId));
                }
            }
            catch
            {
                // If file does not exist, or invalid, starts a new object
                saveSelections = new List <SaveSelection>();
            }

            SaveSelection saveSelection = new SaveSelection();

            saveSelection.SubscriptionId = subscriptionId;

            saveSelection.VirtualNetworks = new List <SaveSelectionVirtualNetwork>();
            saveSelection.StorageAccounts = new List <SaveSelectioStorageAccount>();
            saveSelection.VirtualMachines = new List <SaveSelectionVirtualMachine>();

            if (selectedNodes != null)
            {
                foreach (TreeNode treeNode in selectedNodes)
                {
                    if (treeNode.Tag != null)
                    {
                        Type tagType = treeNode.Tag.GetType();
                        if (tagType == typeof(Azure.Asm.VirtualNetwork))
                        {
                            Azure.Asm.VirtualNetwork asmVirtualNetwork = (Azure.Asm.VirtualNetwork)treeNode.Tag;

                            SaveSelectionVirtualNetwork saveSelectionVirtualNetwork = new SaveSelectionVirtualNetwork();
                            saveSelectionVirtualNetwork.VirtualNetworkName = asmVirtualNetwork.Name;

                            saveSelection.VirtualNetworks.Add(saveSelectionVirtualNetwork);
                        }
                        else if (tagType == typeof(Azure.Asm.StorageAccount))
                        {
                            Azure.Asm.StorageAccount asmStorageAccount = (Azure.Asm.StorageAccount)treeNode.Tag;

                            SaveSelectioStorageAccount saveSelectionStorageAccount = new SaveSelectioStorageAccount();
                            saveSelectionStorageAccount.StorageAccountName       = asmStorageAccount.Name;
                            saveSelectionStorageAccount.TargetStorageAccountName = asmStorageAccount.TargetName;

                            saveSelection.StorageAccounts.Add(saveSelectionStorageAccount);
                        }
                        else if (tagType == typeof(Azure.Asm.VirtualMachine))
                        {
                            Azure.Asm.VirtualMachine asmVirtualMachine = (Azure.Asm.VirtualMachine)treeNode.Tag;

                            SaveSelectionVirtualMachine saveSelectionVirtualMachine = new SaveSelectionVirtualMachine();
                            saveSelectionVirtualMachine.CloudService   = asmVirtualMachine.CloudServiceName;
                            saveSelectionVirtualMachine.VirtualMachine = asmVirtualMachine.RoleName;

                            if (asmVirtualMachine.TargetVirtualNetwork != null)
                            {
                                saveSelectionVirtualMachine.TargetVirtualNetwork = asmVirtualMachine.TargetVirtualNetwork.Id;
                            }

                            if (asmVirtualMachine.TargetSubnet != null)
                            {
                                saveSelectionVirtualMachine.TargetSubnet = asmVirtualMachine.TargetSubnet.Id;
                            }

                            // Add OS Disk Target Storage Account
                            if (asmVirtualMachine.OSVirtualHardDisk.TargetStorageAccount != null)
                            {
                                saveSelectionVirtualMachine.TargetDiskStorageAccounts.Add(asmVirtualMachine.OSVirtualHardDisk.DiskName, asmVirtualMachine.OSVirtualHardDisk.TargetStorageAccount.Id);
                            }

                            // Add OS Disk Target Storage Account
                            foreach (Azure.Asm.Disk asmDataDisk in asmVirtualMachine.DataDisks)
                            {
                                if (asmDataDisk.TargetStorageAccount != null)
                                {
                                    saveSelectionVirtualMachine.TargetDiskStorageAccounts.Add(asmDataDisk.DiskName, asmDataDisk.TargetStorageAccount.Id);
                                }
                            }

                            saveSelection.VirtualMachines.Add(saveSelectionVirtualMachine);
                        }
                    }
                }
            }

            saveSelections.Add(saveSelection);

            // save blob copy details file
            jsontext = JsonConvert.SerializeObject(saveSelections, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            });

            StreamWriter saveSelectionWriter = new StreamWriter(filePath);

            saveSelectionWriter.Write(jsontext);
            saveSelectionWriter.Close();
        }
        public async Task Read(Guid subscriptionId, AzureRetriever sourceAzureRetreiver, AzureRetriever targetAzureRetreiver, TreeView treeView)
        {
            try
            {
                StreamReader saveSelectionReader = new StreamReader(filePath);
                string       jsontext            = saveSelectionReader.ReadToEnd();
                saveSelectionReader.Close();

                saveSelections = JsonConvert.DeserializeObject <List <SaveSelection> >(jsontext);
            }
            catch
            {
                // If file does not exist, or invalid, starts a new object
                saveSelections = new List <SaveSelection>();
            }

            if (saveSelections.Exists(x => x.SubscriptionId == subscriptionId))
            {
                SaveSelection saveSelection = saveSelections.Find(x => x.SubscriptionId == subscriptionId);

                foreach (SaveSelectionVirtualNetwork saveSelectionVirtualNetwork in saveSelection.VirtualNetworks)
                {
                    foreach (TreeNode treeNode in treeView.Nodes.Find(saveSelectionVirtualNetwork.VirtualNetworkName, true))
                    {
                        if (treeNode.Tag.GetType() == typeof(Azure.Asm.VirtualNetwork))
                        {
                            Azure.Asm.VirtualNetwork asmVirtualNetwork = (Azure.Asm.VirtualNetwork)treeNode.Tag;

                            treeNode.Checked = true;
                        }
                    }
                }

                foreach (SaveSelectioStorageAccount saveSelectionStorageAccount in saveSelection.StorageAccounts)
                {
                    foreach (TreeNode treeNode in treeView.Nodes.Find(saveSelectionStorageAccount.StorageAccountName, true))
                    {
                        if (treeNode.Tag.GetType() == typeof(Azure.Asm.StorageAccount))
                        {
                            Azure.Asm.StorageAccount asmStorageAccount = (Azure.Asm.StorageAccount)treeNode.Tag;
                            if (saveSelectionStorageAccount.TargetStorageAccountName.Length > 0) // We aren't going to reload a blank name, should it occur, as a name is required
                            {
                                asmStorageAccount.TargetName = saveSelectionStorageAccount.TargetStorageAccountName;
                            }
                            treeNode.Checked = true;
                        }
                    }
                }

                foreach (SaveSelectionVirtualMachine saveSelectionVirtualMachine in saveSelection.VirtualMachines)
                {
                    foreach (TreeNode virtualMachineNode in treeView.Nodes.Find(saveSelectionVirtualMachine.VirtualMachine, true))
                    {
                        if (virtualMachineNode.Tag != null)
                        {
                            if (virtualMachineNode.Tag.GetType() == typeof(Azure.Asm.VirtualMachine))
                            {
                                Azure.Asm.VirtualMachine asmVirtualMachine = (Azure.Asm.VirtualMachine)virtualMachineNode.Tag;

                                if (asmVirtualMachine.CloudServiceName == saveSelectionVirtualMachine.CloudService && asmVirtualMachine.RoleName == saveSelectionVirtualMachine.VirtualMachine)
                                {
                                    asmVirtualMachine.TargetVirtualNetwork = SeekVirtualNetwork(saveSelectionVirtualMachine.TargetVirtualNetwork, await sourceAzureRetreiver.GetAzureAsmVirtualNetworks(), await targetAzureRetreiver.GetAzureARMVirtualNetworks());
                                    asmVirtualMachine.TargetSubnet         = SeekSubnet(saveSelectionVirtualMachine.TargetSubnet, asmVirtualMachine.TargetVirtualNetwork);

                                    if (saveSelectionVirtualMachine.TargetDiskStorageAccounts.ContainsKey(asmVirtualMachine.OSVirtualHardDisk.DiskName))
                                    {
                                        asmVirtualMachine.OSVirtualHardDisk.TargetStorageAccount = SeekStorageAccount(saveSelectionVirtualMachine.TargetDiskStorageAccounts[asmVirtualMachine.OSVirtualHardDisk.DiskName].ToString(), await sourceAzureRetreiver.GetAzureAsmStorageAccounts(), await targetAzureRetreiver.GetAzureARMStorageAccounts());
                                    }

                                    foreach (Azure.Asm.Disk asmDataDisk in asmVirtualMachine.DataDisks)
                                    {
                                        if (saveSelectionVirtualMachine.TargetDiskStorageAccounts.ContainsKey(asmDataDisk.DiskName))
                                        {
                                            asmDataDisk.TargetStorageAccount = SeekStorageAccount(saveSelectionVirtualMachine.TargetDiskStorageAccounts[asmDataDisk.DiskName].ToString(), await sourceAzureRetreiver.GetAzureAsmStorageAccounts(), await targetAzureRetreiver.GetAzureARMStorageAccounts());
                                        }
                                    }

                                    virtualMachineNode.Checked = true;
                                }
                            }
                        }
                    }
                }
            }
        }