Exemplo n.º 1
0
        /// <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();
            }
        }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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;
            }
        }