Beispiel #1
0
        private void listViewControl_KeyUp(object sender, KeyEventArgs e)
        {
            if (Settings.Enabled && Settings.EnableShortcutKeys == true)
            {
                Debug.WriteLine("[QuickConnectPlugin] ListViewControl Key Up Event: " + e.KeyData);

                PwEntry[]   selectedEntries = pluginHost.MainWindow.GetSelectedEntries();
                HostPwEntry selectedEntry   = null;

                if (selectedEntries != null && selectedEntries.Length == 1)
                {
                    selectedEntry = new HostPwEntry(selectedEntries[0], pluginHost.Database, fieldsMapper);
                }
                ;

                if (selectedEntry == null)
                {
                    return;
                }

                if (Settings.PuttyShortcutKey != Keys.None && e.KeyData == Settings.RemoteDesktopShortcutKey)
                {
                    Debug.WriteLine("[QuickConnectPlugin] Open Remote Desktop Using Shortcut Key");
                    if (selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.RemoteDesktop))
                    {
                        try
                        {
                            ProcessUtils.Start(CmdKeyRegisterArgumentsFormatter.CmdKeyPath, new CmdKeyRegisterArgumentsFormatter().Format(selectedEntry));
                            var argsFormatter = new RemoteDesktopArgumentsFormatter()
                            {
                                FullScreen = true
                            };
                            ProcessUtils.StartDetached(argsFormatter.Format(selectedEntry));
                            ProcessUtils.StartDetached(new CmdKeyUnregisterArgumentsFormatter()
                            {
                                IncludePath = true
                            }.Format(selectedEntry), RemoveCredentialsDelay);
                        }
                        catch (Exception ex)
                        {
                            log(ex);
                        };
                        e.Handled = true;
                    }
                }
                else if (Settings.PuttyShortcutKey != Keys.None && e.KeyData == Settings.PuttyShortcutKey)
                {
                    Debug.WriteLine("[QuickConnectPlugin] Open PuTTY Using Shortcut Key");
                    if (selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttySSH) ||
                        selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.PuttyTelnet))
                    {
                        string puttyPath = null;
                        if (QuickConnectUtils.CanOpenPutty(Settings, selectedEntry, out puttyPath))
                        {
                            try
                            {
                                var sessionFinder = new RegistryPuttySessionFinder(new WindowsRegistryService());
                                var argsFormatter = new PuttyArgumentsFormatter(puttyPath, sessionFinder, !Settings.DisableCLIPasswordForPutty);
                                ProcessUtils.StartDetached(argsFormatter.Format(selectedEntry));
                            }
                            catch (Exception ex)
                            {
                                log(ex);
                            };
                        }
                        e.Handled = true;
                    }
                }
                else if (Settings.WinScpShortcutKey != Keys.None && e.KeyData == Settings.WinScpShortcutKey)
                {
                    Debug.WriteLine("[QuickConnectPlugin] Open WinSCP Using Shortcut Key");
                    if (selectedEntry.ConnectionMethods.Contains(ConnectionMethodType.WinSCP))
                    {
                        string winScpPath = null;
                        if (QuickConnectUtils.CanOpenWinScp(Settings, selectedEntry, out winScpPath))
                        {
                            try
                            {
                                var argsFormatter = new WinScpArgumentsFormatter(winScpPath);
                                ProcessUtils.StartDetached(argsFormatter.Format(selectedEntry));
                            }
                            catch (Exception ex)
                            {
                                log(ex);
                            };
                        }
                        e.Handled = true;
                    }
                }
                else
                {
                    Debug.WriteLine("[QuickConnectPlugin] Keyboard Event Ignored");
                }
            }
        }
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);
        }
Beispiel #3
0
        public void Format()
        {
            InMemoryHostPwEntry pwEntry = new InMemoryHostPwEntry()
            {
                Username  = "******",
                Password  = "******",
                IPAddress = "127.0.0.1"
            };

            pwEntry.ConnectionMethods.Add(ConnectionMethodType.RemoteDesktop);

            RemoteDesktopArgumentsFormatter argumentsFormatter = new RemoteDesktopArgumentsFormatter();

            Assert.AreEqual(String.Format("\"{0}\" /v:127.0.0.1", RemoteDesktopArgumentsFormatter.RemoteDesktopClientPath), argumentsFormatter.Format(pwEntry));
        }