Exemple #1
0
 public void OpenInstanceInTerminal(VagrantInstance instance)
 {
     if (Directory.Exists(instance.Path))
     {
         Process p = new Process();
         if (File.Exists(Properties.Settings.Default.CmderExecutablePath))
         {
             p.StartInfo.FileName  = Properties.Settings.Default.CmderExecutablePath;
             p.StartInfo.Arguments = String.Format("/START {0}", instance.Path);
         }
         else
         {
             if (File.Exists("D:\\Cmder\\Cmder.exe"))
             {
                 p.StartInfo.FileName  = "D:\\Cmder\\Cmder.exe";
                 p.StartInfo.Arguments = String.Format("/START {0}", instance.Path);
             }
             else
             {
                 p.StartInfo.FileName  = "cmd";
                 p.StartInfo.Arguments = String.Format("/K cd /d {0}", instance.Path);
             }
         }
         p.Start();
     }
     else
     {
         MessageBox.Show("路径不存在: " + instance.Path);
     }
 }
Exemple #2
0
        protected VagrantProcess(VagrantInstance instance, Command command, bool showWindow = false)
        {
            Instance = instance;
            _command = command;

            _outputData = new List <string>();
            _errorData  = new List <string>();

            var startInfo = new ProcessStartInfo
            {
                FileName         = "vagrant.exe",
                Arguments        = CommandArguments[command],
                WorkingDirectory = instance.Directory,
                UseShellExecute  = false
            };

            if (!showWindow)
            {
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardError  = true;
                startInfo.CreateNoWindow         = true;

                EnableRaisingEvents = true;

                OutputDataReceived += OnOutputDataReceived;
                ErrorDataReceived  += OnErrorDataReceived;
            }

            if (Properties.Settings.Default.RunAsAdministrator)
            {
                startInfo.Verb = "runas";
            }

            StartInfo = startInfo;
        }
Exemple #3
0
 public void InstanceRemoved(VagrantManager vagrantManager, VagrantInstance instance)
 {
     _NativeMenu.Menu.BeginInvoke((MethodInvoker) delegate {
         Dictionary <string, object> userInfo = new Dictionary <string, object>();
         userInfo["instance"] = instance;
         NotificationCenter.Instance.PostNotification("vagrant-manager.instance-removed", new Notification(null, userInfo));
     });
 }
        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 if (action == "rsync")
            {
                command = "vagrant rsync";
            }
            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
            {
                Task        = process,
                TaskCommand = process.StartInfo.Arguments,
                TaskAction  = command,
                Target      = instance
            };

            outputWindow.Show();
        }
        public VagrantSshProcess(VagrantInstance instance) : base(instance, Command.Ssh, true)
        {
            //override process filename
            StartInfo.FileName = Properties.Settings.Default.ShellApplication;

            //override args
            StartInfo.Arguments = ShellCommandFactory.GenerateShellCommand(
                Properties.Settings.Default.ShellApplication, Command.Ssh);
        }
Exemple #6
0
 public void OpenInstanceInExplorer(VagrantInstance instance)
 {
     if (Directory.Exists(instance.Path))
     {
         Process.Start(@instance.Path);
     }
     else
     {
         MessageBox.Show("Path not found: " + instance.Path);
     }
 }
 public void InstanceUpdated(VagrantManager vagrantManager, VagrantInstance oldInstance, VagrantInstance newInstance)
 {
     _NativeMenu.Menu.BeginInvoke((MethodInvoker) delegate {
         Dictionary <string, object> userInfo = new Dictionary <string, object>
         {
             ["old_instance"] = oldInstance,
             ["new_instance"] = newInstance
         };
         NotificationCenter.Instance.PostNotification("vagrant-manager.instance-updated", new Notification(null, userInfo));
     });
 }
Exemple #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);
     }
 }
Exemple #9
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);
     }
 }
Exemple #10
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");
 }
Exemple #11
0
 public VagrantUpProcess(VagrantInstance instance) : base(instance, Command.Up)
 {
 }
 public VagrantReloadProcess(VagrantInstance instance)
     : base(instance, Command.Reload)
 {
 }
 public VagrantResumeProcess(VagrantInstance instance)
     : base(instance, Command.Resume)
 {
 }
Exemple #14
0
 private NativeMenuItem MenuItemForInstance(VagrantInstance instance)
 {
     return(_MenuItems.Find(nativeMenuItem => nativeMenuItem.Instance.Path == instance.Path));
 }
 public VagrantSuspendProcess(VagrantInstance instance) : base(instance, Command.Suspend)
 {
 }
Exemple #16
0
        public void RebuildMenu()
        {
            _MenuItems.ForEach(item => item.Refresh());

            BookmarkManager bookmarkManager = BookmarkManager.Instance;

            List <NativeMenuItem> sortedList = _MenuItems.ToList();

            sortedList.Sort((a, b) => {
                VagrantInstance firstInstance  = a.Instance;
                VagrantInstance secondInstance = b.Instance;

                bool firstBookmarked  = bookmarkManager.GetBookmarkWithPath(firstInstance.Path) != null;
                bool secondBookmarked = bookmarkManager.GetBookmarkWithPath(secondInstance.Path) != null;

                int firstRunningCount  = firstInstance.GetRunningMachineCount();
                int secondRunningCount = secondInstance.GetRunningMachineCount();

                if (firstBookmarked && !secondBookmarked)
                {
                    return(-1);
                }
                else if (secondBookmarked && !firstBookmarked)
                {
                    return(1);
                }
                else
                {
                    if (firstRunningCount > 0 && secondRunningCount == 0)
                    {
                        return(-1);
                    }
                    else if (secondRunningCount > 0 && firstRunningCount == 0)
                    {
                        return(1);
                    }
                    else
                    {
                        int firstIdx  = bookmarkManager.GetIndexOfBookmarkWithPath(firstInstance.Path);
                        int secondIdx = bookmarkManager.GetIndexOfBookmarkWithPath(secondInstance.Path);

                        if (firstIdx < secondIdx)
                        {
                            return(-1);
                        }
                        else if (secondIdx < firstIdx)
                        {
                            return(1);
                        }
                        else
                        {
                            return(firstInstance.DisplayName.CompareTo(secondInstance.DisplayName));
                        }
                    }
                }
            });

            sortedList.ForEach(item => {
                if (_Menu.Items.Contains(item.MenuItem))
                {
                    _Menu.Items.Remove(item.MenuItem);
                }

                _Menu.Items.Insert(_Menu.Items.IndexOf(_BottomMachineSeparator), item.MenuItem);
            });

            _MenuItems = sortedList;

            if (_Menu.Items.Contains(_TopMachineSeparator))
            {
                _Menu.Items.Remove(_TopMachineSeparator);
            }

            if (_MenuItems.Count > 0)
            {
                _Menu.Items.Insert(_Menu.Items.IndexOf(_RefreshMenuItem) + 1, _TopMachineSeparator);
            }
        }
Exemple #17
0
 public VagrantDestroyProcess(VagrantInstance instance)
     : base(instance, Command.Destroy)
 {
 }
Exemple #18
0
 public VagrantHaltProcess(VagrantInstance instance)
     : base(instance, Command.Halt)
 {
 }
Exemple #19
0
 public void RemoveBookmarkWithInstance(VagrantInstance instance)
 {
     BookmarkManager.Instance.RemoveBookmarkWithPath(instance.Path);
     BookmarkManager.Instance.SaveBookmarks();
     NotificationCenter.Instance.PostNotification("vagrant-manager.bookmarks-updated");
 }
Exemple #20
0
 private void PerformAction(string action, VagrantInstance instance)
 {
     Delegate.PerformVagrantAction(action, instance);
 }
Exemple #21
0
 public VagrantStatusProcess(VagrantInstance instance)
     : base(instance, Command.Status)
 {
 }