Esempio n. 1
0
        /// <summary>
        /// Launches a new Putty session
        /// </summary>
        /// <returns>If launching Putty succeeded</returns>
        private bool LaunchPuttySession(string session, PuttySession puttySession = null)
        {
            try
            {
                var puttyPath = settings.PuttyPath;

                if (string.IsNullOrEmpty(settings.PuttyPath))
                {
                    puttyPath = "putty.exe";
                }

                var p = new Process {
                    StartInfo = { FileName = puttyPath }
                };

                if (!string.IsNullOrEmpty(puttySession?.Hostname))
                {
                    p.StartInfo.Arguments = "-load \"" + puttySession.Identifier + "\"";
                }
                else if (!string.IsNullOrEmpty(session))
                {
                    p.StartInfo.Arguments = "-ssh \"" + session + "\"";
                }

                if (settings.AlwaysStartsSessionMaximized)
                {
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                }

                p.Start();

                return(true);
            }
            catch (Exception ex)
            {
                // Report the exception to the user. No further actions required
                context.API.ShowMsg("Putty Error: " + puttySession?.Identifier ?? session + " (" + settings.PuttyPath + ") ", ex.Message, "");

                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new Result item
        /// </summary>
        /// <returns>A Result object containing the PuttySession identifier and its connection string</returns>
        private Result CreateResult(
            string title = "putty.exe", string subTitle = "Open Putty", int score = 50, PuttySession puttySession = null)
        {
            if (puttySession != null && string.IsNullOrEmpty(puttySession.Hostname))
            {
                return new Result
                       {
                           Title    = $"{puttySession.Identifier}- Hostname not defined",
                           SubTitle = $"Open Putty",
                           IcoPath  = "icon.png",
                           Action   = context => LaunchPuttySession(string.Empty),//load Putty instead,
                           Score    = score
                       }
            }
            ;

            return(new Result
            {
                Title = title,
                SubTitle = subTitle,
                IcoPath = "icon.png",
                Action = context => title != "putty.exe" ? LaunchPuttySession(title, puttySession) : LaunchPuttySession(string.Empty),//load Putty instead,
                Score = score
            });
        }