Ejemplo n.º 1
0
        /// <summary>
        /// CSVエクスポートクリックイベント
        /// </summary>
        private void _csvExportButton_Click(object sender, System.EventArgs e)
        {
            StreamWriter sw       = null;
            bool         delPWFlg = false;

            if (_saveCSVFileDialog.ShowDialog() == DialogResult.OK)
            {
                // パスワード出力/削除確認
                if (ConnectProfilePlugin.AskUserYesNoInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVExportDetetePasssword"), MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    delPWFlg = true;
                }

                // CSVファイル出力
                try {
                    sw = new System.IO.StreamWriter(_saveCSVFileDialog.FileName, false, System.Text.Encoding.UTF8);
                    sw.WriteLine(_cmd.CSVHeader);
                    foreach (ConnectProfileStruct prof in ConnectProfilePlugin.Profiles)
                    {
                        sw.WriteLine(_cmd.ConvertCSV(prof, delPWFlg));
                    }
                    ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVExportComplete"), MessageBoxIcon.Information);
                } catch (Exception ex) {
                    ConnectProfilePlugin.MessageBoxInvoke(ex.Message, MessageBoxIcon.Error);
                } finally {
                    if (sw != null)
                    {
                        sw.Close();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// プロファイル削除
        /// </summary>
        private void DeleteProfile()
        {
            ConnectProfileStruct prof = GetSelectedProfile();

            if (prof != null)
            {
                if (ConnectProfilePlugin.AskUserYesNoInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.ConfirmProfileDelete"), MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    _cmd.DeleteProfileCommand(ConnectProfilePlugin.Profiles, prof);
                    RefreshAllProfiles();
                    RefreshSelectCount();
                }
            }
        }
        /// <summary>
        /// SUスイッチ
        /// </summary>
        private bool SUSwitch()
        {
            // ユーザ名
            TransmitLn(string.Format("{0} {1}", _prof.SUType, _prof.SUUserName));

            // パスワード
            if (WaitRecv(_prof.PasswordPrompt) != true)
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.Connect.PasswordPromptNotFound"), MessageBoxIcon.Warning);
                _terminalSession.Terminal.EndModalTerminalTask();
                return(false);
            }
            TransmitLn(_prof.SUPassword);

            return(true);
        }
 private void OnOK(object sender, EventArgs args)
 {
     if (_backgroundImageBox.Text.Length > 0)
     {
         try {
             Image.FromFile(_backgroundImageBox.Text);
         }
         catch (Exception) {
             ConnectProfilePlugin.MessageBoxInvoke(string.Format(ConnectProfilePlugin.Strings.GetString("Message.EditRenderProfile.InvalidPicture"), _backgroundImageBox.Text), MessageBoxIcon.Error);
             this.DialogResult = DialogResult.None;
             return;
         }
     }
     _profile.BackgroundImageFileName = _backgroundImageBox.Text;
     _profile.ImageStyle = ((EnumListItem <ImageStyle>)_imageStyleBox.SelectedItem).Value;
 }
        //固定長フォントを使っているとき、認められていないサイズを指定していたら警告してfalseを返す。
        //allowed_sizesはサイズ指定のリストに含まれているものを使用すること!
        private bool CheckFixedSizeFont(string name, params float[] allowed_sizes)
        {
            if (_asciiFont.Name == name || _cjkFont.Name == name)
            {
                float sz        = GetFontSize();
                bool  contained = false;
                float diff      = Single.MaxValue;
                float nearest   = 0;
                foreach (float t in allowed_sizes)
                {
                    if (t == sz)
                    {
                        contained = true;
                        break;
                    }
                    else
                    {
                        if (diff > Math.Abs(sz - t))
                        {
                            diff    = Math.Abs(sz - t);
                            nearest = t;
                        }
                    }
                }

                if (!contained)
                {
                    ConnectProfilePlugin.MessageBoxInvoke(string.Format(ConnectProfilePlugin.Strings.GetString("Message.GFontDialog.NotTrueTypeWarning"), name, nearest), MessageBoxIcon.Error);
                    _fontSizeList.SelectedIndex = _fontSizeList.FindStringExact(nearest.ToString());
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// Telnet自動ログイン
        /// </summary>
        private bool TelnetAutoLogin()
        {
            // ユーザ名
            if (WaitRecv(_prof.LoginPrompt) != true)
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.Connect.LoginPromptNotFound"), MessageBoxIcon.Warning);
                _terminalSession.Terminal.EndModalTerminalTask();
                return(false);
            }
            TransmitLn(_prof.UserName);

            // パスワード
            if (WaitRecv(_prof.PasswordPrompt) != true)
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.Connect.PasswordPromptNotFound"), MessageBoxIcon.Warning);
                _terminalSession.Terminal.EndModalTerminalTask();
                return(false);
            }
            TransmitLn(_prof.Password);

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public override void InitializePlugin(IPoderosaWorld poderosa)
        {
            base.InitializePlugin(poderosa);
            _instance = this;

            // 文字列リソース読み込み
            _stringResource = new Poderosa.StringResource("Contrib.ConnectProfile.strings", typeof(ConnectProfilePlugin).Assembly);
            ConnectProfilePlugin.Instance.PoderosaWorld.Culture.AddChangeListener(_stringResource);

            // コマンド登録
            IPluginManager pm = poderosa.PluginManager;

            _coreServices           = (ICoreServices)poderosa.GetAdapter(typeof(ICoreServices));
            _terminalEmulatorPlugin = (ITerminalEmulatorService)pm.FindPlugin("org.poderosa.terminalemulator", typeof(ITerminalEmulatorService));
            ConnectProfileCommand.Register(_coreServices.CommandManager);

            // メニューリスト作成
            ConnectProfileMenuGroup        menulist        = new ConnectProfileMenuGroup();
            ConnectProfileContextMenuGroup contextmenulist = new ConnectProfileContextMenuGroup();

            // メニュー登録
            IExtensionPoint toolmenu = pm.FindExtensionPoint("org.poderosa.menu.tool");

            toolmenu.RegisterExtension(menulist);

            // コンテキストメニュー登録
            IExtensionPoint contextmenu = pm.FindExtensionPoint("org.poderosa.terminalemulator.contextMenu");

            contextmenu.RegisterExtension(contextmenulist);

            // 設定ファイル連携
            _connectProfileOptionSupplier = new ConnectProfileOptionsSupplier();
            _coreServices.PreferenceExtensionPoint.RegisterExtension(_connectProfileOptionSupplier);

            // 接続プロファイル
            _profiles = new ConnectProfileList();
        }
        /// <summary>
        /// CSVデータ整合性チェック
        /// </summary>
        /// <param name="data">CSVデータ</param>
        public ConnectProfileStruct CheckCSVData(string data)
        {
            ConnectProfileStruct     prof            = new ConnectProfileStruct();
            ITerminalEmulatorOptions terminalOptions = ConnectProfilePlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions;

            string[] ary = data.Split(',');
            int      tmp;
            float    tmpfloat;

            // ホスト名
            if (ary[0] != "")
            {
                prof.HostName = ary[0];
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidHostName"), MessageBoxIcon.Error);
                return(null);
            }

            // プロトコル(
            if (ary[1].ToLower() == "telnet")
            {
                prof.Protocol = ConnectionMethod.Telnet;
            }
            else if (ary[1].ToLower() == "ssh1")
            {
                prof.Protocol = ConnectionMethod.SSH1;
            }
            else if (ary[1].ToLower() == "ssh2")
            {
                prof.Protocol = ConnectionMethod.SSH2;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidProtocol"), MessageBoxIcon.Error);
                return(null);
            }

            // ポート
            if (int.TryParse(ary[2], out tmp) == true)
            {
                prof.Port = tmp;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidPort"), MessageBoxIcon.Error);
                return(null);
            }

            // SSH認証方法(空白=Password)
            if ((ary[3].ToLower() == "password") || (ary[3] == ""))
            {
                prof.AuthType = AuthType.Password;
            }
            else if (ary[3].ToLower() == "publickey")
            {
                prof.AuthType = AuthType.PublicKey;
            }
            else if (ary[3].ToLower() == "keyboardinteractive")
            {
                prof.AuthType = AuthType.KeyboardInteractive;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidAuthType"), MessageBoxIcon.Error);
                return(null);
            }

            // 秘密鍵ファイル/ユーザ名/パスワード
            prof.KeyFile  = ary[4];
            prof.UserName = ary[5];
            prof.Password = ary[6];

            // 自動ログイン(空白=false)
            if (ary[7].ToLower() == "true")
            {
                prof.AutoLogin = true;
            }
            else if ((ary[7].ToLower() == "false") || ary[7] == "")
            {
                prof.AutoLogin = false;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidAutoLogin"), MessageBoxIcon.Error);
                return(null);
            }

            // プロンプト/実行コマンド/SU
            prof.LoginPrompt    = ary[8];
            prof.PasswordPrompt = ary[9];
            prof.ExecCommand    = ary[10];
            prof.SUUserName     = ary[11];
            prof.SUPassword     = ary[12];

            // SUコマンド
            if (ary[13].ToLower() == "")
            {
                prof.SUType = "";
            }
            else if (ary[13].ToLower() == ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio1"))
            {
                prof.SUType = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio1");
            }
            else if (ary[13].ToLower() == ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio2"))
            {
                prof.SUType = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio2");
            }
            else if (ary[13].ToLower() == ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio3"))
            {
                prof.SUType = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio3");
            }
            else if (ary[13].ToLower() == ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio4"))
            {
                prof.SUType = ConnectProfilePlugin.Strings.GetString("Form.AddProfile._suTypeRadio4");
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidSUType"), MessageBoxIcon.Error);
                return(null);
            }

            // 文字コード(空白=UTF8)
            if (ary[14].ToLower() == "iso8859_1")
            {
                prof.CharCode = EncodingType.ISO8859_1;
            }
            else if ((ary[14].ToLower() == "utf8") || (ary[14]) == "")
            {
                prof.CharCode = EncodingType.UTF8;
            }
            else if (ary[14].ToLower() == "euc_jp")
            {
                prof.CharCode = EncodingType.EUC_JP;
            }
            else if (ary[14].ToLower() == "shift_jis")
            {
                prof.CharCode = EncodingType.SHIFT_JIS;
            }
            else if (ary[14].ToLower() == "gb2312")
            {
                prof.CharCode = EncodingType.GB2312;
            }
            else if (ary[14].ToLower() == "big5")
            {
                prof.CharCode = EncodingType.BIG5;
            }
            else if (ary[14].ToLower() == "euc_cn")
            {
                prof.CharCode = EncodingType.EUC_CN;
            }
            else if (ary[14].ToLower() == "euc_kr")
            {
                prof.CharCode = EncodingType.EUC_KR;
            }
            else if (ary[14].ToLower() == "utf8_latin")
            {
                prof.CharCode = EncodingType.UTF8_Latin;
            }
            else if (ary[14].ToLower() == "oem850")
            {
                prof.CharCode = EncodingType.OEM850;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidCharCode"), MessageBoxIcon.Error);
                return(null);
            }

            // 改行コード(空白=CR)
            if ((ary[15].ToLower() == "cr") || (ary[15] == ""))
            {
                prof.NewLine = NewLine.CR;
            }
            else if (ary[15].ToLower() == "lf")
            {
                prof.NewLine = NewLine.LF;
            }
            else if (ary[15].ToLower() == "crlf")
            {
                prof.NewLine = NewLine.CRLF;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidNewLine"), MessageBoxIcon.Error);
                return(null);
            }

            // TelnetNewLine(空白=true)
            if ((ary[16].ToLower() == "true") || (ary[16] == ""))
            {
                prof.TelnetNewLine = true;
            }
            else if (ary[16].ToLower() == "false")
            {
                prof.TelnetNewLine = false;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidTelnetNewLine"), MessageBoxIcon.Error);
                return(null);
            }

            // ターミナル種類(空白=XTerm)
            if (ary[17].ToLower() == "kterm")
            {
                prof.TerminalType = TerminalType.KTerm;
            }
            else if (ary[17].ToLower() == "vt100")
            {
                prof.TerminalType = TerminalType.VT100;
            }
            else if ((ary[17].ToLower() == "xterm") || (ary[17] == ""))
            {
                prof.TerminalType = TerminalType.XTerm;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidTerminalType"), MessageBoxIcon.Error);
                return(null);
            }

            // 表示オプション(背景/フォント/エスケープシーケンス色)
            prof.RenderProfile            = ConnectProfilePlugin.Instance.TerminalEmulatorService.TerminalEmulatorOptions.CreateRenderProfile();
            prof.RenderProfile.ForeColor  = Poderosa.ParseUtil.ParseColor(ary[18].ToLower(), terminalOptions.TextColor);
            prof.RenderProfile.BackColor  = Poderosa.ParseUtil.ParseColor(ary[19].ToLower(), terminalOptions.BGColor);
            prof.RenderProfile.ESColorSet = new EscapesequenceColorSet();
            prof.RenderProfile.ESColorSet.ResetToDefault();
            prof.RenderProfile.ESColorSet[0] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[20].ToLower(), terminalOptions.EscapeSequenceColorSet[0].Color), false);
            prof.RenderProfile.ESColorSet[1] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[21].ToLower(), terminalOptions.EscapeSequenceColorSet[1].Color), false);
            prof.RenderProfile.ESColorSet[2] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[22].ToLower(), terminalOptions.EscapeSequenceColorSet[2].Color), false);
            prof.RenderProfile.ESColorSet[3] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[23].ToLower(), terminalOptions.EscapeSequenceColorSet[3].Color), false);
            prof.RenderProfile.ESColorSet[4] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[24].ToLower(), terminalOptions.EscapeSequenceColorSet[4].Color), false);
            prof.RenderProfile.ESColorSet[5] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[25].ToLower(), terminalOptions.EscapeSequenceColorSet[5].Color), false);
            prof.RenderProfile.ESColorSet[6] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[26].ToLower(), terminalOptions.EscapeSequenceColorSet[6].Color), false);
            prof.RenderProfile.ESColorSet[7] = new ESColor(Poderosa.ParseUtil.ParseColor(ary[27].ToLower(), terminalOptions.EscapeSequenceColorSet[7].Color), false);

            // 表示オプション(フォント)
            prof.RenderProfile.FontName    = (ary[28] != "") ? ary[28] : terminalOptions.Font.Name;
            prof.RenderProfile.CJKFontName = (ary[29] != "") ? ary[29] : terminalOptions.CJKFont.Name;
            if (ary[30] == "")
            {
                prof.RenderProfile.FontSize = terminalOptions.Font.Size;
            }
            else if (float.TryParse(ary[30], out tmpfloat) == true)
            {
                prof.RenderProfile.FontSize = tmpfloat;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidFontSize"), MessageBoxIcon.Error);
                return(null);
            }
            if (ary[31] == "")
            {
                prof.RenderProfile.UseClearType = terminalOptions.UseClearType;
            }
            else if (ary[31].ToLower() == "true")
            {
                prof.RenderProfile.UseClearType = true;
            }
            else if (ary[31].ToLower() == "false")
            {
                prof.RenderProfile.UseClearType = false;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidClearType"), MessageBoxIcon.Error);
                return(null);
            }
            if (ary[32] == "")
            {
                prof.RenderProfile.EnableBoldStyle = terminalOptions.EnableBoldStyle;
            }
            else if (ary[32].ToLower() == "true")
            {
                prof.RenderProfile.EnableBoldStyle = true;
            }
            else if (ary[32].ToLower() == "false")
            {
                prof.RenderProfile.EnableBoldStyle = false;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidBoldStyle"), MessageBoxIcon.Error);
                return(null);
            }
            if (ary[33] == "")
            {
                prof.RenderProfile.ForceBoldStyle = terminalOptions.ForceBoldStyle;
            }
            else if (ary[33].ToLower() == "true")
            {
                prof.RenderProfile.ForceBoldStyle = true;
            }
            else if (ary[33].ToLower() == "false")
            {
                prof.RenderProfile.ForceBoldStyle = false;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidForceBoldStyle"), MessageBoxIcon.Error);
                return(null);
            }

            // 表示オプション(背景画像, ファイルチェックあり)
            if (ary[34] == "")
            {
                prof.RenderProfile.BackgroundImageFileName = terminalOptions.BackgroundImageFileName;
            }
            else
            {
                prof.RenderProfile.BackgroundImageFileName = ary[34];
            }
            if (prof.RenderProfile.BackgroundImageFileName != "")
            {
                try {
                    Image.FromFile(prof.RenderProfile.BackgroundImageFileName);
                } catch (Exception) {
                    ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidBackgroundImageFileName"), MessageBoxIcon.Error);
                    return(null);
                }
            }
            if (ary[35] == "")
            {
                prof.RenderProfile.ImageStyle = terminalOptions.ImageStyle;
            }
            else if (ary[35].ToLower() == "center")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.Center;
            }
            else if (ary[35].ToLower() == "topleft")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.TopLeft;
            }
            else if (ary[35].ToLower() == "topright")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.TopRight;
            }
            else if (ary[35].ToLower() == "bottomleft")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.BottomLeft;
            }
            else if (ary[35].ToLower() == "bottomright")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.BottomRight;
            }
            else if (ary[35].ToLower() == "scaled")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.Scaled;
            }
            else if (ary[35].ToLower() == "horizontalfit")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.HorizontalFit;
            }
            else if (ary[35].ToLower() == "verticalfit")
            {
                prof.RenderProfile.ImageStyle = ImageStyle.VerticalFit;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidImageStyle"), MessageBoxIcon.Error);
                return(null);
            }

            // コマンド発行間隔
            if (ary[36] == "")
            {
                prof.CommandSendInterval = ConnectProfileStruct.DEFAULT_CMD_SEND_INTERVAL;
            }
            else if (int.TryParse(ary[36], out tmp) == true)
            {
                prof.CommandSendInterval = tmp;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidCommandSendInterval"), MessageBoxIcon.Error);
                return(null);
            }

            // プロンプト受信タイムアウト
            if (ary[37] == "")
            {
                prof.PromptRecvTimeout = ConnectProfileStruct.DEFAULT_PROMPT_RECV_TIMEOUT;
            }
            else if (int.TryParse(ary[37], out tmp) == true)
            {
                prof.PromptRecvTimeout = tmp;
            }
            else
            {
                ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidPromptRecvTimeout"), MessageBoxIcon.Error);
                return(null);
            }

            // 項目色
            prof.ProfileItemColor = Poderosa.ParseUtil.ParseColor(ary[38].ToLower(), Color.Black);

            // 説明
            prof.Description = ary[39];

            return(prof);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// CSVインポートクリックイベント
        /// </summary>
        private void _csvImportButton_Click(object sender, System.EventArgs e)
        {
            ConnectProfileList   profList = new ConnectProfileList();
            ConnectProfileStruct prof     = new ConnectProfileStruct();
            StreamReader         sr       = null;
            bool appendFlg = false;
            int  lineCnt   = 1;

            if (_openCSVFileDialog.ShowDialog() == DialogResult.OK)
            {
                // インポート実行確認
                if (ConnectProfilePlugin.AskUserYesNoInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportConfirm"), MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    // 追加/削除確認
                    if (ConnectProfilePlugin.AskUserYesNoInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportAppendProfileList"), MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        appendFlg = true;
                    }

                    // インポート実行
                    try {
                        sr = new System.IO.StreamReader(_openCSVFileDialog.FileName, System.Text.Encoding.UTF8);
                        while (!sr.EndOfStream)
                        {
                            string line = sr.ReadLine();

                            // 各種チェック
                            if (lineCnt == 1)
                            {
                                // ヘッダーチェック(1行目固定)
                                if (_cmd.CheckCSVHeader(line) != true)
                                {
                                    ConnectProfilePlugin.MessageBoxInvoke(string.Format(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidHeader"), lineCnt.ToString()), MessageBoxIcon.Error);
                                    return;
                                }
                            }
                            else if ((line == "") || (line.IndexOf("#") == 0))
                            {
                                // 空白行/行頭シャープの行はスキップ
                                lineCnt++;
                                continue;
                            }
                            else
                            {
                                // フィールド数チェック
                                if (_cmd.CheckCSVFieldCount(line) != true)
                                {
                                    ConnectProfilePlugin.MessageBoxInvoke(string.Format(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportInvalidFieldCount"), lineCnt.ToString()), MessageBoxIcon.Error);
                                    return;
                                }

                                // 各項目チェック
                                prof = _cmd.CheckCSVData(line);
                                if (prof == null)
                                {
                                    ConnectProfilePlugin.MessageBoxInvoke(string.Format(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportFailed"), lineCnt.ToString()), MessageBoxIcon.Error);
                                    return;
                                }

                                // プロファイル追加
                                if (appendFlg == true)
                                {
                                    _cmd.AddProfileCommand(ConnectProfilePlugin.Profiles, prof);
                                }
                                else
                                {
                                    _cmd.AddProfileCommand(profList, prof);
                                }
                            }
                            lineCnt++;
                        }
                        // プロファイルリスト全置換
                        if (appendFlg == false)
                        {
                            _cmd.ReplaceAllProfileCommand(ConnectProfilePlugin.Profiles, profList);
                        }

                        RefreshAllProfiles();
                        RefreshSelectCount();
                        ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportComplete"), MessageBoxIcon.Information);
                    } catch (Exception ex) {
                        ConnectProfilePlugin.MessageBoxInvoke(ex.Message, MessageBoxIcon.Error);
                    } finally {
                        if (sr != null)
                        {
                            sr.Close();
                        }
                    }
                }
                else
                {
                    // キャンセル
                    ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.CSVImportCancel"), MessageBoxIcon.Warning);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// OKボタンイベント
        /// </summary>
        private void _okButton_Click(object sender, EventArgs e)
        {
            ArrayList hostlist = new ArrayList();

            this.DialogResult = DialogResult.None;
            _connectCancelFlg = false;
            EnableControl(false);

            if ((_selectCnt == 0) && (_profileListView.Items.Count == 1))
            {
                // 選択数0 & リスト1行のみ
                _profileListView.Items[0].Selected = true;
                Connect(GetSelectedProfile());
                this.DialogResult = DialogResult.OK;
            }
            else if ((_selectCnt == 0) && (_profileListView.SelectedItems.Count == 1))
            {
                // 選択数0 & リスト1行選択
                Connect(GetSelectedProfile());
                this.DialogResult = DialogResult.OK;
            }
            else if (_selectCnt > 0)
            {
                // 選択数1以上(複数接続)
                foreach (ConnectProfileStruct prof in ConnectProfilePlugin.Profiles)
                {
                    if (prof.Check == true)
                    {
                        hostlist.Add(prof.HostName);
                    }
                }

                // 接続確認
                if (ConnectProfilePlugin.AskUserYesNoInvoke(String.Format(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.ConnectConfirm"), _selectCnt, String.Join(", ", (string[])hostlist.ToArray(typeof(string)))), MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    // 接続
                    foreach (ConnectProfileStruct prof in ConnectProfilePlugin.Profiles)
                    {
                        if (_connectCancelFlg != true)
                        {
                            if (prof.Check == true)
                            {
                                Connect(prof);
                            }
                        }
                        else
                        {
                            // キャンセルボタン押下
                            ConnectProfilePlugin.MessageBoxInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.ConnectCancel"), MessageBoxIcon.Warning);
                            this.DialogResult = DialogResult.None;
                            EnableControl(true);
                            _okButton.Focus();
                            return;
                        }
                    }
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    // キャンセル
                    EnableControl(true);
                    _okButton.Focus();
                }
            }
            else
            {
                // リスト未選択
                ConnectProfilePlugin.AskUserYesNoInvoke(ConnectProfilePlugin.Strings.GetString("Message.ConnectProfile.ProfileNotSelected"), MessageBoxIcon.Warning);
                EnableControl(true);
                _okButton.Focus();
            }
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public override void InitializePlugin(IPoderosaWorld poderosa)
        {
            base.InitializePlugin(poderosa);
            _instance = this;

            // 文字列リソース読み込み
            _stringResource = new Poderosa.StringResource("Contrib.ConnectProfile.strings", typeof(ConnectProfilePlugin).Assembly);
            ConnectProfilePlugin.Instance.PoderosaWorld.Culture.AddChangeListener(_stringResource);

            // コマンド登録
            IPluginManager pm = poderosa.PluginManager;
            _coreServices = (ICoreServices)poderosa.GetAdapter(typeof(ICoreServices));
            _terminalEmulatorPlugin = (ITerminalEmulatorService)pm.FindPlugin("org.poderosa.terminalemulator", typeof(ITerminalEmulatorService));
            ConnectProfileCommand.Register(_coreServices.CommandManager);

            // メニューリスト作成
            ConnectProfileMenuGroup menulist = new ConnectProfileMenuGroup();
            ConnectProfileContextMenuGroup contextmenulist = new ConnectProfileContextMenuGroup();

            // メニュー登録
            IExtensionPoint toolmenu = pm.FindExtensionPoint("org.poderosa.menu.tool");
            toolmenu.RegisterExtension(menulist);

            // コンテキストメニュー登録
            IExtensionPoint contextmenu = pm.FindExtensionPoint("org.poderosa.terminalemulator.contextMenu");
            contextmenu.RegisterExtension(contextmenulist);

            // 設定ファイル連携
            _connectProfileOptionSupplier = new ConnectProfileOptionsSupplier();
            _coreServices.PreferenceExtensionPoint.RegisterExtension(_connectProfileOptionSupplier);

            // 接続プロファイル
            _profiles = new ConnectProfileList();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// OKボタンクリックイベント
        /// </summary>
        private void _okButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.None;

            // 入力チェック
            try {
                // 初期化
                _result.HostName            = _hostNameBox.Text;
                _result.Protocol            = ((ListItem <ConnectionMethod>)_protocolBox.SelectedItem).Value;
                _result.Port                = (int)_portBox.Value;
                _result.AuthType            = ((EnumListItem <AuthType>)_authTypeBox.SelectedItem).Value;
                _result.KeyFile             = "";
                _result.UserName            = "";
                _result.Password            = _passwordBox.Text;
                _result.AutoLogin           = _autoLoginCheck.Checked;
                _result.LoginPrompt         = "";
                _result.PasswordPrompt      = "";
                _result.ExecCommand         = "";
                _result.SUUserName          = "";
                _result.SUPassword          = "";
                _result.SUType              = "";
                _result.CharCode            = ((EnumListItem <EncodingType>)_charCodeBox.SelectedItem).Value;
                _result.NewLine             = ((EnumListItem <NewLine>)_newLineTypeBox.SelectedItem).Value;
                _result.TelnetNewLine       = _telnetNewLineCheck.Checked;
                _result.TerminalType        = ((EnumListItem <TerminalType>)_terminalTypeBox.SelectedItem).Value;
                _result.CommandSendInterval = (int)_commandSendIntBox.Value;
                _result.PromptRecvTimeout   = (int)_promptRecvTimeoutBox.Value;
                _result.ProfileItemColor    = _profileItemColorButton.SelectedColor;
                _result.Description         = _descriptionBox.Text;
                _result.RenderProfile       = _renderProfile;

                // ホスト名
                if (_hostNameBox.Text == "")
                {
                    throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyHostName"));
                }

                // 秘密鍵ファイル
                if (_keyFileBox.Enabled == true)
                {
                    if (_keyFileBox.Text != "")
                    {
                        if (File.Exists(_keyFileBox.Text))
                        {
                            _result.KeyFile = _keyFileBox.Text;
                        }
                        else
                        {
                            throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.KeyFileNotExist"));
                        }
                    }
                    else
                    {
                        throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyKeyFile"));
                    }
                }

                // ユーザ名
                if (_userNameBox.Enabled == true)
                {
                    if (_userNameBox.Text != "")
                    {
                        _result.UserName = _userNameBox.Text;
                    }
                    else
                    {
                        throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyUserName"));
                    }
                }

                // ログインプロンプト
                if (_loginPromptBox.Enabled == true)
                {
                    if (_loginPromptBox.Text != "")
                    {
                        _result.LoginPrompt = _loginPromptBox.Text;
                    }
                    else
                    {
                        throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.EmptyLoginPrompt"));
                    }
                }

                // パスワードプロンプト
                if (_passwordPromptBox.Enabled == true)
                {
                    _result.PasswordPrompt = _passwordPromptBox.Text;
                }

                // 実行コマンド
                if ((_execCommandBox.Enabled == true) && _execCommandBox.Text != "")
                {
                    _result.ExecCommand = _execCommandBox.Text;
                }

                // SU
                if ((_suUserNameBox.Enabled == true) && _suUserNameBox.Text != "")
                {
                    _result.SUUserName = _suUserNameBox.Text;
                    _result.SUPassword = _suPasswordBox.Text;
                    if (_suTypeRadio1.Checked == true)
                    {
                        _result.SUType = _suTypeRadio1.Text;
                    }
                    else if (_suTypeRadio2.Checked == true)
                    {
                        _result.SUType = _suTypeRadio2.Text;
                    }
                    else if (_suTypeRadio3.Checked == true)
                    {
                        _result.SUType = _suTypeRadio3.Text;
                    }
                    else if (_suTypeRadio4.Checked == true)
                    {
                        _result.SUType = _suTypeRadio4.Text;
                    }
                    else
                    {
                        throw new Exception(ConnectProfilePlugin.Strings.GetString("Message.AddProfile.SUTypeNotSelect"));
                    }
                }

                this.DialogResult = DialogResult.OK;
            } catch (Exception ex) {
                ConnectProfilePlugin.MessageBoxInvoke(ex.Message, MessageBoxIcon.Warning);
            }
        }