Exemplo n.º 1
0
 private void RefreshCollections(WorkerContext ctx = null)
 {
     try
     {
         if (ctx == null)
         {
             databaseManager.FlushCache();
         }
         else
         {
             databaseManager.FlushCache(PsStreamEventHandlers.GetUIHandlers(ctx));
             ctx.s = StatusCode.OK;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Exception", MessageBoxButtons.OK);
         if (ctx != null)
         {
             ctx.s = StatusCode.FAILED;
         }
         return;
     }
     RefreshUI();
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 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();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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.");
 }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
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;
        }