public VagrantMachine(VagrantInstance instance, string name, VagrantMachineState state)
 {
     Instance    = instance;
     Name        = name;
     State       = state;
     StateString = VagrantMachine.GetStringForState(state);
 }
Esempio n. 2
0
        private void RunVagrantAction(string action, VagrantInstance instance)
        {
            string command;

            if (action == "up")
            {
                command = String.Format("vagrant up{0}", !String.IsNullOrEmpty(instance.ProviderIdentifier) ? String.Format(" --provider={0}", 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}", Util.EscapeShellArg(instance.Path), command);

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

            _TaskOutputWindows.Add(outputWindow);
        }
Esempio n. 3
0
 public void InstanceUpdated(VagrantManager vagrantManager, VagrantInstance oldInstance, VagrantInstance newInstance)
 {
     _NativeMenu.Menu.BeginInvoke((MethodInvoker)delegate
     {
         Dictionary<string, object> userInfo = new Dictionary<string, object>();
         userInfo["old_instance"] = oldInstance;
         userInfo["new_instance"] = newInstance;
         NotificationCenter.Instance.PostNotification("vagrant-manager.instance-updated", new Notification(null, userInfo));
     });
 }
Esempio n. 4
0
 public void RemoveBookmarkWithInstance(VagrantInstance instance)
 {
     BookmarkManager.Instance.RemoveBookmarkWithPath(instance.Path);
     BookmarkManager.Instance.SaveBookmarks();
     NotificationCenter.Instance.PostNotification("vagrant-manager.bookmarks-updated");
 }
Esempio n. 5
0
 public void AddBookmarkWithInstance(VagrantInstance instance)
 {
     BookmarkManager.Instance.AddBookmarkWithPath(instance.Path, instance.DisplayName, instance.ProviderIdentifier);
     BookmarkManager.Instance.SaveBookmarks();
     NotificationCenter.Instance.PostNotification("vagrant-manager.bookmarks-updated");
 }
Esempio n. 6
0
 public void OpenInstanceInTerminal(VagrantInstance instance)
 {
     if (Directory.Exists(instance.Path))
     {
         Process p = new Process();
         p.StartInfo.FileName = "cmd";
         p.StartInfo.Arguments = String.Format("/K cd /d {0}", instance.Path);
         p.Start();
     }
     else {
         MessageBox.Show("Path not found: " + instance.Path);
     }
 }
Esempio n. 7
0
 public void OpenInstanceInExplorer(VagrantInstance instance)
 {
     if (Directory.Exists(instance.Path))
     {
         Process.Start(@instance.Path);
     }
     else {
         MessageBox.Show("Path not found: " + instance.Path);
     }
 }
Esempio n. 8
0
 public void PerformVagrantAction(string action, VagrantInstance instance)
 {
     if (action == "ssh")
     {
         action = String.Format("cd /d {0} && vagrant ssh", Util.EscapeShellArg(instance.Path));
         this.RunTerminalCommand(action);
     }
     else {
         this.RunVagrantAction(action, instance);
     }
 }
 private NativeMenuItem MenuItemForInstance(VagrantInstance instance)
 {
     return _MenuItems.Find(nativeMenuItem => nativeMenuItem.Instance.Path == instance.Path);
 }
 private void PerformAction(string action, VagrantInstance instance)
 {
     Delegate.PerformVagrantAction(action, instance);
 }
        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);
                }
            }
        }
 public VagrantMachine(VagrantInstance instance, string name, VagrantMachineState state) {
     Instance = instance;
     Name = name;
     State = state;
     StateString = VagrantMachine.GetStringForState(state);
 }