Beispiel #1
0
        /// <summary>
        /// Create a new PipeTerminalConnection
        /// </summary>
        /// <param name="param">Terminal parameter</param>
        /// <param name="settings">Terminal settings</param>
        /// <returns>created object</returns>
        /// <exception cref="PipeCreatorException">Creation was failed.</exception>
        public static PipeTerminalConnection CreateNewPipeTerminalConnection(PipeTerminalParameter param, PipeTerminalSettings settings)
        {
            Debug.Assert(param != null);
            Debug.Assert(settings != null);

            if (param.ExeFilePath != null) {
                try {
                    OverrideSettings(param, settings);
                    return OpenExeFile(param);
                }
                catch (Exception e) {
                    string message = PipePlugin.Instance.Strings.GetString("PipeCreator.LaunchingApplicationFailed");
                    throw new PipeCreatorException(message, e);
                }
            }
            else if (param.InputPipePath != null) {
                try {
                    return OpenNamedPipe(param);
                }
                catch (Exception e) {
                    string message = PipePlugin.Instance.Strings.GetString("PipeCreator.OpeningPipeFailed");
                    throw new PipeCreatorException(message, e);
                }
            }
            else {
                throw new ArgumentException("Parameter error: exe file or pipe path must be present.");
            }
        }
Beispiel #2
0
        public override ITerminalSettings Clone()
        {
            PipeTerminalSettings ts = new PipeTerminalSettings();

            ts.Import(this);
            return(ts);
        }
Beispiel #3
0
        /// <summary>
        /// Command execution
        /// </summary>
        public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            PipeTerminalParameter paramInit    = null;
            PipeTerminalSettings  settingsInit = null;

            IExtensionPoint ext = PipePlugin.Instance.PoderosaWorld.PluginManager.FindExtensionPoint("org.poderosa.terminalsessions.loginDialogUISupport");

            if (ext != null && ext.ExtensionInterface == typeof(ILoginDialogUISupport))
            {
                foreach (ILoginDialogUISupport sup in ext.GetExtensions())
                {
                    ITerminalParameter terminalParam;
                    ITerminalSettings  terminalSettings;
                    sup.FillTopDestination(typeof(PipeTerminalParameter), out terminalParam, out terminalSettings);
                    PipeTerminalParameter paramTemp    = terminalParam as PipeTerminalParameter;
                    PipeTerminalSettings  settingsTemp = terminalSettings as PipeTerminalSettings;
                    if (paramInit == null)
                    {
                        paramInit = paramTemp;
                    }
                    if (settingsInit == null)
                    {
                        settingsInit = settingsTemp;
                    }
                }
            }
            if (paramInit == null)
            {
                paramInit = new PipeTerminalParameter();
            }
            if (settingsInit == null)
            {
                settingsInit = new PipeTerminalSettings();
            }

            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            CommandResult commandResult = CommandResult.Failed;

            using (OpenPipeDialog dialog = new OpenPipeDialog()) {
                dialog.OpenPipe =
                    delegate(PipeTerminalParameter param, PipeTerminalSettings settings) {
                    PipeTerminalConnection connection = PipeCreator.CreateNewPipeTerminalConnection(param, settings);
                    commandResult = PipePlugin.Instance.CommandManager.Execute(
                        PipePlugin.Instance.TerminalSessionsService.TerminalSessionStartCommand,
                        window, connection, settings);
                    return(commandResult == CommandResult.Succeeded);
                };

                dialog.ApplyParams(paramInit, settingsInit);

                DialogResult dialogResult = dialog.ShowDialog(window != null ? window.AsForm() : null);
                if (dialogResult == DialogResult.Cancel)
                {
                    commandResult = CommandResult.Cancelled;
                }
            }

            return(commandResult);
        }
Beispiel #4
0
        public ITerminalConnection EstablishConnection(IPoderosaMainWindow window, ITerminalParameter param, ITerminalSettings settings)
        {
            PipeTerminalParameter tp = param as PipeTerminalParameter;
            PipeTerminalSettings  ts = settings as PipeTerminalSettings;

            Debug.Assert(tp != null && ts != null);

            return(PipeCreator.CreateNewPipeTerminalConnection(tp, ts));
        }
        public StructuredText Serialize(object obj) {
            PipeTerminalSettings ts = obj as PipeTerminalSettings;
            Debug.Assert(ts != null);

            StructuredText node = new StructuredText(this.ConcreteType.FullName);
            node.AddChild(PipePlugin.Instance.SerializeService.Serialize(typeof(TerminalSettings), obj));

            return node;
        }
        public object Deserialize(StructuredText node) {
            PipeTerminalSettings ts = new PipeTerminalSettings();

            StructuredText baseNode = node.GetChildOrNull(0);
            if (baseNode != null) {
                TerminalSettings baseTs = PipePlugin.Instance.SerializeService.Deserialize(baseNode) as TerminalSettings;
                if (baseTs != null) {
                    ts.Import(baseTs);
                }
            }
            return ts;
        }
Beispiel #7
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();
        }
Beispiel #8
0
        /// <summary>
        /// Command execution
        /// </summary>
        public override CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            PipeTerminalParameter paramInit = null;
            PipeTerminalSettings settingsInit = null;

            IExtensionPoint ext = PipePlugin.Instance.PoderosaWorld.PluginManager.FindExtensionPoint("org.poderosa.terminalsessions.loginDialogUISupport");
            if (ext != null && ext.ExtensionInterface == typeof(ILoginDialogUISupport)) {
                foreach (ILoginDialogUISupport sup in ext.GetExtensions()) {
                    ITerminalParameter terminalParam;
                    ITerminalSettings terminalSettings;
                    sup.FillTopDestination(typeof(PipeTerminalParameter), out terminalParam, out terminalSettings);
                    PipeTerminalParameter paramTemp = terminalParam as PipeTerminalParameter;
                    PipeTerminalSettings settingsTemp = terminalSettings as PipeTerminalSettings;
                    if (paramInit == null)
                        paramInit = paramTemp;
                    if (settingsInit == null)
                        settingsInit = settingsTemp;
                }
            }
            if (paramInit == null)
                paramInit = new PipeTerminalParameter();
            if (settingsInit == null)
                settingsInit = new PipeTerminalSettings();

            IPoderosaMainWindow window = (IPoderosaMainWindow)target.GetAdapter(typeof(IPoderosaMainWindow));

            CommandResult commandResult = CommandResult.Failed;

            using (OpenPipeDialog dialog = new OpenPipeDialog()) {

                dialog.OpenPipe =
                    delegate(PipeTerminalParameter param, PipeTerminalSettings settings) {
                        PipeTerminalConnection connection = PipeCreator.CreateNewPipeTerminalConnection(param, settings);
                        commandResult = PipePlugin.Instance.CommandManager.Execute(
                                            PipePlugin.Instance.TerminalSessionsService.TerminalSessionStartCommand,
                                            window, connection, settings);
                        return (commandResult == CommandResult.Succeeded);
                    };

                dialog.ApplyParams(paramInit, settingsInit);

                DialogResult dialogResult = dialog.ShowDialog(window != null ? window.AsForm() : null);
                if (dialogResult == DialogResult.Cancel)
                    commandResult = CommandResult.Cancelled;
            }

            return commandResult;
        }
Beispiel #9
0
        /// <summary>
        /// Modify icon to which is obtained from the executable file
        /// </summary>
        /// <param name="param"></param>
        /// <param name="settings"></param>
        private static void OverrideSettings(PipeTerminalParameter param, PipeTerminalSettings settings)
        {
            if (param.ExeFilePath != null)
            {
                Image icon = GetExeFileIcon(param.ExeFilePath);
                if (icon != null)
                {
                    Image oldIcon = settings.Icon;
                    settings.BeginUpdate();
                    settings.Icon = icon;
                    settings.EndUpdate();

                    // FIXME:
                    //   oldIcon may being used to repainting, so we don't dispose it here.
                    //   I don't know where the icon is disposed...
                    //
                    //if (oldIcon != null)
                    //    oldIcon.Dispose();
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Create a new PipeTerminalConnection
        /// </summary>
        /// <param name="param">Terminal parameter</param>
        /// <param name="settings">Terminal settings</param>
        /// <returns>created object</returns>
        /// <exception cref="PipeCreatorException">Creation was failed.</exception>
        public static PipeTerminalConnection CreateNewPipeTerminalConnection(PipeTerminalParameter param, PipeTerminalSettings settings)
        {
            Debug.Assert(param != null);
            Debug.Assert(settings != null);

            if (param.ExeFilePath != null)
            {
                try {
                    OverrideSettings(param, settings);
                    return(OpenExeFile(param));
                }
                catch (Exception e) {
                    string message = PipePlugin.Instance.Strings.GetString("PipeCreator.LaunchingApplicationFailed");
                    throw new PipeCreatorException(message, e);
                }
            }
            else if (param.InputPipePath != null)
            {
                try {
                    return(OpenNamedPipe(param));
                }
                catch (Exception e) {
                    string message = PipePlugin.Instance.Strings.GetString("PipeCreator.OpeningPipeFailed");
                    throw new PipeCreatorException(message, e);
                }
            }
            else
            {
                throw new ArgumentException("Parameter error: exe file or pipe path must be present.");
            }
        }
Beispiel #11
0
        /// <summary>
        /// Modify icon to which is obtained from the executable file
        /// </summary>
        /// <param name="param"></param>
        /// <param name="settings"></param>
        private static void OverrideSettings(PipeTerminalParameter param, PipeTerminalSettings settings) {
            if (param.ExeFilePath != null) {
                Image icon = GetExeFileIcon(param.ExeFilePath);
                if (icon != null) {
                    Image oldIcon = settings.Icon;
                    settings.BeginUpdate();
                    settings.Icon = icon;
                    settings.EndUpdate();

                    // FIXME:
                    //   oldIcon may being used to repainting, so we don't dispose it here.
                    //   I don't know where the icon is disposed...
                    //   
                    //if (oldIcon != null)
                    //    oldIcon.Dispose();
                }
            }
        }
Beispiel #12
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();
            }
        }
Beispiel #13
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);
            }
        }
 public override ITerminalSettings Clone() {
     PipeTerminalSettings ts = new PipeTerminalSettings();
     ts.Import(this);
     return ts;
 }
Beispiel #15
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;
            }
        }