Пример #1
0
 private void RefreshBackground()
 {
     SetStatus("Busy.");
     new BackgroundWorkerQueueDialog("Loading servers...", ProgressBarStyle.Marquee)
     .AppendTask("Connecting machines...", DummyWorker.GetWorker((ctx) => RefreshCollections(ctx)))
     .ShowDialog();
     SetStatus("Ready.");
 }
Пример #2
0
 private void StopVmms(string host)
 {
     SetStatus("Busy.");
     new BackgroundWorkerQueueDialog("Stopping service...")
     .AppendTask("Stopping vmms...", DummyWorker.GetWorker((ctx) =>
                                                           Interface.StopService(host, "vmms", PsStreamEventHandlers.GetUIHandlers(ctx))
                                                           )).ShowDialog();
     Thread.Sleep(1000);
     SetStatus("Ready.");
 }
Пример #3
0
        private void suspendToolButton_Click(object sender, EventArgs e)
        {
            var node = treeListView.SelectedObject as MasterTreeNode;

            if (node == null)
            {
                return;
            }
            new BackgroundWorkerQueueDialog("Setting machine state...")
            .AppendTask("", DummyWorker.GetWorker((ctx) =>
                                                  HyperV.SuspendVm(node.Host, node.Name, PsStreamEventHandlers.GetUIHandlers(ctx))
                                                  )).ShowDialog();
            RefreshBackground();
        }
Пример #4
0
        private void MainFrm_Load(object sender, EventArgs e)
        {
            if (GetAuthentication() != DialogResult.OK)
            {
                this.Close();
            }

            // Initialize tree
            SetupMasterTree();
            var backgroundWorker = new BackgroundWorkerQueueDialog("Loading servers...", ProgressBarStyle.Marquee);

            backgroundWorker.AppendTask("Connecting machines...", DummyWorker.GetWorker(() => RefreshCollections()));
            backgroundWorker.ShowDialog(FormStartPosition.CenterScreen);
        }
Пример #5
0
        private void startToolButton_Click(object sender, EventArgs e)
        {
            var node = treeListView.SelectedObject as MasterTreeNode;

            if (node == null)
            {
                return;
            }
            BackgroundWorkerQueueDialog bg = new BackgroundWorkerQueueDialog("Setting machine state...");

            if (node.State?.vs == VirtualMachineState.Paused)
            {
                bg.AppendTask("", DummyWorker.GetWorker((ctx) => HyperV.ResumeVm(node.Host, node.Name, PsStreamEventHandlers.GetUIHandlers(ctx))));
            }
            else
            {
                bg.AppendTask("", DummyWorker.GetWorker((ctx) => HyperV.StartVm(node.Host, node.Name, PsStreamEventHandlers.GetUIHandlers(ctx))));
            }
            bg.ShowDialog();
            RefreshBackground();
        }
Пример #6
0
        public InspectDiskDialog(string computer, string path)
        {
            InitializeComponent();
            var bg = new BackgroundWorkerQueueDialog("Getting information...", ProgressBarStyle.Marquee);

            bg.AppendTask("Getting information...", DummyWorker.GetWorker((ctx) =>
            {
                try
                {
                    pso   = HyperV.GetVhd(computer, path, PsStreamEventHandlers.GetUIHandlers(ctx))[0];
                    ctx.s = StatusCode.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);
                    ctx.s = StatusCode.FAILED;
                }
                return(ctx);
            }));
            bg.ShowDialog();
            this.c = computer;
        }
Пример #7
0
        public ServerPropertyGrid(string hostName)
        {
            this.HostName = hostName;
            // Populate all
            PSObject psObj = null;

            new BackgroundWorkerQueueDialog("Getting server information...", ProgressBarStyle.Marquee)
            .AppendTask("", DummyWorker.GetWorker((ctx) => psObj = HyperV.GetVmHost(hostName, PsStreamEventHandlers.GetUIHandlers(ctx))))
            .ShowDialog();
            if (psObj == null)
            {
                return;
            }

            this.VirtualHardDiskPath       = (string)psObj.Members["VirtualHardDiskPath"].Value;
            this.VirtualMachinePath        = (string)psObj.Members["VirtualMachinePath"].Value;
            this.MacAddressMaximum         = (string)psObj.Members["MacAddressMaximum"].Value;
            this.MacAddressMinimum         = (string)psObj.Members["MacAddressMinimum"].Value;
            this.EnableEnhancedSessionMode = (bool)psObj.Members["EnableEnhancedSessionMode"].Value;
            this.MemoryCapacity            = (long)psObj.Members["MemoryCapacity"].Value;
            this.LogicalProcessorCount     = (int)psObj.Members["LogicalProcessorCount"].Value;
        }
Пример #8
0
        private void addbtn_Click(object sender, EventArgs e)
        {
            bool isFormValid = false;

            // Disgusting
            if (serverComboBox.SelectedIndex == -1)
            {
                serverComboBox.IsValid = tribool.FALSE;
            }
            else
            {
                serverComboBox.IsValid = tribool.TRUE;
            }
            if (baseComboBox.SelectedIndex == -1)
            {
                baseComboBox.IsValid = tribool.FALSE;
            }
            else
            {
                baseComboBox.IsValid = tribool.TRUE;
            }
            if (configComboBox.SelectedIndex == -1)
            {
                configComboBox.IsValid = tribool.FALSE;
            }
            else
            {
                configComboBox.IsValid = tribool.TRUE;
            }
            if (adapterComboBox.SelectedIndex == -1)
            {
                adapterComboBox.IsValid = tribool.FALSE;
            }
            else
            {
                adapterComboBox.IsValid = tribool.TRUE;
            }
            if (string.IsNullOrEmpty(vmTextbox.Text))
            {
                vmTextbox.IsValid = tribool.FALSE;
            }
            else
            {
                vmTextbox.IsValid = tribool.TRUE;
            }

            isFormValid = serverComboBox.IsValid == tribool.TRUE &&
                          baseComboBox.IsValid == tribool.TRUE &&
                          vmTextbox.IsValid == tribool.TRUE &&
                          configComboBox.IsValid == tribool.TRUE &&
                          adapterComboBox.IsValid == tribool.TRUE;

            if (!isFormValid)
            {
                this.DialogResult = DialogResult.None;
            }
            else
            {
                // !! IMPORTANT !!
                // We NEED these exactly here because of cross thread errors
                // (we cannot get the user inputs from the BackgroundWorker)
                var a1 = GetSelectedHost().HostName;
                var a2 = vmTextbox.Text;
                var a3 = GetSelectedVirtualMachine().Uuid;
                var a4 = GetSelectedSwitch().Name;
                var a5 = configComboBox.SelectedIndex;

                if (a1 != GetSelectedVirtualMachine().Host&&
                    MessageBox.Show(
                        "The selected target server is different from the server hosting the base image. Do you want to continue?",
                        "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    this.DialogResult = DialogResult.None;
                    return;
                }

                var backgroundWorker = new BackgroundWorkerQueueDialog("Loading servers...");
                backgroundWorker.AppendTask("Creating VM...", DummyWorker.GetWorker((ctx) => {
                    // Try to create the VM
                    try
                    {
                        Interface.NewTemplate(a1, a2, a3, a4, jsonHelper.JObject["templates"][a5], PsStreamEventHandlers.GetUIHandlers(ctx));
                        ctx.s = StatusCode.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);
                        ctx.s = StatusCode.FAILED;
                    }
                    return(ctx);
                }));
                backgroundWorker.ShowDialog();
                if (backgroundWorker.GetWorker().ReturnedObjects[0].s == StatusCode.OK)
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Пример #9
0
        private void AddTemplateDialog_Load(object sender, EventArgs e)
        {
            // Get server information
            BackgroundWorkerQueueDialog backgroundWorker = new BackgroundWorkerQueueDialog("Retrieving Network Information");

            foreach (var host in SessionManager.GetDatabase().GetServerDb())
            {
                backgroundWorker.AppendTask("Validating " + host.HostName, NetworkWorkers.GetStarterWorker(
                                                new NetworkWorkerObject {
                    HostName = host.HostName
                }
                                                ));
                backgroundWorker.AppendTask("Getting IP address of " + host.HostName + "...", NetworkWorkers.GetIpWorker());
            }
            backgroundWorker.ShowDialog();
            var bw = backgroundWorker.GetWorker();

            for (int i = 0; i < SessionManager.GetDatabase().GetServerDb().Count; i++)
            {
                if (bw.ReturnedObjects[i * 2 + 1].s == StatusCode.OK)
                {
                    hostComputers.Add(new HostComputer
                    {
                        HostName  = ((NetworkWorkerObject)bw.ReturnedObjects[i * 2 + 1].o).HostName,
                        IpAddress = ((NetworkWorkerObject)bw.ReturnedObjects[i * 2 + 1].o).IpAddress,
                    });
                }
            }

            // Get configurations
            for (int i = 0; i < jsonHelper.JObject["templates"]?.Count(); i++)
            {
                configComboBox.ComboBox.Items.Add(jsonHelper.JObject["templates"][i]["name"]);
            }

            // Add options to host combobox
            hostComputers.ForEach(x =>
            {
                if (!string.IsNullOrEmpty(x.HostName) && !string.IsNullOrEmpty(x.IpAddress))
                {
                    serverComboBox.ComboBox.Items.Add(x.HostName + " [" + x.IpAddress + "]");
                }
            });

            // Get virtual machines
            backgroundWorker = new BackgroundWorkerQueueDialog("Scanning for Virtual Machines...", ProgressBarStyle.Marquee);
            backgroundWorker.AppendTask("Getting machines...", DummyWorker.GetWorker((ctx) =>
            {
                SessionManager.GetDatabase().FlushCache(PsStreamEventHandlers.GetUIHandlers(ctx));
                try
                {
                    foreach (var vm in SessionManager.GetDatabase().GetVm(VirtualMachineType.BASE))
                    {
                        virtualMachines.Add(vm);
                    }
                    virtualMachines.ForEach(x =>
                    {
                        ThreadManager.Invoke(this, baseComboBox, () =>
                                             baseComboBox.ComboBox.Items.Add(x.Name + " [" + x.Host + "]")
                                             );
                    });
                    ctx.s = StatusCode.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);
                    ctx.s = StatusCode.FAILED;
                }
                return(ctx);
            }));
            backgroundWorker.ShowDialog();
        }
Пример #10
0
        private bool ValidateTexts(bool flushCache = false)
        {
            // Clean!
            vms = null;
            if (flushCache)
            {
                _hn_cache = null;
            }

            // A clean alternative way to run consecutive network events
            BackgroundWorkerQueueDialog backgroundWorker = new BackgroundWorkerQueueDialog("Retrieving Network Information");

            backgroundWorker.AppendTask("Starting...", NetworkWorkers.GetStarterWorker(new NetworkWorkerObject
            {
                HostName   = hostnameText.Text,
                IpAddress  = ipText.Text,
                MacAddress = macText.Text
            }));
            backgroundWorker.AppendTask("Getting IP address from server...", NetworkWorkers.GetIpWorker());
            backgroundWorker.AppendTask("Getting MAC address from IP...", NetworkWorkers.GetMacWorker());
            backgroundWorker.ShowDialog();
            var v = backgroundWorker.GetWorker();

            // Set fields, only if the returned object has text - therefore preserving whatever was typed beforehand
            if (backgroundWorker.GetWorker().ReturnedObjects[1].s == StatusCode.OK)
            {
                ipText.Text = ((NetworkWorkerObject)backgroundWorker.GetWorker().ReturnedObjects[1].o).IpAddress;
            }
            if (backgroundWorker.GetWorker().ReturnedObjects[2].s == StatusCode.OK)
            {
                macText.Text = ((NetworkWorkerObject)backgroundWorker.GetWorker().ReturnedObjects[2].o).MacAddress;
            }

            // If something's empty/failed, let user know
            hostnameText.IsValid = (string.IsNullOrWhiteSpace(hostnameText.Text)) ?
                                   tribool.FALSE : tribool.TRUE;
            ipText.IsValid = (string.IsNullOrWhiteSpace(ipText.Text) ||
                              backgroundWorker.GetWorker().ReturnedObjects[1].s != StatusCode.OK) ?
                             tribool.FALSE : tribool.TRUE;
            macText.IsValid = (string.IsNullOrWhiteSpace(macText.Text) ||
                               backgroundWorker.GetWorker().ReturnedObjects[2].s != StatusCode.OK) ?
                              tribool.FALSE : tribool.TRUE;

            // Check if the PowerShell thing is on...
            backgroundWorker = new BackgroundWorkerQueueDialog("Checking for PSRemoting and WinRM...", ProgressBarStyle.Marquee);
            backgroundWorker.AppendTask("Pinging...", DummyWorker.GetWorker((ctx) =>
            {
                try
                {
                    Interface.BringOnline(hostnameText.Text);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Exception", MessageBoxButtons.OK);
                    ctx.s = StatusCode.FAILED;
                    return(ctx);
                }
                ctx.s = StatusCode.OK;
                return(ctx);
            }));
            backgroundWorker.ShowDialog();
            if (backgroundWorker.GetWorker().ReturnedObjects[0].s != StatusCode.OK)
            {
                return(false);
            }

            // Get VMs
            // Check if the vms in the cache are different
            if (_hn_cache == hostnameText.Text)
            {
                return(true);
            }
            listBox1.Items.Clear();
            backgroundWorker = new BackgroundWorkerQueueDialog("Scanning for Virtual Machines...", ProgressBarStyle.Marquee);
            backgroundWorker.AppendTask("Getting machines...", DummyWorker.GetWorker(() =>
            {
                try
                {
                    _hn_cache = hostnameText.Text;
                    vms       = HyperV.GetVm(hostnameText.Text);
                    vms?.ForEach(x =>
                    {
                        ThreadManager.Invoke(this, listBox1, () =>
                                             listBox1.Items.Add(x.Name + " [" + x.Uuid.ToString().ToUpper() + "]"));
                    });
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Exception", MessageBoxButtons.OK);
                }
            }));
            backgroundWorker.ShowDialog();
            return(true);
        }
Пример #11
0
        public static void Run()
        {
            var dummyWorker = new DummyWorker();

            dummyWorker.PerformDummyWork();
        }