/// <summary> /// DB Management로부터(udp) 수신받는 리시브 이벤트 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void udpSoc_recvEvtHandler(object sender, AdengRecvEvtArgs e) { if (e.Len > 0) { try { PrtBase protoBase = PrtMng.ParseFrame(e.Buff); switch (protoBase.Cmd) { case 30: PrtCmd30 p30 = protoBase as PrtCmd30; if (p30.CompleteState == 1) //CC변경 완료 { this.SetLogListBox("Data receive from CC DB Management - Basic data changed!"); this.clientSoc.Send(e.Buff); this.SetLogListBox("Data send to CC Opration Management - Basic data changed!"); } break; default: break; } } catch (Exception ex) { this.SetLogListBox("UDP data receiver error - " + ex.Message); } } }
/// <summary> /// 큐 처리 /// </summary> private void proc_runAsyncProcess() { while (this.proc.ContinueThread) { this.proc.ManuEvent.Reset(); this.proc.ManuEvent.WaitOne(500); int remainCnt = 0; lock (this.insertQ) { remainCnt = this.insertQ.Count; } if (remainCnt > 0) { if (TryConnect() == false) { continue; } } while (true) { PrtBase tmp = null; try { lock (this.insertQ) { if (this.insertQ.Count > 0) { tmp = this.insertQ.Dequeue(); } } if (tmp == null) { break; } this.SyncDataInsert(tmp); } catch (Exception ex) { Debug.WriteLine("proc_runAsyncProcess - " + ex.Message); break; } } this.dataMng.OracleClose(); } }
/// <summary> /// 서버 소켓에서 전송한 데이터 이벤트 /// </summary> /// <param name="buff"></param> private void clientSoc_evReceived(byte[] buff) { try { PrtBase pBase = PrtMng.ParseFrame(buff); if (pBase.Cmd == 9) { return; } if (pBase.Cmd == 3) { PrtCmd03 p3 = pBase as PrtCmd03; if ((p3.Kind == (byte)PrtCmd03.emKind.SET_TIME) && (p3.Addr == 0xffffffff)) { this.setLocalTime(p3.SetTimeDT); return; } } if (pBase != null) { lock (this.insertQ) { this.insertQ.Enqueue(pBase); } this.proc.ManuEvent.Set(); } } catch (Exception ex) { Debug.WriteLine("clientSoc_evReceived - " + ex.Message); } }
/// <summary> /// Data Insert 처리 /// </summary> /// <param name="_base"></param> private void SyncDataInsert(PrtBase _base) { PrtBase tmp = _base; try { switch (tmp.Cmd) { case 0: PrtCmd00 p0 = tmp as PrtCmd00; this.dataMng.SetDB_TC0(p0); this.procCount++; break; case 1: PrtCmd01 p1 = tmp as PrtCmd01; this.dataMng.SetDB_TC1(p1); this.procCount++; break; /* * case 2: * PrtCmd02 p2 = tmp as PrtCmd02; * this.dataMng.SetDB_TC2(p2); * this.procCount++; * break; */ case 3: PrtCmd03 p3 = tmp as PrtCmd03; this.dataMng.SetDB_TC3(p3); this.procCount++; break; /* * case 4: * PrtCmd04 p4 = tmp as PrtCmd04; * this.dataMng.SetDB_TC4(p4); * this.procCount++; * break; */ case 5: PrtCmd05 p5 = tmp as PrtCmd05; this.dataMng.SetDB_TC5(p5); this.procCount++; break; case 6: PrtCmd06 p6 = tmp as PrtCmd06; this.dataMng.SetDB_TC6(p6); this.procCount++; break; case 7: PrtCmd07 p7 = tmp as PrtCmd07; this.dataMng.SetDB_TC7(p7); this.procCount++; break; case 8: PrtCmd08 p8 = tmp as PrtCmd08; this.dataMng.SetDB_TC8(p8); this.procCount++; break; /* * case 9: * PrtCmd09 p9 = tmp as PrtCmd09; * this.dataMng.SetDB_TC9(p9); * this.procCount++; * break; * * case 10: * PrtCmd10 p10 = tmp as PrtCmd10; * this.dataMng.SetDB_TC10(p10); * this.procCount++; * break; * * case 11: * PrtCmd11 p11 = tmp as PrtCmd11; * this.dataMng.SetDB_TC11(p11); * this.procCount++; * break; */ case 12: PrtCmd12 p12 = tmp as PrtCmd12; this.dataMng.SetDB_TC12(p12); this.procCount++; break; /* * case 13: * PrtCmd13 p13 = tmp as PrtCmd13; * this.dataMng.SetDB_TC13(p13); * this.procCount++; * break; * * case 14: * PrtCmd14 p14 = tmp as PrtCmd14; * this.dataMng.SetDB_TC14(p14); * this.procCount++; * break; */ case 15: PrtCmd15 p15 = tmp as PrtCmd15; this.dataMng.SetDB_TC15(p15); this.procCount++; break; /* * case 16: * PrtCmd16 p16 = tmp as PrtCmd16; * this.dataMng.SetDB_TC16(p16); * this.procCount++; * break; * * case 17: * PrtCmd17 p17 = tmp as PrtCmd17; * this.dataMng.SetDB_TC17(p17); * this.procCount++; * break; */ case 21: PrtCmd21 p21 = tmp as PrtCmd21; this.dataMng.SetDB_TC21(p21); this.procCount++; break; default: break; } } catch (Exception ex) { Debug.WriteLine("SyncDataInsert - " + ex.Message); //this.SetLogListBox((object)ex.Message); } }
/// <summary> /// 초기화 /// </summary> private void init() { //디렉토리가 있는지 체크.. if (!Directory.Exists(this.IniFileDirectoryPath)) { Directory.CreateDirectory(IniFileDirectoryPath); } //파일이 있는지 체크..없으면 파일 생성 if (!File.Exists(IniFilePath)) { AdengUtil.INIWriteValueString(this.setting, this.DBIP, "58.181.17.58", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.DBSID, "orcl", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.DBID, "mews33", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.DBPW, "mews", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.Oracle8i, "F", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.TCPIP, "127.0.0.1", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.TCPPort, "9009", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.LogFlag, "F", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.UDPIP, "127.0.0.1", IniFilePath); AdengUtil.INIWriteValueString(this.setting, this.UDPPort, "7001", IniFilePath); } //tcp client socket 생성 this.clientSoc = TCPModClient.getTCPModClient(); this.clientSoc.evConnected += new TCPModClient.ConnectedHandler(clientSoc_evConnected); this.clientSoc.evConnectFailed += new TCPModClient.ConnectedFailedHandler(clientSoc_evConnectFailed); this.clientSoc.evDisconnected += new TCPModClient.DisconnectedHandler(clientSoc_evDisconnected); this.clientSoc.evReceived += new TCPModClient.ReceivedHandler(clientSoc_evReceived); this.clientSoc.evSendFailed += new TCPModClient.SendFailedHandler(clientSoc_evSendFailed); this.clientSoc.evTimeout += new TCPModClient.TimeOutHandler(clientSoc_evTimeout); //udp socket 생성 try { this.udpSoc = new AdengUdpSocket(AdengUtil.INIReadValueString(this.setting, this.UDPIP, this.IniFilePath), int.Parse(AdengUtil.INIReadValueString(this.setting, this.UDPPort, this.IniFilePath))); this.udpSoc.recvEvtHandler += new RecvEvtHandler(udpSoc_recvEvtHandler); this.SetLogListBox("UDP Success!"); } catch (Exception ex) { this.SetLogListBox("UDP Fail!"); } //data Manager 생성 this.dataMng = DBMngDataMng.getInstance(); this.dataMng.OnTermStateTCPSendEvt += new EventHandler <TermStateTCPSendEvtArgs>(dataMng_OnTermStateTCPSendEvt); //queue 생성 this.insertQ = new Queue <PrtBase>(); try { //로그 셋팅 값을 가져온다. this.logState = (AdengUtil.INIReadValueString(this.setting, this.LogFlag, IniFilePath) == "T" ? true : false); //TCP 연결 this.localTcpIp = AdengUtil.INIReadValueString(this.setting, this.TCPIP, this.IniFilePath); this.localTcpPort = int.Parse(AdengUtil.INIReadValueString(this.setting, this.TCPPort, this.IniFilePath)); this.clientSoc.ConnectTo(this.localTcpIp, this.localTcpPort); } catch (Exception ex) { Debug.WriteLine("MewsMain.init - " + ex.Message); } //폴링 데이터 처리 PrtBase p9 = PrtMng.GetPrtObject(9); p9.MakeData(); byte[] buff = PrtMng.MakeFrame(p9); this.clientSoc.BtPoll = buff; //기초데이터 로드 (단말) if (this.TryConnect()) { if (this.dataMng.InitDataLoad()) { this.SetLogListBox("Init Data Load Success!"); } else { this.SetLogListBox("Init Data Load Fail (DB Read Fail!)"); } } else { this.SetLogListBox("Init Data Load Fail (DB Connect Fail!)"); } //처리한 큐 카운트를 라벨에 셋팅한다. this.procCountTD = new Thread(new ThreadStart(this.SetDataProcCnt)); this.procCountTD.IsBackground = true; this.procCountTD.Start(); //큐처리 this.proc.runAsyncProcess += new InvokeValue(proc_runAsyncProcess); this.proc.Start(); //프로그램 제목 최신 버전 표시 this.Text += version1; //시작 로그 if (this.logState) { MTextLog.WriteTextLog(true, this.Text + " START"); } }
public void tempM() { PrtBase pb = new PrtBase(); PrtCmd00 p01 = new PrtCmd00(); }