//クライアント側への送信 public void AddTrace(TraceKind traceKind, string str, Ip ip) { if (!OpenTraceDlg) { return; } var threadId = GetCurrentThreadId(); var buffer = string.Format("{0}\b{1}\b{2}\b{3}", traceKind.ToString(), threadId.ToString(), ip, str); //トレース(S->C) RemoteData.Send(_sockTcp, RemoteDataKind.DatTrace, buffer); }
//RunMode��Remote�̏ꍇ�AKernel��MenuOnClick����A�����炪�Ă�� public void MenuOnClick(String cmd) { //�I�v�V�������j���[�̏ꍇ if (cmd.IndexOf("Option_") == 0) { var oneOption = _kernel.ListOption.Get(cmd.Substring(7)); if (oneOption != null) { var dlg = new OptionDlg(_kernel, oneOption); if (DialogResult.OK == dlg.ShowDialog()) { oneOption.Save(_kernel.IniDb);//�I�v�V������ۑ����� //�T�[�o���֑��M���� string optionStr; using (var sr = new StreamReader(_optionFileName, Encoding.GetEncoding("Shift_JIS"))) { optionStr = sr.ReadToEnd(); sr.Close(); } //Option�̑��M(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdOption, optionStr); } } //�u�c�[���v���j���[�̏ꍇ } else if (cmd.IndexOf("Tool_") == 0) { var oneTool = _kernel.ListTool.Get(cmd.Substring(5)); if (oneTool != null) { _toolDlg = oneTool.CreateDlg(_sockTcp); _toolDlg.ShowDialog(); _toolDlg.Dispose(); _toolDlg = null; } //�u�N���^��~�v�̏ꍇ } else if (cmd.IndexOf("StartStop_") == 0) { string nameTag = cmd.Substring(10); if (nameTag == "Restart") { if (_sockTcp != null) { //�u�ċN���v���j���[�I��(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdRestart, ""); } } } }
//RunModeがRemoteの場合、KernelのMenuOnClickから、こちらが呼ばれる public void MenuOnClick(String cmd) { //オプションメニューの場合 if (cmd.IndexOf("Option_") == 0) { var oneOption = _kernel.ListOption.Get(cmd.Substring(7)); if (oneOption != null) { var dlg = new OptionDlg(_kernel, oneOption); if (DialogResult.OK == dlg.ShowDialog()) { oneOption.Save(_kernel.IniDb);//オプションを保存する //サーバ側へ送信する string optionStr; using (var sr = new StreamReader(_optionFileName, Encoding.GetEncoding("Shift_JIS"))) { optionStr = sr.ReadToEnd(); sr.Close(); } //Optionの送信(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdOption, optionStr); } } //「ツール」メニューの場合 } else if (cmd.IndexOf("Tool_") == 0) { var oneTool = _kernel.ListTool.Get(cmd.Substring(5)); if (oneTool != null) { _toolDlg = oneTool.CreateDlg(_sockTcp); _toolDlg.ShowDialog(); _toolDlg.Dispose(); _toolDlg = null; } //「起動/停止」の場合 } else if (cmd.IndexOf("StartStop_") == 0) { string nameTag = cmd.Substring(10); if (nameTag == "Restart") { if (_sockTcp != null) { //「再起動」メニュー選択(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdRestart, ""); } } } }
//�㏈�� override protected void OnRunThread() //�{�� { _kernel.View.SetColor(); //�y�E�C���h�F�z //[C#] ThreadBaseKind = ThreadBaseKind.Running; if (_ip == new Ip(IpKind.V4_0)) { return; //���������s } while (IsLife()) { //TraceDlg traceDlg = null; Ssl ssl = null; var timeout = 3; _sockTcp = Inet.Connect(_kernel, _ip, _port, timeout, ssl); if (_sockTcp == null) { //isRun = false; _logger.Set(LogKind.Error, _sockTcp, 4, string.Format("address={0} port={1}", _ip, _port)); //�Đڑ�����݂�̂́A2�b�� for (int i = 0; i < 20 && IsLife(); i++) { Thread.Sleep(100); } } else { _logger.Set(LogKind.Normal, _sockTcp, 5, string.Format("address={0} port={1}", _ip, _port)); while (IsLife()) //�ڑ��� { if (_sockTcp.SockState != SockState.Connect) { //�ڑ����ꂽ�ꍇ�́A�����^�C�~���O��u���Ă���A�Đڑ������ɖ߂� //�Đڑ�����݂�̂́A1�b�� _sockTcp.Close(); for (int i = 0; i < 10 && IsLife(); i++) { Thread.Sleep(100); } break; } var o = RemoteData.Recv(_sockTcp, this); if (o == null) { Thread.Sleep(100); continue; } switch (o.Kind) { case RemoteDataKind.DatAuth: //�F�؏��i�p�X���[�h�v���j var dlg = new PasswordDlg(_kernel); if (DialogResult.OK == dlg.ShowDialog()) { //�n�b�V��������̍쐬�iMD5�j string md5Str = Inet.Md5Str(dlg.PasswordStr + o.Str); //DAT_AUTH�ɑ���p�X���[�h(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdAuth, md5Str); } else { StopLife(); //Ver5.8.4 �b�菈�u } break; case RemoteDataKind.DatVer: //�o�[�W������� if (!_kernel.Ver.VerData(o.Str)) { //�T�[�o�ƃN���C�A���g�Ńo�[�W�����ɈႢ���L��ꍇ�A�N���C�A���g�@�\���~���� StopLife(); //Ver5.8.4 �b�菈�u } else { IsConected = true; //�ڑ��� _kernel.View.SetColor(); //�y�E�C���h�F�z //���O�C������ _logger.Set(LogKind.Normal, _sockTcp, 10, ""); } break; case RemoteDataKind.DatLocaladdress: //���[�J���A�h���X LocalAddress.SetInstance(o.Str); //_kernel.LocalAddress = new LocalAddress(o.Str); break; case RemoteDataKind.DatTool: //�f�[�^��M if (_toolDlg != null) { var tmp = o.Str.Split(new[] { '\t' }, 2); _toolDlg.CmdRecv(tmp[0], tmp[1]); } break; case RemoteDataKind.DatBrowse: //�f�B���N�g������M if (_browseDlg != null) { _browseDlg.CmdRecv(o.Str); } break; case RemoteDataKind.DatTrace: //�g���[�X��M _kernel.TraceDlg.AddTrace(o.Str); break; case RemoteDataKind.DatLog: //���O��M _kernel.LogView.Append(new OneLog(o.Str)); //���O�r���[�ւ̒lj� break; case RemoteDataKind.DatOption: //�I�v�V�����̎�M //Option.ini���M����$remote.ini�ɏo�͂��� using (var sw = new StreamWriter(_optionFileName, false, Encoding.GetEncoding("Shift_JIS"))) { sw.Write(o.Str); sw.Close(); } _kernel.ListInitialize(); break; default: _logger.Set(LogKind.Error, null, 999, string.Format("kind = {0}", o.Kind)); break; } } //err: _sockTcp.Close(); _sockTcp = null; IsConected = false;//�ڑ��f _kernel.Menu.InitializeRemote(_kernel.IsJp()); _kernel.View.SetColor(); _logger.Set(LogKind.Normal, null, 8, ""); } } _logger.Set(LogKind.Normal, null, 7, "");//�����[�g�N���C�A���g��~ }
public void VisibleTrace2(bool enabled) { //TraceDlg�̕\���E��\��(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdTrace, enabled ? "1" : "0"); }
//後処理 override protected void OnRunThread() //本体 { _kernel.View.SetColor(); //【ウインド色】 //[C#] ThreadBaseKind = ThreadBaseKind.Running; if (_ip == new Ip(IpKind.V4_0)) { return; //初期化失敗 } while (IsLife()) { //TraceDlg traceDlg = null; Ssl ssl = null; var timeout = 3; _sockTcp = Inet.Connect(_kernel, _ip, _port, timeout, ssl); if (_sockTcp == null) { //isRun = false; _logger.Set(LogKind.Error, _sockTcp, 4, string.Format("address={0} port={1}", _ip, _port)); //再接続を試みるのは、2秒後 for (int i = 0; i < 20 && IsLife(); i++) { Thread.Sleep(100); } } else { _logger.Set(LogKind.Normal, _sockTcp, 5, string.Format("address={0} port={1}", _ip, _port)); while (IsLife()) //接続中 { if (_sockTcp.SockState != SockState.Connect) { //接続が切れた場合は、少しタイミングを置いてから、再接続処理に戻る //再接続を試みるのは、1秒後 _sockTcp.Close(); for (int i = 0; i < 10 && IsLife(); i++) { Thread.Sleep(100); } break; } var o = RemoteData.Recv(_sockTcp, this); if (o == null) { Thread.Sleep(100); continue; } switch (o.Kind) { case RemoteDataKind.DatAuth: //認証情報(パスワード要求) var dlg = new PasswordDlg(_kernel); if (DialogResult.OK == dlg.ShowDialog()) { //ハッシュ文字列の作成(MD5) string md5Str = Inet.Md5Str(dlg.PasswordStr + o.Str); //DAT_AUTHに対するパスワード(C->S) RemoteData.Send(_sockTcp, RemoteDataKind.CmdAuth, md5Str); } else { StopLife(); //Ver5.8.4 暫定処置 } break; case RemoteDataKind.DatVer: //バージョン情報 if (!_kernel.Ver.VerData(o.Str)) { //サーバとクライアントでバージョンに違いが有る場合、クライアント機能を停止する StopLife(); //Ver5.8.4 暫定処置 } else { IsConected = true; //接続中 _kernel.View.SetColor(); //【ウインド色】 //ログイン完了 _logger.Set(LogKind.Normal, _sockTcp, 10, ""); } break; case RemoteDataKind.DatLocaladdress: //ローカルアドレス LocalAddress.SetInstance(o.Str); //_kernel.LocalAddress = new LocalAddress(o.Str); break; case RemoteDataKind.DatTool: //データ受信 if (_toolDlg != null) { var tmp = o.Str.Split(new[] { '\t' }, 2); _toolDlg.CmdRecv(tmp[0], tmp[1]); } break; case RemoteDataKind.DatBrowse: //ディレクトリ情報受信 if (_browseDlg != null) { _browseDlg.CmdRecv(o.Str); } break; case RemoteDataKind.DatTrace: //トレース受信 _kernel.TraceDlg.AddTrace(o.Str); break; case RemoteDataKind.DatLog: //ログ受信 _kernel.LogView.Append(new OneLog(o.Str)); //ログビューへの追加 break; case RemoteDataKind.DatOption: //オプションの受信 //Option.iniを受信して$remote.iniに出力する using (var sw = new StreamWriter(_optionFileName, false, Encoding.GetEncoding("Shift_JIS"))) { sw.Write(o.Str); sw.Close(); } _kernel.ListInitialize(); break; default: _logger.Set(LogKind.Error, null, 999, string.Format("kind = {0}", o.Kind)); break; } } //err: _sockTcp.Close(); _sockTcp = null; IsConected = false;//接続断 _kernel.Menu.InitializeRemote(_kernel.IsJp()); _kernel.View.SetColor(); _logger.Set(LogKind.Normal, null, 8, ""); } } _logger.Set(LogKind.Normal, null, 7, "");//リモートクライアント停止 }