//EXTP使用 public void ApplyParam() { ICygwinParameter parameter = null; ITerminalSettings settings = null; if (_loginDialogUISupport != null) { ITerminalParameter tp = null; _loginDialogUISupport.FillTopDestination(typeof(ICygwinParameter), out tp, out settings); parameter = tp == null ? null : (ICygwinParameter)tp.GetAdapter(typeof(ICygwinParameter)); } if (parameter == null) { parameter = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultCygwinParameter(); } if (settings == null) { settings = CygwinPlugin.Instance.CreateDefaultCygwinTerminalSettings(); } IAutoExecMacroParameter autoExecParams = parameter.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && CygwinPlugin.Instance.MacroEngine != null) { _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _autoExecMacroPathLabel.Enabled = false; _autoExecMacroPathBox.Enabled = false; _selectAutoExecMacroButton.Enabled = false; } ApplyParam(parameter, settings); }
//基本のスタートセッション public ITerminalSession StartTerminalSession(ICommandTarget target, ITerminalConnection connection, ITerminalSettings settings) { Debug.Assert(connection != null); Debug.Assert(settings != null); //ここでターミナルエミュレータの遅延初期化 TerminalSessionsPlugin.Instance.TerminalEmulatorService.LaterInitialize(); ISessionManager sm = (ISessionManager)TerminalSessionsPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager)); IPoderosaView view = ToPoderosaView(target); Debug.Assert(view != null); TerminalSession session = new TerminalSession(connection, settings); sm.StartNewSession(session, view); sm.ActivateDocument(session.Terminal.IDocument, ActivateReason.InternalAction); IAutoExecMacroParameter autoExecParam = connection.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null) { TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, session); } return(session); }
public void ApplyParam(SerialTerminalParam param, SerialTerminalSettings settings) { _terminalParam = param == null? new SerialTerminalParam() : param; _terminalSettings = settings == null?SerialPortUtil.CreateDefaultSerialTerminalSettings(_terminalParam.Port) : settings; _portBox.SelectedIndex = _terminalParam.Port - 1; //COM1からなので //これらのSelectedIndexの設定はコンボボックスに設定した項目順に依存しているので注意深くすること _baudRateBox.SelectedIndex = _baudRateBox.FindStringExact(_terminalSettings.BaudRate.ToString()); _dataBitsBox.SelectedIndex = _terminalSettings.ByteSize == 7? 0 : 1; _parityBox.SelectedIndex = (int)_terminalSettings.Parity; _stopBitsBox.SelectedIndex = (int)_terminalSettings.StopBits; _flowControlBox.SelectedIndex = (int)_terminalSettings.FlowControl; _encodingBox.SelectedIndex = (int)_terminalSettings.Encoding; _newLineBox.SelectedIndex = _newLineBox.FindStringExact(_terminalSettings.TransmitNL.ToString()); _localEchoBox.SelectedIndex = _terminalSettings.LocalEcho? 1 : 0; _transmitDelayPerCharBox.Text = _terminalSettings.TransmitDelayPerChar.ToString(); _transmitDelayPerLineBox.Text = _terminalSettings.TransmitDelayPerLine.ToString(); IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && SerialPortPlugin.Instance.MacroEngine != null) { _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _autoExecMacroPathLabel.Enabled = false; _autoExecMacroPathBox.Enabled = false; _selectAutoExecMacroButton.Enabled = false; } }
public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) { IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow)); if (window == null) { return(CommandResult.Ignored); } using (OpenSessionDialog dlg = new OpenSessionDialog(window)) { if (dlg.ShowDialog() == DialogResult.OK) { IContentReplaceableView view = (IContentReplaceableView)window.ViewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView)); IPoderosaView targetView = view.AssureViewClass(typeof(TerminalView)); ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager)); TerminalSession ts = new TerminalSession(dlg.TerminalConnection, dlg.TerminalSettings); sm.StartNewSession(ts, targetView); sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction); IAutoExecMacroParameter autoExecParam = dlg.TerminalConnection.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null) { TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts); } return(CommandResult.Succeeded); } return(CommandResult.Cancelled); } }
private bool ValidateParam() { SerialTerminalSettings settings = _terminalSettings; SerialTerminalParam param = _terminalParam; try { LogType logtype = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None); ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(false); //動作キャンセル } } param.Port = _portBox.SelectedIndex + 1; string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } settings.BeginUpdate(); if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.Caption = String.Format("COM{0}", param.Port); settings.BaudRate = Int32.Parse(_baudRateBox.Text); settings.ByteSize = (byte)(_dataBitsBox.SelectedIndex == 0? 7 : 8); settings.StopBits = (StopBits)_stopBitsBox.SelectedIndex; settings.Parity = (Parity)_parityBox.SelectedIndex; settings.FlowControl = (FlowControl)_flowControlBox.SelectedIndex; settings.Encoding = (EncodingType)_encodingBox.SelectedIndex; settings.LocalEcho = _localEchoBox.SelectedIndex == 1; settings.TransmitNL = (NewLine)EnumDescAttribute.For(typeof(NewLine)).FromDescription(_newLineBox.Text, LogType.None); settings.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text); settings.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text); settings.EndUpdate(); return(true); } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(false); } }
protected override ITerminalParameter PrepareTerminalParameter() { _param.Home = _homeDirectoryBox.Text; _param.ShellName = _shellBox.Text; //ログ設定 LogType logtype = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None); ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(null); //動作キャンセル } } ITerminalSettings settings = this.TerminalSettings; settings.BeginUpdate(); if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.Caption = _param.ShellBody; settings.Icon = Poderosa.TerminalSession.Properties.Resources.Cygwin16x16; settings.Encoding = (EncodingType)_encodingBox.SelectedIndex; settings.TerminalType = (TerminalType)_terminalTypeBox.SelectedIndex; settings.EndUpdate(); ITerminalParameter termParam = (ITerminalParameter)_param.GetAdapter(typeof(ITerminalParameter)); termParam.SetTerminalName(_terminalTypeBox.Text); // Used for TERM environment variable (LocalShellUtil) _param.CygwinDir = _cygwinDirBox.Text; if (_param.CygwinDir.Length > 0 && _param.CygwinDir[_param.CygwinDir.Length - 1] == Path.PathSeparator) { _param.CygwinDir = _param.CygwinDir.Substring(0, _param.CygwinDir.Length - 1); } string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = _param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } return((ITerminalParameter)_param.GetAdapter(typeof(ITerminalParameter))); }
private void InitUI() { ITCPParameter tcp = (ITCPParameter)_sshParam.GetAdapter(typeof(ITCPParameter)); _hostBox.Text = tcp.Destination; _methodBox.Text = _sshParam.Method.ToString(); //if(_sshParam.Port!=22) _methodBox.Text += String.Format(TEnv.Strings.GetString("Caption.SSHShortcutLoginDialog.NotStandardPort"), _sshParam.Port); _accountBox.Text = _sshParam.Account; _authenticationTypeBox.Text = _sshParam.AuthenticationType.ToString(); //さぼり _encodingBox.Text = EnumListItem <EncodingType> .CreateListItem(this.TerminalSettings.Encoding).Text; _logTypeBox.SelectedItem = LogType.None; // select EnumListItem<T> by T if (_sshParam.AuthenticationType == AuthenticationType.Password) { _privateKeyBox.Enabled = false; _privateKeySelect.Enabled = false; } else if (_sshParam.AuthenticationType == AuthenticationType.PublicKey) { _privateKeyBox.Text = _sshParam.IdentityFileName; } else if (_sshParam.AuthenticationType == AuthenticationType.KeyboardInteractive) { _privateKeyBox.Enabled = false; _privateKeySelect.Enabled = false; _passphraseBox.Enabled = false; } _passphraseBox.Text = ""; if (_sshParam.PasswordOrPassphrase.Length == 0 && TerminalSessionsPlugin.Instance.ProtocolService.ProtocolOptions.RetainsPassphrase) { string p = TerminalSessionsPlugin.Instance.ProtocolService.PassphraseCache.GetOrEmpty(tcp.Destination, _sshParam.Account); _passphraseBox.Text = p; } IAutoExecMacroParameter autoExecParams = _sshParam.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && TelnetSSHPlugin.Instance.MacroEngine != null) { _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _autoExecMacroPathLabel.Enabled = false; _autoExecMacroPathBox.Enabled = false; _selectAutoExecMacroButton.Enabled = false; } AdjustUI(); }
public void ApplyParam(IAdaptable destination, ITerminalSettings terminal) { _initializing = true; Debug.Assert(destination != null); Debug.Assert(terminal != null); this.TerminalSettings = terminal.Clone(); ITCPParameter tcp_destination = (ITCPParameter)destination.GetAdapter(typeof(ITCPParameter)); ISSHLoginParameter ssh_destination = (ISSHLoginParameter)destination.GetAdapter(typeof(ISSHLoginParameter)); bool is_telnet = ssh_destination == null; _methodBox.SelectedIndex = is_telnet? 0 : ssh_destination.Method == SSHProtocol.SSH1? 1 : 2; _portBox.SelectedIndex = _portBox.FindStringExact(PortDescription(tcp_destination.Port)); if (ssh_destination != null) { _userNameBox.SelectedIndex = _userNameBox.FindStringExact(ssh_destination.Account); _passphraseBox.Text = ssh_destination.PasswordOrPassphrase; if (ssh_destination.AuthenticationType == AuthenticationType.PublicKey) { _privateKeyFile.Text = ssh_destination.IdentityFileName; } else { _privateKeyFile.Text = ""; } _authOptions.SelectedIndex = ToAuthenticationIndex(ssh_destination.AuthenticationType); } IAutoExecMacroParameter autoExecParams = destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && TelnetSSHPlugin.Instance.MacroEngine != null) { _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _autoExecMacroPathLabel.Enabled = false; _autoExecMacroPathBox.Enabled = false; _selectAutoExecMacroButton.Enabled = false; } _encodingBox.SelectedIndex = (int)terminal.Encoding; _newLineBox.SelectedIndex = (int)terminal.TransmitNL; _localEchoBox.SelectedIndex = terminal.LocalEcho? 1 : 0; _terminalTypeBox.SelectedIndex = (int)terminal.TerminalType; _initializing = false; EnableValidControls(); }
public void ApplyParam(SerialTerminalParam param, SerialTerminalSettings settings) { _terminalParam = param == null ? new SerialTerminalParam() : param; _terminalSettings = settings == null?SerialPortUtil.CreateDefaultSerialTerminalSettings(_terminalParam.PortName) : settings; // 設定のポート名称のアイテムを選択。それが選択できなければ最初の項目を選択。 _portBox.SelectedItem = _terminalParam.PortName; if (_portBox.SelectedItem == null && 0 < _portBox.Items.Count) { _portBox.SelectedIndex = 0; } //これらのSelectedIndexの設定はコンボボックスに設定した項目順に依存しているので注意深くすること _baudRateBox.SelectedIndex = _baudRateBox.FindStringExact(_terminalSettings.BaudRate.ToString()); _dataBitsBox.SelectedIndex = _terminalSettings.ByteSize == 7 ? 0 : 1; _parityBox.SelectedItem = _terminalSettings.Parity; // select EnumListItem<T> by T _stopBitsBox.SelectedItem = _terminalSettings.StopBits; // select EnumListItem<T> by T _flowControlBox.SelectedItem = _terminalSettings.FlowControl; // select EnumListItem<T> by T _encodingBox.SelectedItem = _terminalSettings.Encoding; // select EnumListItem<T> by T _newLineBox.SelectedItem = _terminalSettings.TransmitNL; // select EnumListItem<T> by T _localEchoBox.SelectedIndex = _terminalSettings.LocalEcho ? 1 : 0; _transmitDelayPerCharBox.Text = _terminalSettings.TransmitDelayPerChar.ToString(); _transmitDelayPerLineBox.Text = _terminalSettings.TransmitDelayPerLine.ToString(); IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && SerialPortPlugin.Instance.MacroEngine != null) { _autoExecMacroPathBox.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _autoExecMacroPathLabel.Enabled = false; _autoExecMacroPathBox.Enabled = false; _selectAutoExecMacroButton.Enabled = false; } }
public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args) { IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow)); if (window == null) { return(CommandResult.Ignored); } TelnetSSHLoginDialog dlg = new TelnetSSHLoginDialog(window); dlg.ApplyParam(); CommandResult res = CommandResult.Cancelled; if (dlg.ShowDialog() == DialogResult.OK) { ITerminalConnection con = dlg.Result; if (con != null) { ISessionManager sm = (ISessionManager)TelnetSSHPlugin.Instance.PoderosaWorld.PluginManager.FindPlugin("org.poderosa.core.sessions", typeof(ISessionManager)); TerminalSession ts = new TerminalSession(con, dlg.TerminalSettings); sm.StartNewSession(ts, (IPoderosaView)dlg.TargetView.GetAdapter(typeof(IPoderosaView))); sm.ActivateDocument(ts.Terminal.IDocument, ActivateReason.InternalAction); IAutoExecMacroParameter autoExecParam = con.Destination.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParam != null && autoExecParam.AutoExecMacroPath != null && TelnetSSHPlugin.Instance.MacroEngine != null) { TelnetSSHPlugin.Instance.MacroEngine.RunMacro(autoExecParam.AutoExecMacroPath, ts); } return(CommandResult.Succeeded); } } dlg.Dispose(); return(res); }
private bool ValidateParams(out PipeTerminalParameter param, out PipeTerminalSettings settings) { PipeTerminalParameter paramTmp = new PipeTerminalParameter(); PipeTerminalSettings settingsTmp = new PipeTerminalSettings(); StringResource res = PipePlugin.Instance.Strings; try { string caption; if (_radioButtonProcess.Checked) { string exePath = _textBoxExePath.Text; if (exePath.Length == 0) { throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoExePath")); } paramTmp.ExeFilePath = exePath; paramTmp.CommandLineOptions = _textBoxCommandLineOptions.Text; paramTmp.EnvironmentVariables = _environmentVariables; caption = Path.GetFileName(exePath); } else if (_radioButtonPipe.Checked) { string path = _textBoxInputPath.Text; if (path.Length == 0) { throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoInputPath")); } paramTmp.InputPipePath = path; caption = Path.GetFileName(path); if (!_checkBoxBidirectinal.Checked) { path = _textBoxOutputPath.Text; if (path.Length == 0) { throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoOutputPath")); } paramTmp.OutputPipePath = path; caption += "/" + Path.GetFileName(path); } } else { throw new Exception(res.GetString("Form.OpenPipeDialog.Error.NoOpenMode")); } TerminalType terminalType = ((EnumListItem <TerminalType>)_comboBoxTerminalType.SelectedItem).Value; paramTmp.SetTerminalName(terminalType.ToString().ToLowerInvariant()); LogType logType = ((EnumListItem <LogType>)_comboBoxLogType.SelectedItem).Value; ISimpleLogSettings logSettings = null; if (logType != LogType.None) { string logFile = _textBoxLogFile.Text; LogFileCheckResult r = LogUtil.CheckLogFileName(logFile, this); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { throw new Exception(""); } logSettings = PipePlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings(); logSettings.LogPath = logFile; logSettings.LogType = logType; logSettings.LogAppend = (r == LogFileCheckResult.Append); } string autoExecMacroPath = null; if (_textBoxAutoExecMacroPath.Text.Length != 0) { autoExecMacroPath = _textBoxAutoExecMacroPath.Text; } IAutoExecMacroParameter autoExecParams = paramTmp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } settingsTmp.BeginUpdate(); settingsTmp.Caption = caption; settingsTmp.Icon = Poderosa.Pipe.Properties.Resources.Icon16x16; settingsTmp.Encoding = ((EnumListItem <EncodingType>)_comboBoxEncoding.SelectedItem).Value; settingsTmp.LocalEcho = _comboBoxLocalEcho.SelectedIndex == 1; settingsTmp.TransmitNL = ((EnumListItem <NewLine>)_comboBoxNewLine.SelectedItem).Value; settingsTmp.TerminalType = terminalType; if (logSettings != null) { settingsTmp.LogSettings.Reset(logSettings); } settingsTmp.EndUpdate(); param = paramTmp; settings = settingsTmp; return(true); } catch (Exception e) { if (e.Message.Length > 0) { GUtil.Warning(this, e.Message); } param = null; settings = null; return(false); } }
/// <summary> /// Validates input values and constructs parameter objects. /// </summary> /// <param name="telnetParam">Telnet parameter object is set when this method returns true.</param> /// <param name="terminalSettings">terminal settings object is set when this method returns true.</param> /// <param name="errorMessage">validation error message is set when this method returns false. this can be null when displaying error message is not needed.</param> /// <returns>true if all validations passed and parameter objects were created.</returns> private bool Validate(out ITCPParameter telnetParam, out ITerminalSettings terminalSettings, out string errorMessage) { telnetParam = null; terminalSettings = null; errorMessage = null; var telnet = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter(); var tcp = (ITCPParameter)telnet.GetAdapter(typeof(ITCPParameter)); var protocolParam = (ITelnetParameter)telnet.GetAdapter(typeof(ITelnetParameter)); tcp.Destination = _hostBox.Text; if (String.IsNullOrEmpty(tcp.Destination)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty"); return(false); } int port; if (Int32.TryParse(_portBox.Text, out port) && port >= 0 && port <= 65535) { tcp.Port = port; } else { errorMessage = String.Format( TEnv.Strings.GetString("Message.LoginDialog.InvalidPort"), _portBox.Text); return(false); } //--- Log settings ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings(); logSettings.LogType = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; if (logSettings.LogType != LogType.None) { logSettings.LogPath = _logFileBox.Text; LogFileCheckResult r = LogUtil.CheckLogFileName(logSettings.LogPath, this.ParentForm); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { errorMessage = null; return(false); } logSettings.LogAppend = (r == LogFileCheckResult.Append); } //--- Terminal settings ITerminalParameter termParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminalType = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value; termParam.SetTerminalName(terminalType.ToTermValue()); string terminalCaption = tcp.Destination; Image terminalIcon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16; ITerminalSettings termSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(terminalCaption, terminalIcon); termSettings.BeginUpdate(); termSettings.Encoding = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value; termSettings.LocalEcho = ((ListItem <bool>)_localEchoBox.SelectedItem).Value; termSettings.TransmitNL = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value; termSettings.TerminalType = terminalType; termSettings.LogSettings.Reset(logSettings); termSettings.EndUpdate(); //--- TELNET protocol settings protocolParam.TelnetNewLine = (termSettings.TransmitNL == NewLine.CRLF) ? _telnetNewLine.Checked : false; //--- Macro IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) // macro plugin is enabled { if (!String.IsNullOrEmpty(_autoExecMacroPathBox.Text)) { autoExecParams.AutoExecMacroPath = _autoExecMacroPathBox.Text; } else { autoExecParams.AutoExecMacroPath = null; } } telnetParam = tcp; terminalSettings = termSettings; return(true); }
//入力内容に誤りがあればそれを警告してnullを返す。なければ必要なところを埋めたTCPTerminalParamを返す private ISSHLoginParameter ValidateContent() { ISSHLoginParameter p = (ISSHLoginParameter)_sshParam.Clone(); string msg = null; try { LogType logtype = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(null); //動作キャンセル } } ITerminalSettings settings = this.TerminalSettings; if (logsettings != null) { settings.BeginUpdate(); settings.LogSettings.Reset(logsettings); settings.EndUpdate(); } ITerminalParameter param = (ITerminalParameter)p.GetAdapter(typeof(ITerminalParameter)); param.SetTerminalName(ToTerminalName(settings.TerminalType)); if (p.AuthenticationType == AuthenticationType.PublicKey) { if (!File.Exists(_privateKeyBox.Text)) { msg = TEnv.Strings.GetString("Message.SSHShortcutLoginDialog.KeyFileNotExist"); } else { p.IdentityFileName = _privateKeyBox.Text; } } p.PasswordOrPassphrase = _passphraseBox.Text; string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = p.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } if (msg != null) { GUtil.Warning(this, msg); return(null); } else { return(p); } } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(null); } }
/// <summary> /// Validates input values and constructs parameter objects. /// </summary> /// <param name="loginParam">SSH parameter object is set when this method returns true.</param> /// <param name="terminalSettings">terminal settings object is set when this method returns true.</param> /// <param name="errorMessage">validation error message is set when this method returns false. this can be null when displaying error message is not needed.</param> /// <returns>true if all validations passed and parameter objects were created.</returns> private bool Validate(out ISSHLoginParameter loginParam, out ITerminalSettings terminalSettings, out string errorMessage) { loginParam = null; terminalSettings = null; errorMessage = null; var ssh = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter(); var tcp = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter)); //--- SSH connection settings if (_ssh1RadioButton.Checked) { ssh.Method = SSHProtocol.SSH1; } else if (_ssh2RadioButton.Checked) { ssh.Method = SSHProtocol.SSH2; } else { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.ProtocolVersionIsNotSpecified"); return(false); } tcp.Destination = _hostBox.Text; if (String.IsNullOrEmpty(tcp.Destination)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty"); return(false); } int port; if (Int32.TryParse(_portBox.Text, out port) && port >= 0 && port <= 65535) { tcp.Port = port; } else { errorMessage = String.Format( TEnv.Strings.GetString("Message.LoginDialog.InvalidPort"), _portBox.Text); return(false); } ssh.Account = _userNameBox.Text; AuthType authType = ((EnumListItem <AuthType>)_authOptions.SelectedItem).Value; ssh.AuthenticationType = authType.ToAuthenticationType(); if (ssh.AuthenticationType == AuthenticationType.PublicKey) { ssh.IdentityFileName = _privateKeyFile.Text; if (String.IsNullOrEmpty(ssh.IdentityFileName)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.PrivateKeyFileIsNotSpecified"); return(false); } if (!File.Exists(ssh.IdentityFileName)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.KeyFileNotExist"); return(false); } } if (ssh.AuthenticationType == AuthenticationType.Password || ssh.AuthenticationType == AuthenticationType.PublicKey) { ssh.PasswordOrPassphrase = _passphraseBox.Text; } //--- Log settings ISimpleLogSettings logSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultSimpleLogSettings(); logSettings.LogType = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; if (logSettings.LogType != LogType.None) { logSettings.LogPath = _logFileBox.Text; LogFileCheckResult r = LogUtil.CheckLogFileName(logSettings.LogPath, this.ParentForm); if (r == LogFileCheckResult.Cancel || r == LogFileCheckResult.Error) { errorMessage = null; return(false); } logSettings.LogAppend = (r == LogFileCheckResult.Append); } //--- Terminal settings ITerminalParameter termParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminalType = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value; termParam.SetTerminalName(terminalType.ToTermValue()); string terminalCaption = tcp.Destination; Image terminalIcon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16; ITerminalSettings termSettings = TerminalSessionsPlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(terminalCaption, terminalIcon); termSettings.BeginUpdate(); termSettings.Encoding = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value; termSettings.LocalEcho = ((ListItem <bool>)_localEchoBox.SelectedItem).Value; termSettings.TransmitNL = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value; termSettings.TerminalType = terminalType; termSettings.LogSettings.Reset(logSettings); termSettings.EndUpdate(); //--- X11 forwarding settings if (_useX11ForwardingCheckBox.Checked) { if (String.IsNullOrEmpty(_x11DisplayText.Text)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11DisplayIsNotEntered"); return(false); } int display; if (!Int32.TryParse(_x11DisplayText.Text, out display) || display < 0 || display > (65535 - 6000)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.InvalidX11Display"); return(false); } X11ForwardingParams x11Param = new X11ForwardingParams(display); if (String.IsNullOrEmpty(_x11ScreenText.Text)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11ScreenIsNotEntered"); return(false); } int screen; if (!Int32.TryParse(_x11ScreenText.Text, out screen) || screen < 0) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.InvalidX11Screen"); return(false); } x11Param.Screen = screen; if (_x11NeedAuthCheckBox.Checked) { x11Param.NeedAuth = true; x11Param.XauthorityFile = _x11XauthorityText.Text; if (String.IsNullOrEmpty(x11Param.XauthorityFile)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.XauthorityFileIsNotSpecified"); return(false); } } else { x11Param.NeedAuth = false; } if (_x11UseCygwinDomainSocketCheckBox.Checked) { x11Param.UseCygwinUnixDomainSocket = true; x11Param.X11UnixFolder = _x11CygwinX11UnixFolderText.Text; if (String.IsNullOrEmpty(x11Param.X11UnixFolder)) { errorMessage = TEnv.Strings.GetString("Message.LoginDialog.X11UnixFolderIsNotSpecified"); return(false); } } ssh.EnableX11Forwarding = true; ssh.X11Forwarding = x11Param; } else { ssh.EnableX11Forwarding = false; ssh.X11Forwarding = null; } //--- Agent forwarding settings if (_useAgentForwardingCheckBox.Checked) { ssh.EnableAgentForwarding = true; ssh.AgentForwardingAuthKeyProvider = null; // set later } else { ssh.EnableAgentForwarding = false; ssh.AgentForwardingAuthKeyProvider = null; } //--- Macro IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) // macro plugin is enabled { if (!String.IsNullOrEmpty(_autoExecMacroPathBox.Text)) { autoExecParams.AutoExecMacroPath = _autoExecMacroPathBox.Text; } else { autoExecParams.AutoExecMacroPath = null; } } loginParam = ssh; terminalSettings = termSettings; return(true); }
/// <summary> /// Apply parameters to controls /// </summary> /// <param name="param">Terminal parameters</param> /// <param name="settings">Terminal settings</param> public void ApplyParams(PipeTerminalParameter param, PipeTerminalSettings settings) { Debug.Assert(param != null); Debug.Assert(settings != null); Control boxToFocus = null; bool isProcessMode = true; // process mode is default bool isBidirectinal = true; // bidirectinal is default boxToFocus = _textBoxExePath; if (param.ExeFilePath != null) { _textBoxExePath.Text = param.ExeFilePath; if (param.CommandLineOptions != null) { _textBoxCommandLineOptions.Text = param.CommandLineOptions; } _environmentVariables = param.EnvironmentVariables; } else if (param.InputPipePath != null) { isProcessMode = false; _textBoxInputPath.Text = param.InputPipePath; if (param.OutputPipePath != null) { isBidirectinal = false; _textBoxOutputPath.Text = param.OutputPipePath; } boxToFocus = _textBoxInputPath; } SetMode(isProcessMode); SetBidirectional(isBidirectinal); _comboBoxLogType.SelectedItem = LogType.None; // select EnumListItem<T> by T _textBoxLogFile.Enabled = false; _buttonBrowseLogFile.Enabled = false; _comboBoxEncoding.SelectedItem = settings.Encoding; // select EnumListItem<T> by T _comboBoxNewLine.SelectedItem = settings.TransmitNL; // select EnumListItem<T> by T _comboBoxLocalEcho.SelectedIndex = settings.LocalEcho ? 1 : 0; _comboBoxTerminalType.SelectedItem = settings.TerminalType; // select EnumListItem<T> by T IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null && PipePlugin.Instance.MacroEngine != null) { _textBoxAutoExecMacroPath.Text = (autoExecParams.AutoExecMacroPath != null) ? autoExecParams.AutoExecMacroPath : String.Empty; } else { _labelAutoExecMacroPath.Enabled = false; _textBoxAutoExecMacroPath.Enabled = false; _buttonSelectAutoExecMacro.Enabled = false; } if (boxToFocus != null) { boxToFocus.Focus(); } }
//入力内容に誤りがあればそれを警告してnullを返す。なければ必要なところを埋めたTCPTerminalParamを返す private ITerminalParameter ValidateContent() { string msg = null; ITCPParameter tcp = null; ISSHLoginParameter ssh = null; try { ConnectionMethod m = ParseMethod(_methodBox.Text); if (m == ConnectionMethod.Telnet) { tcp = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultTelnetParameter(); } else { ISSHLoginParameter sp = TerminalSessionsPlugin.Instance.ProtocolService.CreateDefaultSSHParameter(); tcp = (ITCPParameter)sp.GetAdapter(typeof(ITCPParameter)); ssh = sp; ssh.Method = m == ConnectionMethod.SSH1? SSHProtocol.SSH1 : SSHProtocol.SSH2; ssh.Account = _userNameBox.Text; ssh.PasswordOrPassphrase = _passphraseBox.Text; } tcp.Destination = _hostBox.Text; try { tcp.Port = ParsePort(_portBox.Text); } catch (FormatException ex) { msg = ex.Message; } if (_hostBox.Text.Length == 0) { msg = TEnv.Strings.GetString("Message.LoginDialog.HostIsEmpty"); } //ログ設定 LogType logtype = (LogType)EnumDescAttribute.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None); ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(null); //動作キャンセル } } ITerminalParameter param = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter)); TerminalType terminal_type = (TerminalType)_terminalTypeBox.SelectedIndex; param.SetTerminalName(ToTerminalName(terminal_type)); if (ssh != null) { Debug.Assert(ssh != null); ssh.AuthenticationType = ToAuthenticationType(_authOptions.SelectedIndex); if (ssh.AuthenticationType == AuthenticationType.PublicKey) { if (!File.Exists(_privateKeyFile.Text)) { msg = TEnv.Strings.GetString("Message.LoginDialog.KeyFileNotExist"); } else { ssh.IdentityFileName = _privateKeyFile.Text; } } } string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = tcp.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } ITerminalSettings settings = this.TerminalSettings; settings.BeginUpdate(); settings.Caption = _hostBox.Text; settings.Icon = Poderosa.TerminalSession.Properties.Resources.NewConnection16x16; settings.Encoding = (EncodingType)_encodingBox.SelectedIndex; settings.LocalEcho = _localEchoBox.SelectedIndex == 1; settings.TransmitNL = (NewLine)EnumDescAttribute.For(typeof(NewLine)).FromDescription(_newLineBox.Text, NewLine.CR); settings.TerminalType = terminal_type; if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.EndUpdate(); if (msg != null) { ShowError(msg); return(null); } else { return((ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter))); } } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(null); } }
private bool ValidateParam() { SerialTerminalSettings settings = _terminalSettings; SerialTerminalParam param = _terminalParam; try { LogType logtype = ((EnumListItem <LogType>)_logTypeBox.SelectedItem).Value; ISimpleLogSettings logsettings = null; if (logtype != LogType.None) { logsettings = CreateSimpleLogSettings(logtype, _logFileBox.Text); if (logsettings == null) { return(false); //動作キャンセル } } param.PortName = _portBox.SelectedItem as string; if (param.PortName == null) { return(false); } string autoExecMacroPath = null; if (_autoExecMacroPathBox.Text.Length != 0) { autoExecMacroPath = _autoExecMacroPathBox.Text; } IAutoExecMacroParameter autoExecParams = param.GetAdapter(typeof(IAutoExecMacroParameter)) as IAutoExecMacroParameter; if (autoExecParams != null) { autoExecParams.AutoExecMacroPath = autoExecMacroPath; } settings.BeginUpdate(); if (logsettings != null) { settings.LogSettings.Reset(logsettings); } settings.Caption = param.PortName; settings.BaudRate = Int32.Parse(_baudRateBox.Text); settings.ByteSize = (byte)(_dataBitsBox.SelectedIndex == 0 ? 7 : 8); settings.StopBits = ((EnumListItem <StopBits>)_stopBitsBox.SelectedItem).Value; settings.Parity = ((EnumListItem <Parity>)_parityBox.SelectedItem).Value; settings.FlowControl = ((EnumListItem <FlowControl>)_flowControlBox.SelectedItem).Value; settings.Encoding = ((EnumListItem <EncodingType>)_encodingBox.SelectedItem).Value; settings.LocalEcho = _localEchoBox.SelectedIndex == 1; settings.TransmitNL = ((EnumListItem <NewLine>)_newLineBox.SelectedItem).Value; settings.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text); settings.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text); settings.EndUpdate(); return(true); } catch (Exception ex) { GUtil.Warning(this, ex.Message); return(false); } }