/// <summary> /// 게이트웨이와의 접속 해제. /// </summary> /// <returns>해제 결과</returns> public bool DisconnectWithGateway() { System.Console.WriteLine("[CommunicationManager] 게이트웨이에 해제 요청"); bool result = false; try { result = this.sessionManager.Disconnect(); if (this.NotifyIAGWConnectionState != null) { IAGWConnectionEventArgs copy = new IAGWConnectionEventArgs(); lock (this.currentIAGWConnectionState) { this.currentIAGWConnectionState.IsAuthenticated = false; this.currentIAGWConnectionState.IsConnected = false; copy.DeepCopyFrom(this.currentIAGWConnectionState); } this.NotifyIAGWConnectionState(this, copy); } } catch (Exception ex) { System.Console.WriteLine("[CommunicationManager] DisconnectWithGateway (Exception:" + ex.ToString() + ")"); FileLogManager.GetInstance().WriteLog("[CommunicationManager] DisconnectWithGateway( Exception=[" + ex.ToString() + "] )"); } return(result); }
/// <summary> /// 연결 성공 통지 /// </summary> public void sessionManager_OnNotifyConnected(object sender, ConnectEvtArgs e) { try { System.Console.WriteLine("[CommunicationManager] : OnNotifyConnected(" + e.Socket.Connected.ToString() + ")"); if (this.NotifyIAGWConnectionState != null) { IAGWConnectionEventArgs copy = new IAGWConnectionEventArgs(); lock (this.currentIAGWConnectionState) { this.currentIAGWConnectionState.IsConnected = e.Socket.Connected; copy.DeepCopyFrom(this.currentIAGWConnectionState); } this.NotifyIAGWConnectionState(this, copy); } } catch (Exception ex) { System.Console.WriteLine("[CommunicationManager] sessionManager_OnNotifyConnected( " + ex.ToString() + " )"); FileLogManager.GetInstance().WriteLog("[CommunicationManager] sessionManager_OnNotifyConnected( Exception=[" + ex.ToString() + "] )"); } }
/// <summary> /// 폴링 처리 (쓰레드 호출용 함수) /// </summary> public void Polling() { try { System.Console.WriteLine("[CommunicationManager] 폴링 감시 준비"); if (this.manualEvtPolling == null) { this.manualEvtPolling = new ManualResetEvent(false); } // 최초 5초는 폴링 없이 대기 this.manualEvtPolling.WaitOne(5000); this.manualEvtPolling.Reset(); IEASProtocolBase protoBase = IEASProtocolManager.CreateProtocolForKCAP(KCAPCmdValue.Polling); protoBase.SenderType = IEASSenderType.SWI; byte[] pollingData = IEASProtocolManager.MakeFrameForKCAP(protoBase); System.Console.WriteLine("[CommunicationManager] 폴링 감시 시작"); while (this.isPollingContinue) { System.Console.WriteLine("[CommunicationManager] 폴링 체크"); bool pollingState = this.sessionManager.SendData(pollingData); if (this.NotifyIAGWConnectionState != null) { IAGWConnectionEventArgs copy = new IAGWConnectionEventArgs(); lock (this.currentIAGWConnectionState) { this.currentIAGWConnectionState.IsConnected = pollingState; copy.DeepCopyFrom(this.currentIAGWConnectionState); } this.NotifyIAGWConnectionState(this, copy); } this.manualEvtPolling.WaitOne(5000); this.manualEvtPolling.Reset(); } } catch (ThreadAbortException ex) { System.Console.WriteLine("[CommunicationManager] Polling( Exception=[ ThreadAbortException ] )"); FileLogManager.GetInstance().WriteLog("[CommunicationManager] Polling( Exception=[ ThreadAbortException ] )"); Thread.ResetAbort(); } catch (Exception ex) { System.Console.WriteLine("[CommunicationManager] Polling( Exception=[" + ex.ToString() + "] )"); FileLogManager.GetInstance().WriteLog("[CommunicationManager] Polling( Exception=[" + ex.ToString() + "] )"); throw new Exception("[CommunicationManager] 통합경보게이트웨이 연결 감시 처리 중에 예외가 발생하였습니다."); } finally { System.Console.WriteLine("[CommunicationManager] 폴링 감시 종료"); FileLogManager.GetInstance().WriteLog("[CommunicationManager] Polling( 종료 )"); this.isPollingContinue = false; if (this.manualEvtPolling != null) { this.manualEvtPolling.Close(); this.manualEvtPolling = null; } } }
/// <summary> /// 큐에 저장된 패킷 데이터를 프레임 단위로 파싱. /// </summary> private int DistributeKCAPCommandData(KCAPCmdValue command, IEASProtocolBase baseData) { try { System.Console.WriteLine("[CommunicationManager] KCAP 프레임 데이터 분배 - command(" + command + ")"); switch (command) { case KCAPCmdValue.OrderResponse: { IEASPrtCmd2 protoCmd2 = baseData as IEASPrtCmd2; if (this.NotifyCAPReceived != null) { CAP capMsg = new CAP(protoCmd2.CAPMessage); SenderTypes senderType = ConvertToLocalSenderType(protoCmd2.SenderType); ReceivedCAPInfo capInfo = new ReceivedCAPInfo(senderType, capMsg); this.NotifyCAPReceived(this, new CapEventArgs(capInfo)); } } break; case KCAPCmdValue.AuthResult: { IEASPrtCmd4 protoCmd4 = baseData as IEASPrtCmd4; if (this.NotifyIAGWConnectionState != null) { if (protoCmd4.SenderType == IEASSenderType.IAGW) { bool authResult = (protoCmd4.AuthentiResult == 0x01) ? true : false; IAGWConnectionEventArgs copy = new IAGWConnectionEventArgs(); lock (this.currentIAGWConnectionState) { this.currentIAGWConnectionState.IsAuthenticated = authResult; copy.DeepCopyFrom(this.currentIAGWConnectionState); } this.NotifyIAGWConnectionState(this, copy); } else { // 메시지 유효성 오류: 무시 } } } break; case KCAPCmdValue.Order: { IEASPrtCmd1 protoCmd1 = baseData as IEASPrtCmd1; if (this.NotifyCAPReceived != null) { CAP capMsg = new CAP(protoCmd1.CAPMessage); SenderTypes senderType = ConvertToLocalSenderType(protoCmd1.SenderType); ReceivedCAPInfo capInfo = new ReceivedCAPInfo(senderType, capMsg); this.NotifyCAPReceived(this, new CapEventArgs(capInfo)); } } break; case KCAPCmdValue.Polling: default: { // do nothing } break; } } catch (Exception ex) { System.Console.WriteLine("[CommunicationManager] DistributeKCAPCommandData( " + ex.ToString() + " )"); FileLogManager.GetInstance().WriteLog("[CommunicationManager] DistributeKCAPCommandData( Exception=[" + ex.ToString() + "] )"); return(-99); } return(0); }