Ejemplo n.º 1
0
 internal static bool CanOpenPutty(IQuickConnectPluginSettings settings, IHostPwEntry hostPwEntry, out string puttyPath)
 {
     puttyPath = !String.IsNullOrEmpty(settings.PuttyPath) ? settings.PuttyPath : QuickConnectUtils.GetPuttyPath();
     return(hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(puttyPath));
 }
        private DisposableList <ToolStripItem> createMenuItems(HostPwEntry 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
                };
                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))
            {
                var sshClientPath = !String.IsNullOrEmpty(this.Settings.SSHClientPath) ? this.Settings.SSHClientPath : QuickConnectUtils.GetPuttyPath();
                var menuItem      = new ToolStripMenuItem()
                {
                    Text    = OpenSSHConsoleMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.konsole,
                    Enabled = hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(sshClientPath)
                };
                menuItem.Click += new EventHandler(
                    delegate(object obj, EventArgs ev) {
                    try {
                        var sessionFinder = new RegistryPuttySessionFinder(new WindowsRegistryService());
                        IArgumentsFormatter argsFormatter = new PuttyArgumentsFormatter(sshClientPath, sessionFinder);
                        ProcessUtils.StartDetached(argsFormatter.Format(hostPwEntry));
                    }
                    catch (Exception ex) {
                        log(ex);
                    };
                }
                    );
                menuItems.Add(menuItem);
            }
            ;
            if (hostPwEntry.ConnectionMethods.Contains(ConnectionMethodType.WinSCP))
            {
                var winScpPath            = !String.IsNullOrEmpty(this.Settings.WinScpPath) ? this.Settings.WinScpPath : QuickConnectUtils.GetWinScpPath();
                var winScpConsoleMenuItem = new ToolStripMenuItem()
                {
                    Text    = OpenWinScpMenuItemText,
                    Image   = (System.Drawing.Image)QuickConnectPlugin.Properties.Resources.winscp,
                    Enabled = hostPwEntry.HasIPAddress && !String.IsNullOrEmpty(winScpPath)
                };
                winScpConsoleMenuItem.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(winScpConsoleMenuItem);
            }
            ;
            return(menuItems);
        }