示例#1
0
        public void QueryMachines()
        {
            List <VagrantMachine> machines = new List <VagrantMachine>();

            if (this.HasVagrantFile())
            {
                Process p = new Process {
                    StartInfo = new ProcessStartInfo {
                        FileName               = "cmd",
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        CreateNoWindow         = true,
                        Arguments              = String.Format("/C cd /d {0} && vagrant status", Util.EscapeShellArg(_Path)),
                        UseShellExecute        = false,
                        RedirectStandardOutput = true,
                    }
                };

                p.Start();
                string outputString = p.StandardOutput.ReadToEnd();
                p.WaitForExit();

                Regex           regex           = new Regex("([\\w-_\\.]+)\\s+([\\w\\s]+) \\(\\w+\\)");
                MatchCollection matchCollection = regex.Matches(outputString);
                foreach (Match match in matchCollection)
                {
                    VagrantMachine machine = new VagrantMachine(this, Util.TrimWhitespaceAndNewlines(match.Groups[1].Value), VagrantMachineState.UnknownState);
                    machine.StateString = Util.TrimWhitespaceAndNewlines(match.Groups[2].Value);
                    machines.Add(machine);
                }
            }

            _Machines = machines;
        }
 public VagrantMachine(VagrantInstance instance, string name, VagrantMachineState state)
 {
     Instance    = instance;
     Name        = name;
     State       = state;
     StateString = VagrantMachine.GetStringForState(state);
 }
        public void QueryMachines() {
            List<VagrantMachine> machines = new List<VagrantMachine>();

            if (this.HasVagrantFile()) {
                Process p = new Process {
                    StartInfo = new ProcessStartInfo {
                        FileName = "cmd",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        CreateNoWindow = true,
                        Arguments = String.Format("/C cd /d {0} && vagrant status", Util.EscapeShellArg(_Path)),
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                    }
                };

                p.Start();
                p.WaitForExit();
                string outputString = p.StandardOutput.ReadToEnd();

                Regex regex = new Regex("([\\w-_\\.]+)\\s+([\\w\\s]+) \\(\\w+\\)");
                MatchCollection matchCollection = regex.Matches(outputString);
                foreach (Match match in matchCollection) {
                    VagrantMachine machine = new VagrantMachine(this, Util.TrimWhitespaceAndNewlines(match.Groups[1].Value), VagrantMachineState.UnknownState);
                    machine.StateString = Util.TrimWhitespaceAndNewlines(match.Groups[2].Value);
                    machines.Add(machine);
                }
            }

            _Machines = machines;
        }
示例#4
0
        private void RunVagrantAction(string action, VagrantMachine machine)
        {
            string command;

            if (action == "up")
            {
                command = String.Format("vagrant up{0}", !String.IsNullOrEmpty(machine.Instance.ProviderIdentifier) ? String.Format(" --provider={0}", machine.Instance.ProviderIdentifier) : "virtualbox");
            }
            else if (action == "reload")
            {
                command = "vagrant reload";
            }
            else if (action == "suspend")
            {
                command = "vagrant suspend";
            }
            else if (action == "halt")
            {
                command = "vagrant halt";
            }
            else if (action == "provision")
            {
                command = "vagrant provision";
            }
            else if (action == "destroy")
            {
                command = "vagrant destroy -f";
            }
            else {
                return;
            }

            Process process = new Process();
            process.StartInfo.FileName = "cmd";
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.Arguments = String.Format("/C cd /d {0} && {1} {2}", Util.EscapeShellArg(machine.Instance.Path), command, Util.EscapeShellArg(machine.Name));

            TaskOutputWindow outputWindow = new TaskOutputWindow();
            outputWindow.Task = process;
            outputWindow.TaskCommand = process.StartInfo.Arguments;
            outputWindow.TaskAction = command;
            outputWindow.Target = machine;
            outputWindow.Show();

            _TaskOutputWindows.Add(outputWindow);
        }
示例#5
0
 public void PerformVagrantAction(string action, VagrantMachine machine)
 {
     if (action == "ssh")
     {
         action = String.Format("cd /d {0} && vagrant ssh {1}", Util.EscapeShellArg(machine.Instance.Path), machine.Name);
         this.RunTerminalCommand(action);
     }
     else {
         this.RunVagrantAction(action, machine);
     }
 }
 private void PerformAction(string action, VagrantMachine machine)
 {
     Delegate.PerformVagrantAction(action, machine);
 }
 public void NativeMenuItemProvisionMachine(VagrantMachine machine)
 {
     this.PerformAction("provision", machine);
 }
 public void NativeMenuItemDestroyMachine(VagrantMachine machine)
 {
     DialogResult dialogResult = MessageBox.Show("Are you sure you want to destroy this machine?", "Confirm Destructive Action", MessageBoxButtons.YesNo);
     if (dialogResult == DialogResult.Yes)
     {
         this.PerformAction("destroy", machine);
     }
 }
 public void NativeMenuItemHaltMachine(VagrantMachine machine)
 {
     this.PerformAction("halt", machine);
 }
 public void NativeMenuItemReloadMachine(VagrantMachine machine)
 {
     this.PerformAction("reload", machine);
 }
 public void NativeMenuItemSuspendMachine(VagrantMachine machine)
 {
     this.PerformAction("suspend", machine);
 }
 public void NativeMenuItemSSHMachine(VagrantMachine machine)
 {
     this.PerformAction("ssh", machine);
 }
 public void NativeMenuItemUpMachine(VagrantMachine machine)
 {
     this.PerformAction("up", machine);
 }
        public void RefreshInstances()
        {
            List <VagrantInstance> instances = new List <VagrantInstance>();

            // create instance for each bookmark
            List <Bookmark> bookmarks = BookmarkManager.Instance.GetBookmarks();

            bookmarks.ForEach(bookmark => instances.Add(new VagrantInstance(bookmark.Path, bookmark.ProviderIdentifier, bookmark.DisplayName)));

            List <string> allPaths = new List <string>();

            // scan vagrant global-status output
            VagrantGlobalStatusScanner globalStatusScanner = new VagrantGlobalStatusScanner();

            Array.ForEach(globalStatusScanner.GetInstancePaths(), (path) => {
                if (BookmarkManager.Instance.GetBookmarkWithPath(path) == null && !allPaths.Contains(path))
                {
                    allPaths.Add(path);
                    instances.Add(new VagrantInstance(path, null));
                }
            });

            // create instance for each detected path
            Dictionary <string, string[]> detectedPaths = this.DetectInstancePaths();

            detectedPaths.Keys.ToList().ForEach(providerIdentifier => {
                string[] paths = detectedPaths[providerIdentifier];
                paths.ToList().ForEach(path => {
                    if (BookmarkManager.Instance.GetBookmarkWithPath(path) == null && !allPaths.Contains(path))
                    {
                        allPaths.Add(path);
                        instances.Add(new VagrantInstance(path, providerIdentifier));
                    }
                });
            });

            List <string> validPaths = new List <string>();

            List <Task> tasks = new List <Task>();

            instances.ForEach(instance => {
                Task task = Task.Run(() => {
                    instance.QueryMachines();

                    lock (_Instances) {
                        VagrantInstance existingInstance = this.GetInstanceForPath(instance.Path);

                        if (existingInstance != null)
                        {
                            // instance already exists, check for changes
                            int idx = _Instances.IndexOf(existingInstance);
                            if (instance.Machines.Length != existingInstance.Machines.Length || existingInstance.DisplayName != instance.DisplayName || existingInstance.ProviderIdentifier != instance.ProviderIdentifier)
                            {
                                _Instances[idx] = instance;
                                Delegate.InstanceUpdated(this, existingInstance, instance);
                            }
                            else
                            {
                                Array.ForEach(instance.Machines, machine => {
                                    VagrantMachine existingMachine = existingInstance.GetMachineWithName(machine.Name);

                                    if (existingMachine == null || existingMachine.StateString != machine.StateString)
                                    {
                                        _Instances[idx] = instance;
                                        Delegate.InstanceUpdated(this, existingInstance, instance);
                                    }
                                });
                            }
                        }
                        else
                        {
                            //new instance
                            _Instances.Add(instance);
                            Delegate.InstanceAdded(this, instance);
                        }

                        validPaths.Add(instance.Path);
                    }
                });

                tasks.Add(task);
            });

            Task.WaitAll(tasks.ToArray());

            for (int i = _Instances.Count - 1; i >= 0; --i)
            {
                VagrantInstance instance = _Instances.ElementAt(i);

                if (!validPaths.Contains(instance.Path))
                {
                    _Instances.RemoveAt(i);
                    Delegate.InstanceRemoved(this, instance);
                }
            }
        }