public void Format()
        {
            InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry()
            {
                Username  = "******",
                Password  = "******",
                IPAddress = "127.0.0.1"
            };

            pwEntry.ConnectionMethods.Add(ConnectionMethodType.vSphereClient);

            VSphereClientArgumentsFormatter argumentsFormatter = new VSphereClientArgumentsFormatter("VpxClient.exe");

            Assert.AreEqual("\"VpxClient.exe\" -s 127.0.0.1 -u root -p 12345678", argumentsFormatter.Format(pwEntry));
        }
Beispiel #2
0
        private DisposableList <ToolStripItem> createMenuItems(IHostPwEntry hostPwEntry)
        {
            var menuItems = new DisposableList <ToolStripItem>();

            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.RemoteDesktop))
            {
                var menuItem = new ToolStripMenuItem()
                {
                    Text    = OpenRemoteDesktopMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.remote,
                    Enabled = hostPwEntry.HasIPAddress
                };

                if (Settings.EnableShortcutKeys == true && Settings.RemoteDesktopShortcutKey != Keys.None)
                {
                    menuItem.ShortcutKeys     = Settings.RemoteDesktopShortcutKey;
                    menuItem.ShowShortcutKeys = true;
                }

                menuItem.Click += new EventHandler(
                    delegate(object obj, EventArgs ev) {
                    try {
                        ProcessUtils.Start(CmdKeyRegisterArgumentsFormatter.CmdKeyPath, new CmdKeyRegisterArgumentsFormatter().Format(hostPwEntry));
                        IArgumentsFormatter argsFormatter = new RemoteDesktopArgumentsFormatter()
                        {
                            FullScreen = true
                        };
                        ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry));
                        ProcessUtils.StartDetached(new CmdKeyUnregisterArgumentsFormatter()
                        {
                            IncludePath = true
                        }.Format(hostPwEntry), RemoveCredentialsDelay);
                    }
                    catch (Exception ex) {
                        log(ex);
                    }
                }
                    );
                menuItems.Add(menuItem);
            }
            ;

            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.RemoteDesktopConsole))
            {
                var menuItem = new ToolStripMenuItem()
                {
                    Text    = OpenRemoteDesktopConsoleMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.mycomputer,
                    Enabled = hostPwEntry.HasIPAddress
                };

                menuItem.Click += new EventHandler(
                    delegate(object obj, EventArgs ev) {
                    try {
                        ProcessUtils.Start(CmdKeyRegisterArgumentsFormatter.CmdKeyPath, new CmdKeyRegisterArgumentsFormatter()
                                           .Format(hostPwEntry));
                        IArgumentsFormatter argsFormatter = new RemoteDesktopArgumentsFormatter()
                        {
                            FullScreen     = true,
                            UseConsole     = true,
                            IsOlderVersion = RDCIsOlderVersion
                        };
                        ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry));
                        ProcessUtils.StartDetached(new CmdKeyUnregisterArgumentsFormatter()
                        {
                            IncludePath = true
                        }.Format(hostPwEntry), RemoveCredentialsDelay);
                    }
                    catch (Exception ex) {
                        log(ex);
                    }
                }
                    );
                menuItems.Add(menuItem);
            }
            ;

            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.vSphereClient))
            {
                var vSphereClientPath = QuickConnectUtils.GetVSphereClientPath();
                var menuItem          = new ToolStripMenuItem()
                {
                    Text    = OpenVSphereClientMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.vmware,
                    Enabled = hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(vSphereClientPath)
                };
                menuItem.Click += new EventHandler(
                    delegate(object obj, EventArgs ev) {
                    try {
                        IArgumentsFormatter argsFormatter = new VSphereClientArgumentsFormatter(vSphereClientPath);
                        ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry));
                    }
                    catch (Exception ex) {
                        log(ex);
                    }
                }
                    );
                menuItems.Add(menuItem);
            }
            ;

            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttySSH) ||
                hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttyTelnet))
            {
                string puttyPath = null;
                var    menuItem  = new ToolStripMenuItem()
                {
                    Text    = OpenPuttyMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.konsole,
                    Enabled = QuickConnectUtils.CanOpenPutty(Settings, hostPwEntry, out puttyPath)
                };

                if (Settings.EnableShortcutKeys == true && Settings.PuttyShortcutKey != Keys.None)
                {
                    menuItem.ShortcutKeys     = Settings.PuttyShortcutKey;
                    menuItem.ShowShortcutKeys = true;
                }

                menuItem.Click += new EventHandler(
                    delegate(object obj, EventArgs ev) {
                    try {
                        var sessionFinder = new RegistryPuttySessionFinder(new WindowsRegistryService());
                        IArgumentsFormatter argsFormatter = new PuttyArgumentsFormatter(puttyPath, sessionFinder, !this.Settings.DisableCLIPasswordForPutty);
                        ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry));
                    }
                    catch (Exception ex) {
                        log(ex);
                    };
                }
                    );
                menuItems.Add(menuItem);
            }
            ;

            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.WinSCP))
            {
                string winScpPath = null;
                var    menuItem   = new ToolStripMenuItem()
                {
                    Text    = OpenWinScpMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.winscp,
                    Enabled = QuickConnectUtils.CanOpenWinScp(Settings, hostPwEntry, out winScpPath)
                };

                if (Settings.EnableShortcutKeys == true && Settings.WinScpShortcutKey != Keys.None)
                {
                    menuItem.ShortcutKeys     = Settings.WinScpShortcutKey;
                    menuItem.ShowShortcutKeys = true;
                }

                menuItem.Click += new EventHandler(
                    delegate(object obj, EventArgs ev) {
                    try {
                        IArgumentsFormatter argsFormatter = new WinScpArgumentsFormatter(winScpPath);
                        ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry));
                    }
                    catch (Exception ex) {
                        log(ex);
                    };
                }
                    );
                menuItems.Add(menuItem);
            }
            ;
            return(menuItems);
        }