예제 #1
0
        /// <summary>
        /// 接続に失敗したら例外を投げる。
        /// -- 今のところ例外を投げるケース無し。問題があれば、接続後すぐに切断する。@ 2017.5.2
        /// </summary>
        /// <param name="si"></param>
        /// <param name="monitorIndex"></param>
        public Connection(Ground.ServerInfo si, int monitorIndex)
        {
            this.si           = si;
            this.monitorIndex = monitorIndex;

            connect();
        }
예제 #2
0
        private void setServerInfo(Ground.ServerInfo si)
        {
            this.txtTitle.Text  = si.title;
            this.txtHost.Text   = si.host;
            this.txtPortNo.Text = "" + si.portNo;
            this.cmbCipherMode.SelectedIndex = (int)si.cipherMode;
            _keyData = si.key;
            this.txtPassphrase.Text = si.passphrase;

            refreshUI();
        }
예제 #3
0
        private void 読み込むLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int rowidx = getFirstSelectedRowIndex();

            if (rowidx == -1)
            {
                return;
            }

            Ground.ServerInfo si = siSheetGetRow(rowidx);
            setServerInfo(si);
        }
예제 #4
0
        private void  前を変更するRToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int rowidx = getFirstSelectedRowIndex();

            if (rowidx == -1)
            {
                return;
            }

            Ground.ServerInfo si       = siSheetGetRow(rowidx);
            string            valTitle = si.title;

            for (; ;)
            {
                if (InputStringDlg.perform(
                        "新しい名前を入力して下さい。",
                        ref valTitle,
                        1000
                        ) == false
                    )
                {
                    break;
                }

                try
                {
                    if (valTitle == "")
                    {
                        throw new FailedOperation("名前が入力されていません。");
                    }

                    for (int rr = 0; rr < siSheet.RowCount; rr++)
                    {
                        if (rr != rowidx && valTitle == siSheetGetRow(rr).title)
                        {
                            throw new FailedOperation("名前が重複しています。");
                        }
                    }

                    // 変更を反映
                    si.title = valTitle;
                    siSheetSetRow(rowidx, si);
                    Utils.adjustColumnsWidth(siSheet);

                    break;
                }
                catch (Exception ex)
                {
                    FailedOperation.caught(ex);
                }
            }
        }
예제 #5
0
 private void btnTestFieldsSerializer_Click(object sender, EventArgs e)
 {
     try
     {
         Ground.ServerInfo si    = new Ground.ServerInfo();
         string[]          lines = FieldsSerializer.serialize(si);
         FieldsSerializer.deserialize(si, lines);
     }
     catch (Exception ex)
     {
         FailedOperation.caught(ex);
     }
 }
예제 #6
0
        private void selectMonitor(int monitorIndex)
        {
            this.mtEnabled = false;

            if (Ground.i.con != null)
            {
                Ground.ServerInfo si = Ground.i.con.si;

                disconnect();                 // 同じところに繋ぐので、new Connection() する前に disconnect() する必要がある!
                connected(new Connection(si, monitorIndex));
            }
            this.mtEnabled = true;
        }
예제 #7
0
        private void siSheetSetRow(int rowidx, Ground.ServerInfo si)
        {
            DataGridViewRow row    = siSheet.Rows[rowidx];
            int             colidx = 0;

            row.Cells[colidx++].Value = si.title;
            row.Cells[colidx++].Value = si.host;
            row.Cells[colidx++].Value = "" + si.portNo;
            row.Cells[colidx++].Value = Consts.cipherModes[(int)si.cipherMode];
            row.Cells[colidx++].Value = si.keyIdent;
            row.Cells[colidx++].Value = si.passphrase;
            row.Cells[colidx++].Value = StringTools.encodeLines(FieldsSerializer.serialize(si));
        }
예제 #8
0
        private void 再接続RToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.mtEnabled = false;

            if (Ground.i.con != null)
            {
                Ground.ServerInfo si = Ground.i.con.si;
                int monitorIndex     = Ground.i.con.monitorIndex;

                disconnect();                 // 同じところに繋ぐので、new Connection() する前に disconnect() する必要がある!
                connected(new Connection(si, monitorIndex));
            }
            this.mtEnabled = true;
        }
예제 #9
0
 private void connect(int rowidx)
 {
     try
     {
         Ground.ServerInfo si  = siSheetGetRow(rowidx);
         Connection        con = new Connection(si, 0);
         retCon = con;
         this.Close();
     }
     catch (Exception ex)
     {
         FailedOperation.caught(ex);
     }
 }
예제 #10
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     try
     {
         Ground.ServerInfo si = getServerInfo(true);
         Ground.i.lastConServerInfo = si;
         Connection con = new Connection(si, 0);
         retCon = con;
         this.Close();
     }
     catch (Exception ex)
     {
         FailedOperation.caught(ex);
     }
 }
예제 #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Ground.ServerInfo si = getServerInfo();
                int rowidx           = getRowIndexByTitle(si.title);

                if (rowidx == -1)
                {
                    if (Ground.i.serverInfoCountMax <= siSheet.RowCount)
                    {
                        MessageBox.Show(
                            "項目数の上限に達したため、これ以上追加できません。",
                            "保存できません",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning
                            );
                        return;
                    }
                    siSheet.RowCount++;
                    siSheetSetRow(siSheet.RowCount - 1, si);
                }
                else
                {
                    if (MessageBox.Show(
                            "設定「" + si.title + "」を上書きします。\n宜しいですか?",
                            "確認",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Warning
                            ) != DialogResult.Yes
                        )
                    {
                        return;
                    }

                    siSheetSetRow(rowidx, si);
                }
                doSortSISheet();
                Utils.adjustColumnsWidth(siSheet);
            }
            catch (Exception ex)
            {
                FailedOperation.caught(ex);
            }
        }
예제 #12
0
        private void 削除DToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int rowidx = getFirstSelectedRowIndex();

            if (rowidx == -1)
            {
                return;
            }

            Ground.ServerInfo si = siSheetGetRow(rowidx);

            if (MessageBox.Show(
                    "設定「" + si.title + "」を削除します。\n宜しいですか?",
                    "確認",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Information
                    ) != DialogResult.Yes
                )
            {
                return;
            }

            siSheet.Rows.RemoveAt(rowidx);
        }
예제 #13
0
        /// <summary>
        /// 画面の入力値から ServerInfo を生成する。
        /// 入力に問題があれば、例外を投げる。
        /// </summary>
        /// <returns></returns>
        private Ground.ServerInfo getServerInfo(bool anonimousMode = false)
        {
            if (!anonimousMode)
            {
                if (this.txtTitle.Text == "")
                {
                    throw new FailedOperation("名前が指定されていません。");
                }

                if (this.txtTitle.Text != this.txtTitle.Text.Trim())
                {
                    throw new FailedOperation(
                              "名前に問題があります。\n" +
                              "・前後に空白は使用できません。"
                              );
                }
            }
            if (this.txtHost.Text == "")
            {
                throw new FailedOperation("ホスト名が指定されていません。");
            }

            if (this.txtHost.Text != JString.toJString(this.txtHost.Text, false, false, false, false))
            {
                throw new FailedOperation(
                          "ホスト名に問題があります。\n" +
                          "・ASCIIに変換できない文字は使用できません。\n" +
                          "・空白は使用できません。"
                          );
            }

            if (this.txtPortNo.Text == "")
            {
                throw new FailedOperation("ポート番号が指定されていません。");
            }

            try
            {
                if (IntTools.isRange(int.Parse(this.txtPortNo.Text), 1, 65535) == false)
                {
                    throw null;
                }
            }
            catch
            {
                throw new FailedOperation(
                          "ポート番号に問題があります。\n" +
                          "・指定できる値は 1 以上 65535 以下の整数です。"
                          );
            }

            switch (this.cmbCipherMode.SelectedIndex)
            {
            case (int)Consts.CipherMode_e.NOT_ENCRYPT:
                break;

            case (int)Consts.CipherMode_e.ENCRYPT_BY_KEY:
            {
                if (_keyData == null)
                {
                    throw new FailedOperation("鍵が指定されていません。");
                }
            }
            break;

            case (int)Consts.CipherMode_e.ENCRYPT_BY_PASSPHRASE:
            {
                if (this.txtPassphrase.Text == "")
                {
                    throw new FailedOperation("パスフレーズが指定されていません。");
                }

                if (this.txtPassphrase.Text != JString.toJString(this.txtPassphrase.Text, true, false, false, false))
                {
                    throw new FailedOperation(
                              "パスフレーズに問題があります。\n" +
                              "・Shift_JISに変換できない文字は使用できません。\n" +
                              "・空白は使用できません。"
                              );
                }
            }
            break;

            default:
                throw null;
            }

            try
            {
                if (IntTools.isRange(int.Parse(this.txtRelayPortNo.Text), 1, 65535) == false)
                {
                    throw null;
                }
            }
            catch
            {
                throw new FailedOperation(
                          "中継用ポート番号に問題があります。\n" +
                          "・指定できる値は 1 以上 65535 以下の整数です。"
                          );
            }

            // <-- check

            Ground.ServerInfo si = new Ground.ServerInfo();

            si.title      = this.txtTitle.Text;
            si.host       = this.txtHost.Text;
            si.portNo     = int.Parse(this.txtPortNo.Text);
            si.key        = null;
            si.passphrase = "";

            switch (this.cmbCipherMode.SelectedIndex)
            {
            case (int)Consts.CipherMode_e.ENCRYPT_BY_KEY:
                si.key = _keyData;
                break;

            case (int)Consts.CipherMode_e.ENCRYPT_BY_PASSPHRASE:
                si.passphrase = this.txtPassphrase.Text;
                break;

            default:
                break;
            }

            Ground.i.relayPortNo = int.Parse(this.txtRelayPortNo.Text);             // ここでいいのか?

            return(si);
        }
예제 #14
0
 private Ground.ServerInfo siSheetGetRow(int rowidx)
 {
     Ground.ServerInfo si = new Ground.ServerInfo();
     FieldsSerializer.deserialize(si, StringTools.decodeLines(siSheet.Rows[rowidx].Cells[siSheet.ColumnCount - 1].Value.ToString()));
     return(si);
 }