//�㏈�� 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��~ }
//後処理 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, "");//リモートクライアント停止 }