Esempio n. 1
0
        private async void CopyAsSessionAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = Application.Current.Resources["String_Header_CopySession"] as string
            };

            PuTTYSessionViewModel puTTYSessionViewModel = new PuTTYSessionViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
                ConfigurationManager.Current.FixAirspace = false;

                PuTTYSessionInfo puTTYSessionInfo = new PuTTYSessionInfo
                {
                    Name  = instance.Name,
                    Host  = instance.Host,
                    Group = instance.Group,
                    Tags  = instance.Tags
                };

                PuTTYSessionManager.AddSession(puTTYSessionInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
                ConfigurationManager.Current.FixAirspace = false;
            }, PuTTYSessionManager.GetSessionGroups(), SelectedSession);

            customDialog.Content = new PuTTYSessionDialog
            {
                DataContext = puTTYSessionViewModel
            };

            ConfigurationManager.Current.FixAirspace = true;
            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Esempio n. 2
0
        public static string BuildCommandLine(PuTTYSessionInfo profileInfo)
        {
            var command = string.Empty;

            // Protocol
            switch (profileInfo.Mode)
            {
            case ConnectionMode.SSH:
                command += "-ssh";
                break;

            case ConnectionMode.Telnet:
                command += "-telnet";
                break;

            case ConnectionMode.Serial:
                command += "-serial";
                break;

            case ConnectionMode.Rlogin:
                command += "-rlogin";
                break;

            case ConnectionMode.RAW:
                command += "-raw";
                break;
            }

            // Profile
            if (!string.IsNullOrEmpty(profileInfo.Profile))
            {
                command += $" -load {'"'}{profileInfo.Profile}{'"'}";
            }

            // Username
            if (!string.IsNullOrEmpty(profileInfo.Username))
            {
                command += $" -l {profileInfo.Username}";
            }

            // Additional commands
            if (!string.IsNullOrEmpty(profileInfo.AdditionalCommandLine))
            {
                command += $" {profileInfo.AdditionalCommandLine}";
            }

            // SerialLine, Baud
            if (profileInfo.Mode == ConnectionMode.Serial)
            {
                command += $" {profileInfo.HostOrSerialLine} -sercfg {profileInfo.PortOrBaud}";
            }

            // Port, Host
            if (profileInfo.Mode != ConnectionMode.Serial)
            {
                command += $" -P {profileInfo.PortOrBaud} {profileInfo.HostOrSerialLine}";
            }

            return(command);
        }
Esempio n. 3
0
        public static string BuildCommandLine(PuTTYSessionInfo sessionInfo)
        {
            string command = string.Empty;

            // Protocol
            switch (sessionInfo.Mode)
            {
            case ConnectionMode.SSH:
                command += string.Format("-ssh");
                break;

            case ConnectionMode.Telnet:
                command += string.Format("-telnet");
                break;

            case ConnectionMode.Serial:
                command += string.Format("-serial");
                break;

            case ConnectionMode.Rlogin:
                command += string.Format("-rlogin");
                break;

            case ConnectionMode.RAW:
                command += string.Format("-raw");
                break;
            }

            // Profile
            if (!string.IsNullOrEmpty(sessionInfo.Profile))
            {
                command += string.Format(" -load {0}{1}{0}", '"', sessionInfo.Profile);
            }

            // Username
            if (!string.IsNullOrEmpty(sessionInfo.Username))
            {
                command += string.Format(" -l {0}", sessionInfo.Username);
            }

            // Additional commands
            if (!string.IsNullOrEmpty(sessionInfo.AdditionalCommandLine))
            {
                command += string.Format(" {0}", sessionInfo.AdditionalCommandLine);
            }

            // SerialLine, Baud
            if (sessionInfo.Mode == ConnectionMode.Serial)
            {
                command += string.Format(" {0} -sercfg {1}", sessionInfo.HostOrSerialLine, sessionInfo.PortOrBaud);
            }

            // Port, Host
            if (sessionInfo.Mode != ConnectionMode.Serial)
            {
                command += string.Format(" -P {0} {1}", sessionInfo.PortOrBaud, sessionInfo.HostOrSerialLine);
            }

            return(command);
        }
        public PuTTYSessionViewModel(Action <PuTTYSessionViewModel> saveCommand, Action <PuTTYSessionViewModel> cancelHandler, List <string> groups, PuTTYSessionInfo sessionInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _sessionInfo = sessionInfo ?? new PuTTYSessionInfo();

            Name = _sessionInfo.Name;

            switch (_sessionInfo.ConnectionMode)
            {
            // SSH is default
            case ConnectionMode.SSH:
                UseSSH = true;
                break;

            case ConnectionMode.Telnet:
                UseTelnet = true;
                break;

            case ConnectionMode.Serial:
                UseSerial = true;
                break;

            case ConnectionMode.Rlogin:
                UseRlogin = true;
                break;

            case ConnectionMode.RAW:
                UseRAW = true;
                break;
            }

            if (_sessionInfo.ConnectionMode == ConnectionMode.Serial)
            {
                SerialLine = sessionInfo.HostOrSerialLine;
                Baud       = sessionInfo.PortOrBaud;
            }
            else
            {
                Host = _sessionInfo.HostOrSerialLine;
                Port = _sessionInfo.PortOrBaud == 0 ? SettingsManager.Current.PuTTY_SSHPort : _sessionInfo.PortOrBaud; // Default SSH port
            }

            Username = _sessionInfo.Username;
            Profile  = _sessionInfo.Profile;
            AdditionalCommandLine = _sessionInfo.AdditionalCommandLine;

            // Get the group, if not --> get the first group (ascending), fallback --> default group
            Group = string.IsNullOrEmpty(_sessionInfo.Group) ? (groups.Count > 0 ? groups.OrderBy(x => x).First() : LocalizationManager.GetStringByKey("String_Default")) : _sessionInfo.Group;
            Tags  = _sessionInfo.Tags;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }
Esempio n. 5
0
        public PuTTYViewModel(IDialogCoordinator instance)
        {
            dialogCoordinator = instance;

            // Check if putty is available...
            CheckIfPuTTYConfigured();

            InterTabClient = new DragablzPuTTYInterTabClient();
            TabItems       = new ObservableCollection <DragablzPuTTYTabItem>();

            // Load sessions
            if (PuTTYSessionManager.Sessions == null)
            {
                PuTTYSessionManager.Load();
            }

            _puTTYSessions = CollectionViewSource.GetDefaultView(PuTTYSessionManager.Sessions);
            _puTTYSessions.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            _puTTYSessions.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending));
            _puTTYSessions.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            _puTTYSessions.Filter = o =>
            {
                if (string.IsNullOrEmpty(Search))
                {
                    return(true);
                }

                PuTTYSessionInfo info = o as PuTTYSessionInfo;

                string search = Search.Trim();

                // Search by: Tag
                if (search.StartsWith(tagIdentifier, StringComparison.OrdinalIgnoreCase))
                {
                    if (string.IsNullOrEmpty(info.Tags))
                    {
                        return(false);
                    }
                    else
                    {
                        return(info.Tags.Replace(" ", "").Split(';').Any(str => search.Substring(tagIdentifier.Length, search.Length - tagIdentifier.Length).IndexOf(str, StringComparison.OrdinalIgnoreCase) > -1));
                    }
                }
                else // Search by: Name, Hostname
                {
                    return(info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1 || info.Host.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1);
                }
            };

            LoadSettings();

            SettingsManager.Current.PropertyChanged += Current_PropertyChanged;
        }
        public PuTTYControl(PuTTYSessionInfo info)
        {
            InitializeComponent();
            DataContext = this;

            _puTTYSessionInfo = info;

            resizeTimer.Tick    += ResizeTimer_Tick;
            resizeTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);

            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }
Esempio n. 7
0
        public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profileInfo)
        {
            var info = new PuTTYSessionInfo
            {
                Mode                  = profileInfo.PuTTY_ConnectionMode,
                HostOrSerialLine      = profileInfo.PuTTY_HostOrSerialLine,
                PortOrBaud            = profileInfo.PuTTY_OverridePortOrBaud ? profileInfo.PuTTY_PortOrBaud : Settings.Application.PuTTY.GetPortOrBaudByConnectionMode(profileInfo.PuTTY_ConnectionMode),
                Username              = profileInfo.PuTTY_OverrideUsername ? profileInfo.PuTTY_Username : SettingsManager.Current.PuTTY_Username,
                Profile               = profileInfo.PuTTY_OverrideProfile ? profileInfo.PuTTY_Profile : SettingsManager.Current.PuTTY_Profile,
                EnableLog             = profileInfo.PuTTY_OverrideEnableLog ? profileInfo.PuTTY_EnableLog : SettingsManager.Current.PuTTY_EnableSessionLog,
                LogMode               = profileInfo.PuTTY_OverrideLogMode ? profileInfo.PuTTY_LogMode : SettingsManager.Current.PuTTY_LogMode,
                LogPath               = profileInfo.PuTTY_OverrideLogPath ? profileInfo.PuTTY_LogPath : Settings.Application.PuTTY.LogPath,
                LogFileName           = profileInfo.PuTTY_OverrideLogFileName ? profileInfo.PuTTY_LogFileName : SettingsManager.Current.PuTTY_LogFileName,
                AdditionalCommandLine = profileInfo.PuTTY_OverrideAdditionalCommandLine ? profileInfo.PuTTY_AdditionalCommandLine : SettingsManager.Current.PuTTY_AdditionalCommandLine
            };

            return(info);
        }
Esempio n. 8
0
        public PuTTYSessionViewModel(Action <PuTTYSessionViewModel> saveCommand, Action <PuTTYSessionViewModel> cancelHandler, List <string> groups, PuTTYSessionInfo sessionInfo = null)
        {
            _saveCommand   = new RelayCommand(p => saveCommand(this));
            _cancelCommand = new RelayCommand(p => cancelHandler(this));

            _sessionInfo = sessionInfo ?? new PuTTYSessionInfo();

            Name = _sessionInfo.Name;
            Host = _sessionInfo.Host;

            // Get the group, if not --> get the first group (ascending), fallback --> default group
            Group = string.IsNullOrEmpty(_sessionInfo.Group) ? (groups.Count > 0 ? groups.OrderBy(x => x).First() : Application.Current.Resources["String_Default"] as string) : _sessionInfo.Group;
            Tags  = _sessionInfo.Tags;

            _groups = CollectionViewSource.GetDefaultView(groups);
            _groups.SortDescriptions.Add(new SortDescription());

            _isLoading = false;
        }