Example #1
0
        private void txtNewVMPath_TextChanged(object sender, System.EventArgs e)
        {
            string deviceID      = txtNewVMPath.Text.Substring(0, 1);
            long   FreeDiskSpace = 0;

            try
            {
                ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\'" + deviceID + ":'", null);;
                disk.Get();
                FreeDiskSpace = long.Parse(disk["FreeSpace"].ToString());
            }
            catch (Exception err)
            {
                btnDupVM.Enabled       = true;
                lblFreeSpace.Text      = "Unable to read free disk space on the destination drive. You may not be able to duplication VM.";
                lblFreeSpace.ForeColor = Color.Red;
                return;
            }


            VMHardDisk vhd     = null;
            long       vhdSize = 0;

            for (int i = 1; i <= vm.HardDiskConnections.Count; i++)
            {
                vhd      = vm.HardDiskConnections[i].HardDisk;
                vhdSize += long.Parse(vhd.SizeOnHost.ToString());
            }

            if (vhdSize > FreeDiskSpace)
            {
                btnDupVM.Enabled  = false;
                lblFreeSpace.Text = "Destination Drive has no enough space! \nAvailable space: " + Utility.ConvertByteToString(FreeDiskSpace.ToString())
                                    + " only. To duplicate this VM, the destination disk must have at least " + Utility.ConvertByteToString(vhdSize.ToString()) + ". Please free at least " + Utility.ConvertByteToString((vhdSize - FreeDiskSpace) + "")
                                    + " or save it to another disk.";
                lblFreeSpace.ForeColor = Color.Red;
            }
            else
            {
                btnDupVM.Enabled       = true;
                lblFreeSpace.Text      = Utility.ConvertByteToString((FreeDiskSpace - vhdSize) + "");
                lblFreeSpace.ForeColor = Color.Black;
            }
        }
Example #2
0
        private void frmDupVM_Load(object sender, System.EventArgs e)
        {
            // Load current VM information
            lblVMName.Text  = vm.Name;
            lblVMState.Text = Utility.ConvertVMStateToString(vm.State);
            FileInfo fi = new FileInfo(vm.File);

            lblVMPath.Text = fi.Directory.FullName;

            VMHardDisk vhd     = null;
            long       vhdSize = 0;

            for (int i = 1; i <= vm.HardDiskConnections.Count; i++)
            {
                vhd      = vm.HardDiskConnections[i].HardDisk;
                vhdSize += long.Parse(vhd.SizeOnHost.ToString());
            }
            lblVMSize.Text = Utility.ConvertByteToString(vhdSize.ToString());

            // Prepare for destination VM
            txtNewVMName.Text = lblVMName.Text + "-1";
            txtNewVMPath.Text = lblVMPath.Text + "-1";
        }