protected void OnOK(object sender, EventArgs args)
        {
            this.DialogResult = DialogResult.None;
            _targetView       = GetTargetView();
            ITerminalParameter term = PrepareTerminalParameter();

            if (term == null)
            {
                return;            //設定に誤りがある場合
            }
            TerminalControl tc = (TerminalControl)_targetView.GetAdapter(typeof(TerminalControl));
            //Size sz = tc.CalcTerminalSize((_terminalSettings.RenderProfile == null) ?
            //            this.GetInitialRenderProfile() : _terminalSettings.RenderProfile);
            Size sz;

            if (_terminalSettings.RenderProfile == null)
            {
                using (RenderProfile profile = this.GetInitialRenderProfile())
                    sz = tc.CalcTerminalSize(profile);
            }
            else
            {
                sz = tc.CalcTerminalSize(_terminalSettings.RenderProfile);
            }
            term.SetTerminalSize(sz.Width, sz.Height);

            _loginButton.Enabled  = false;
            _cancelButton.Enabled = false;
            this.Cursor           = Cursors.WaitCursor;
            _originalText         = this.Text;
            this.Text             = String.Format("{0} - {1}", _originalText, TEnv.Strings.GetString("Caption.HowToCancel"));

            StartConnection();
        }
        public static ITerminalSession InvokeOpenSessionOrNull(ICommandTarget target, TerminalParam param)
        {
            ITerminalParameter tp = param.ConvertToTerminalParameter();
            ITerminalSettings  ts = CreateTerminalSettings(param);

            IViewManager pm = CommandTargetUtil.AsWindow(target).ViewManager;
            //独立ウィンドウにポップアップさせるようなことは考えていない
            IContentReplaceableView rv = (IContentReplaceableView)pm.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         tc = (TerminalControl)rv.GetCurrentContent().GetAdapter(typeof(TerminalControl));

            if (tc != null) //ターミナルコントロールがないときは無理に設定しにいかない
            {
                Size sz;
                if (ts.UsingDefaultRenderProfile)
                {
                    using (RenderProfile profile = MacroPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile())
                        sz = tc.CalcTerminalSize(profile);
                }
                else
                {
                    sz = tc.CalcTerminalSize(ts.RenderProfile);
                }
                //RenderProfile rp = ts.UsingDefaultRenderProfile? MacroPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile() : ts.RenderProfile;
                //Size sz = tc.CalcTerminalSize(rp);
                tp.SetTerminalSize(sz.Width, sz.Height);
            }


            return((ITerminalSession)MacroPlugin.Instance.WindowManager.ActiveWindow.AsForm().Invoke(new OpenSessionDelegate(OpenSessionOrNull), tp, ts));
        }
Exemple #3
0
        public static CommandResult OpenShortcutFile(ICommandTarget target, string filename)
        {
            IPoderosaMainWindow window = CommandTargetUtil.AsWindow(target);

            if (window == null)
            {
                window = (IPoderosaMainWindow)CommandTargetUtil.AsViewOrLastActivatedView(target).ParentForm.GetAdapter(typeof(IPoderosaMainWindow));
            }
            if (window == null)
            {
                return(CommandResult.Ignored);
            }

            if (!File.Exists(filename))
            {
                window.Warning(String.Format("{0} is not a file", filename));
                return(CommandResult.Failed);
            }

            ShortcutFileContent f = null;

            try {
                f = ShortcutFileContent.LoadFromXML(filename);
            }
            catch (Exception ex) {
                //変なファイルをドロップしたなどで例外は簡単に起こりうる
                window.Warning(String.Format("Failed to read {0}\n{1}", filename, ex.Message));
                return(CommandResult.Failed);
            }

            try {
                //独立ウィンドウにポップアップさせるようなことは考えていない
                IContentReplaceableView rv = (IContentReplaceableView)target.GetAdapter(typeof(IContentReplaceableView));
                if (rv == null)
                {
                    rv = (IContentReplaceableView)window.ViewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
                }

                TerminalControl tc = (TerminalControl)rv.GetCurrentContent().GetAdapter(typeof(TerminalControl));
                if (tc != null)   //ターミナルコントロールがないときは無理に設定しにいかない
                {
                    RenderProfile rp = f.TerminalSettings.UsingDefaultRenderProfile ? TerminalSessionsPlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile() : f.TerminalSettings.RenderProfile;
                    Size          sz = tc.CalcTerminalSize(rp);
                    f.TerminalParameter.SetTerminalSize(sz.Width, sz.Height);
                }

                ITerminalSession s = TerminalSessionsPlugin.Instance.TerminalSessionStartCommand.StartTerminalSession(target, f.TerminalParameter, f.TerminalSettings);
                return(s != null ? CommandResult.Succeeded : CommandResult.Failed);
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
                return(CommandResult.Failed);
            }
        }
        /// <summary>
        /// 接続
        /// </summary>
        public void Connect()
        {
            ITCPParameter tcp = null;

            // プロトコル
            if (_prof.Protocol == ConnectionMethod.Telnet)
            {
                // Telnet
                tcp             = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultTelnetParameter();
                tcp.Destination = _prof.HostName;
                tcp.Port        = _prof.Port;
                ITelnetParameter telnetParameter = null;
                telnetParameter = (ITelnetParameter)tcp.GetAdapter(typeof(ITelnetParameter));
                if (telnetParameter != null)
                {
                    telnetParameter.TelnetNewLine = _prof.TelnetNewLine;
                }
            }
            else if ((_prof.Protocol == ConnectionMethod.SSH1) || (_prof.Protocol == ConnectionMethod.SSH2))
            {
                // SSH
                ISSHLoginParameter ssh = ConnectProfilePlugin.Instance.ProtocolService.CreateDefaultSSHParameter();
                tcp                      = (ITCPParameter)ssh.GetAdapter(typeof(ITCPParameter));
                tcp.Destination          = _prof.HostName;
                tcp.Port                 = _prof.Port;
                ssh.Method               = (_prof.Protocol == ConnectionMethod.SSH1) ? SSHProtocol.SSH1 : SSHProtocol.SSH2;
                ssh.Account              = _prof.UserName;
                ssh.AuthenticationType   = ConvertAuth(_prof.AuthType);
                ssh.PasswordOrPassphrase = _prof.Password;
                ssh.IdentityFileName     = _prof.KeyFile;
                ssh.LetUserInputPassword = (_prof.AutoLogin == true) ? false : true;
            }

            // TerminalSettings(表示プロファイル/改行コード/文字コード)
            ITerminalSettings terminalSettings = ConnectProfilePlugin.Instance.TerminalEmulatorService.CreateDefaultTerminalSettings(_prof.HostName, null);

            terminalSettings.BeginUpdate();
            terminalSettings.RenderProfile = _prof.RenderProfile;
            terminalSettings.TransmitNL    = _prof.NewLine;
            terminalSettings.Encoding      = _prof.CharCode;
            terminalSettings.LocalEcho     = false;
            terminalSettings.EndUpdate();

            // TerminalParameter
            ITerminalParameter terminalParam = (ITerminalParameter)tcp.GetAdapter(typeof(ITerminalParameter));

            // ターミナルサイズ(これを行わないとPoderosa起動直後のOnReceptionが何故か機能しない, 行わない場合は2回目以降の接続時は正常)
            IViewManager            viewManager            = CommandTargetUtil.AsWindow(ConnectProfilePlugin.Instance.WindowManager.ActiveWindow).ViewManager;
            IContentReplaceableView contentReplaceableView = (IContentReplaceableView)viewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView));
            TerminalControl         terminalControl        = (TerminalControl)contentReplaceableView.GetCurrentContent().GetAdapter(typeof(TerminalControl));

            if (terminalControl != null)
            {
                Size size = terminalControl.CalcTerminalSize(terminalSettings.RenderProfile);
                terminalParam.SetTerminalSize(size.Width, size.Height);
            }

            // 接続(セッションオープン)
            _terminalSession = (ITerminalSession)ConnectProfilePlugin.Instance.WindowManager.ActiveWindow.AsForm().Invoke(new OpenSessionDelegate(InvokeOpenSessionOrNull), terminalParam, terminalSettings);

            // 自動ログイン/SU/実行コマンド
            if (_terminalSession != null)
            {
                // 受信データオブジェクト作成(ユーザからのキーボード入力が不可)
                ReceptionData pool = new ReceptionData();
                _terminalSession.Terminal.StartModalTerminalTask(pool);

                // Telnet自動ログイン
                if ((_prof.AutoLogin == true) && (_prof.Protocol == ConnectionMethod.Telnet))
                {
                    if (TelnetAutoLogin() != true)
                    {
                        return;
                    }
                }

                // SU
                if ((_prof.AutoLogin == true) && (_prof.SUUserName != ""))
                {
                    if (SUSwitch() != true)
                    {
                        return;
                    }
                }

                // 実行コマンド
                if ((_prof.AutoLogin == true) && (_prof.ExecCommand != ""))
                {
                    if (ExecCommand() != true)
                    {
                        return;
                    }
                }

                // 受信データオブジェクト定義解除(ユーザからのキーボード入力を許可)
                _terminalSession.Terminal.EndModalTerminalTask();
            }
        }