/// <summary> /// CAP 메시지로부터 발령 대상 정보를 추출. /// 1)Private의 경우, 표준경보시스템 명칭의 연속 문자열(구분자 콤마) /// 2)Public/Restricted의 경우, 지역 명칭의 연속 문자열(구분자 콤마) /// </summary> /// <param name="msg"></param> /// <returns></returns> public string ExtractTargetNamesFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); if (msg == null || msg.Info == null || msg.Info.Count < 1) { return(null); } string targets = string.Empty; StringBuilder builder = new StringBuilder(); InfoType info = msg.Info[0]; if (info == null) { return(null); } if (info.Area == null || info.Area.Count < 1) { return(null); } targets = info.Area[0].AreaDesc.Replace(' ', ','); return(targets); }
/// <summary> /// CAP 메시지로부터 시스템 종류 정보를 추출. /// </summary> /// <param name="msg"></param> /// <returns></returns> public List <SASKind> ExtractTargetKindsFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); if (msg.Scope != CAPLib.ScopeType.Restricted) { return(null); } if (string.IsNullOrEmpty(msg.Restriction)) { return(null); } string[] stringSeperators = new string[] { "," }; string[] dividedArray = msg.Restriction.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries); if (dividedArray == null || dividedArray.Count() <= 0) { return(null); } List <SASKind> targets = new List <SASKind>(); foreach (string systemKindCode in dividedArray) { SASKind kindInfo = BasisData.FindSASKindByCode(systemKindCode); if (kindInfo != null) { targets.Add(kindInfo); } } return(targets); }
/// <summary> /// CAP 메시지를 기반으로 헤드라인 문자열 작성. /// </summary> /// <param name="msg"></param> /// <returns></returns> public string MakeHeadline(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); try { StringBuilder builder = new StringBuilder(); foreach (InfoType msgInfo in msg.Info) { if (msgInfo.Language.ToUpper() == BasisData.DEFAULT_LANGUAGECODE.ToUpper()) { builder.Append(msgInfo.Headline); break; } } if (builder.Length < 1) { OrderMode modeInfo = BasisData.FindOrderModeInfoByCode(msg.MessageStatus.Value); if (modeInfo == null || string.IsNullOrEmpty(modeInfo.Name)) { FileLogManager.GetInstance().WriteLog("[CAPInfo] MakeHeadline ( 헤드라인 정보 작성 실패. 모드 정보를 찾을 수 없습니다. )"); throw new Exception("[CAPInfo] 헤드라인 정보 작성 실패. 모드 정보를 찾을 수 없습니다."); } if (msg.Info == null || msg.Info.Count < 1 || string.IsNullOrEmpty(msg.Info[0].Event)) { FileLogManager.GetInstance().WriteLog("[CAPInfo] MakeHeadline ( 헤드라인 정보 작성 실패. 이벤트 코드 정보를 찾을 수 없습니다. )"); throw new Exception("[CAPInfo] 헤드라인 정보 작성 실패. 이벤트 코드 정보를 찾을 수 없습니다."); } string disasterKindName = msg.Info[0].Event; string targets = ExtractTargetNamesFromCAP(msg); if (string.IsNullOrEmpty(targets)) { FileLogManager.GetInstance().WriteLog("[CAPInfo] MakeHeadline ( 헤드라인 정보 작성 실패. 발령 대상 정보를 찾을 수 없습니다. )"); throw new Exception("[CAPInfo] 헤드라인 정보 작성 실패. 발령 대상 정보를 찾을 수 없습니다."); } builder.Append(msg.SentDateTime.ToString()); builder.Append(" [" + modeInfo.Name + "]"); builder.Append(" [" + targets.Replace(',', '/') + "] 대상으로"); builder.Append(" [" + disasterKindName + "]"); builder.Append(" 발령"); } return(builder.ToString()); } catch (Exception ex) { System.Console.WriteLine("[CAPInfo] MakeHeadline( Exception=[ " + ex.ToString() + "] )"); FileLogManager.GetInstance().WriteLog("[CAPInfo] MakeHeadline ( Exception=[" + ex.ToString() + "] )"); throw new Exception("[CAPInfo] 헤드라인 정보 작성 실패. 처리 중 예외가 발생하였습니다."); } }
public string ExtractAckNoteFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); if (msg == null || msg.MessageType.Value != MsgType.Ack) { return(null); } return(msg.Note); }
/// <summary> /// 리스트 갱신. /// </summary> private void UpdateReportList() { try { this.lvClearWaitingList.Items.Clear(); if (this.currentWaitingList == null || this.currentWaitingList.Count <= 0) { return; } CAPHelper helper = new CAPHelper(); foreach (OrderRecord record in this.currentWaitingList) { // 번호 int itemNo = this.lvClearWaitingList.Items.Count + 1; AdengListViewItem newItem = this.lvClearWaitingList.Items.Add(itemNo.ToString()); // 발령 아이디 newItem.SubItems.Add(record.CAPID); // 발령 시각 newItem.SubItems.Add(record.OrderedTime.ToString()); // 발령 모드 newItem.SubItems.Add(BasisData.GetDisplayStringOrderMode(record.OrderMode)); // 재난종류 newItem.SubItems.Add(BasisData.GetDisplayStringDisasterKindName(record.DisasterKindCode)); CAP msg = new CAP(record.CapText); if (msg == null) { continue; } // 발령 대상 string targetNames = helper.ExtractTargetNamesFromCAP(msg); if (targetNames == null) { targetNames = ""; } newItem.SubItems.Add(targetNames); newItem.Name = record.CAPID; newItem.Tag = record; } } catch (Exception ex) { System.Console.WriteLine("[ClearAlertWaitingListForm] UpdateReportList( Exception: \n" + ex.ToString() + ")"); FileLogManager.GetInstance().WriteLog("[ClearAlertWaitingListForm] UpdateReportList( Exception=[" + ex.ToString() + "] )"); } }
/// <summary> /// CAP 메시지로부터 발령 대상 시스템 정보를 추출. /// </summary> /// <param name="msg"></param> /// <returns></returns> public List <SASProfile> ExtractTargetSystemsFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); System.Diagnostics.Debug.Assert(msg.Info != null); if (msg.Scope != CAPLib.ScopeType.Private) { return(null); } if (string.IsNullOrEmpty(msg.Addresses)) { return(null); } List <SASProfile> profileInfo = DBManager.GetInstance().QuerySASInfo(); if (profileInfo == null || profileInfo.Count < 1) { return(null); } string[] stringSeperators = new string[] { "," }; string[] dividedArray = msg.Addresses.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries); if (dividedArray == null || dividedArray.Count() <= 0) { return(null); } List <SASProfile> targets = new List <SASProfile>(); foreach (string systemIP in dividedArray) { foreach (SASProfile profile in profileInfo) { if (profile.IpAddress == systemIP) { SASProfile copy = new SASProfile(); copy.DeepCopyFrom(profile); targets.Add(copy); break; } } } return(targets); }
public List <CAPParameterMsgInfo> ExtractMsgTextFromCAP(CAP msg, string languageKindCode = null, string mediaTypeCode = null) { System.Diagnostics.Debug.Assert(msg != null); if (msg.Info == null || msg.Info.Count < 1 || languageKindCode == null) { return(null); } List <CAPParameterMsgInfo> result = new List <CAPParameterMsgInfo>(); foreach (InfoType info in msg.Info) { if (info == null) { continue; } if (languageKindCode != null && info.Language != languageKindCode) { continue; } foreach (NameValueType parameter in info.Parameter) { if (parameter == null) { continue; } if (mediaTypeCode != null && mediaTypeCode != parameter.Name) { continue; } CAPParameterMsgInfo msgInfo = new CAPParameterMsgInfo(); msgInfo.ValueName = parameter.Name; msgInfo.Value = parameter.Value; msgInfo.LanguageCode = info.Language; result.Add(msgInfo); } } return(result); }
/// <summary> /// CAP 메시지로부터 발령 대상 정보를 추출. /// 1)Private의 경우, 아이디어드레스의 연속 문자열(구분자 콤마) /// 2)Public/Restricted의 경우, 지역코드의 연속 문자열(구분자 콤마) /// </summary> /// <param name="msg"></param> /// <returns></returns> public List <string> ExtractTargetCodesFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); List <string> targets = new List <string>(); StringBuilder builder = new StringBuilder(); if (msg.Scope == CAPLib.ScopeType.Private) { List <SASProfile> targetSystems = ExtractTargetSystemsFromCAP(msg); if (targetSystems == null) { return(null); } foreach (SASProfile system in targetSystems) { targets.Add(system.IpAddress); } } else { List <RegionDefinition> targetRegions = ExtractTargetRegionsFromCAP(msg); if (targetRegions == null) { return(null); } foreach (RegionDefinition region in targetRegions) { if (region.Code != null) { targets.Add(region.Code.ToString()); } } } return(targets); }
public string GetLanguageNamesFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); if (msg.Info == null || msg.Info.Count < 1) { return(null); } bool isFirst = true; StringBuilder builder = new StringBuilder(); foreach (InfoType info in msg.Info) { if (info == null || string.IsNullOrEmpty(info.Language)) { continue; } string name = string.Empty; MsgTextDisplayLanguageKind kindInfo = BasisData.FindMsgTextLanguageInfoByCode(info.Language); if (kindInfo == null) { continue; } if (isFirst) { isFirst = false; builder.Append(kindInfo.LanguageName); } else { builder.Append("," + kindInfo.LanguageName); } } return(builder.ToString()); }
private void UpdateResponseList() { this.lvOrderResponse.Items.Clear(); if (this.lvOrderResponse.Columns == null) { return; } if (this.currentResponseList == null) { return; } Dictionary <string, SASProfile> sasProfiles = new Dictionary <string, SASProfile>(); List <SASProfile> sasList = DBManager.GetInstance().QuerySASInfo(); if (sasList != null) { foreach (SASProfile profile in sasList) { sasProfiles.Add(profile.ID, profile); } } bool isAllOK = true; bool isAllNG = true; foreach (OrderResponseProfile response in this.currentResponseList) { if (response == null) { continue; } bool existOK = false; bool existNG = false; // 발령 결과 AdengListViewItem item = this.lvOrderResponse.Items.Add(" "); item.ForeColor = Color.Gray; item.SubItems[0].Text = "?"; // 응답 시스템 이름 if (sasProfiles.ContainsKey(response.SenderID)) { item.SubItems.Add(sasProfiles[response.SenderID].Name); } else { item.SubItems.Add(response.SenderID); } if (string.IsNullOrEmpty(response.CapMsg)) { // 리소스 인증 item.SubItems.Add(""); // 경보 서비스 item.SubItems.Add(""); // 수행 결과 item.SubItems.Add(""); } else { CAP capMsg = new CAP(response.CapMsg); if (capMsg == null) { continue; } if (capMsg == null || capMsg.MessageType == null || (capMsg.MessageType.Value != MsgType.Ack && capMsg.MessageType.Value != MsgType.Error)) { MessageBox.Show("올바르지 않는 데이터가 존재합니다.", "데이터 오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); break; } if (string.IsNullOrEmpty(capMsg.Note)) { continue; } string[] seperator = { " ", }; string[] resAll = capMsg.Note.Split(seperator, StringSplitOptions.RemoveEmptyEntries); if (resAll == null || resAll.Count() < 1) { continue; } string responseCodeStr = resAll[0]; int responseCode = -1; if (!int.TryParse(responseCodeStr, out responseCode)) { responseCode = -1; } // 리소스 인증 if (responseCode < (int)OrderResponseCodes.SasResourceCerciticationOK) { item.SubItems.Add(""); } else if (responseCode >= (int)OrderResponseCodes.SasResourceCerciticationOK && responseCode != (int)OrderResponseCodes.SasResourceCerciticationNG) { item.SubItems.Add("성공"); existOK = true; } else { item.SubItems.Add("실패"); existNG = true; } // 경보 서비스 if (responseCode < (int)OrderResponseCodes.SasAlertServiceOK) { item.SubItems.Add(""); } else if (responseCode >= (int)OrderResponseCodes.SasAlertServiceOK && responseCode != (int)OrderResponseCodes.SasAlertServiceError) { item.SubItems.Add("성공"); existOK = true; } else { item.SubItems.Add("실패"); existNG = true; } // 수행 결과 (전체/성공/실패) if (resAll.Count() > 1 && !string.IsNullOrEmpty(resAll[1])) { string res = resAll[1].Replace(",", "/"); item.SubItems.Add(res); } if (existNG) { // 하나라도 실패가 있으면 실패로 표시 item.ForeColor = Color.Red; item.SubItems[0].Text = "X"; isAllOK = false; } else if (existOK) { if (responseCode == 800) { // 성공 item.ForeColor = Color.Black; item.SubItems[0].Text = "O"; isAllNG = false; } else { // 하나라도 성공이 있으면 응답중 item.ForeColor = Color.Black; item.SubItems[0].Text = "△"; } } else { // 아무 것도 없으면 무응답 item.ForeColor = Color.Gray; item.SubItems[0].Text = "?"; } } } if (isAllOK) { this.lvSelectedOrder.Items[0].SubItems[0].Text = "O"; } else if (isAllNG) { this.lvSelectedOrder.Items[0].SubItems[0].Text = "X"; } else { this.lvSelectedOrder.Items[0].SubItems[0].Text = "△"; } }
private void UpdateOrderDetailList() { this.dgvOrderDetail.Rows.Clear(); if (this.dgvOrderDetail.Columns == null) { return; } this.dgvOrderDetail.Rows.Add("발령 아이디", this.currentOrderRecord.CAPID.ToString()); this.dgvOrderDetail.Rows.Add("발령 시각", this.currentOrderRecord.OrderedTime.ToString()); CAP capMsg = new CAP(this.currentOrderRecord.CapText); if (capMsg == null) { return; } this.dgvOrderDetail.Rows.Add("발령원", capMsg.Source); this.dgvOrderDetail.Rows.Add("모드", BasisData.GetDisplayStringOrderMode(this.currentOrderRecord.OrderMode)); this.dgvOrderDetail.Rows.Add("이벤트 종류", BasisData.GetDisplayStringDisasterKindName(this.currentOrderRecord.DisasterKindCode)); CAPHelper helper = new CAPHelper(); string targets = helper.ExtractTargetNamesFromCAP(capMsg); if (!string.IsNullOrEmpty(targets)) { this.dgvOrderDetail.Rows.Add("대상", targets); } List <SASKind> targetKinds = helper.ExtractTargetKindsFromCAP(capMsg); if (targetKinds != null && targetKinds.Count > 0) { bool isFirst = true; StringBuilder builder = new StringBuilder(); foreach (SASKind kind in targetKinds) { if (isFirst) { isFirst = false; builder.Append(kind.Name); } else { builder.Append("," + kind.Name); } } if (builder.Length > 0) { this.dgvOrderDetail.Rows.Add("시스템 종류", builder.ToString()); } } else { this.dgvOrderDetail.Rows.Add("시스템 종류", "전체"); } string languages = helper.GetLanguageNamesFromCAP(capMsg); if (!string.IsNullOrEmpty(languages)) { this.dgvOrderDetail.Rows.Add("언어", languages); } List <CAPParameterMsgInfo> msgInfo = helper.ExtractMsgTextFromCAP(capMsg, BasisData.DEFAULT_LANGUAGECODE); if (msgInfo != null && msgInfo.Count > 0) { foreach (CAPParameterMsgInfo info in msgInfo) { if (info.ValueName.ToUpper().Contains("TTS")) { int height = this.dgvOrderDetail.Rows.GetRowsHeight(DataGridViewElementStates.Displayed); int remainHeight = this.dgvOrderDetail.Height - height; int index = this.dgvOrderDetail.Rows.Add("문안[TTS]", info.Value); break; } } foreach (CAPParameterMsgInfo info in msgInfo) { if (info.ValueName.ToUpper().Contains("CBS")) { int height = this.dgvOrderDetail.Rows.GetRowsHeight(DataGridViewElementStates.Displayed); int remainHeight = this.dgvOrderDetail.Height - height; int index = this.dgvOrderDetail.Rows.Add("문안[CBS]", info.Value); break; } } foreach (CAPParameterMsgInfo info in msgInfo) { if (info.ValueName.ToUpper().Contains("BOARD")) { int height = this.dgvOrderDetail.Rows.GetRowsHeight(DataGridViewElementStates.Displayed); height += this.dgvOrderDetail.ColumnHeadersHeight + 2; int remainHeight = this.dgvOrderDetail.Height - height; int index = this.dgvOrderDetail.Rows.Add("문안[Board]", info.Value); if (remainHeight > 0) { //this.dgvOrderDetail.Rows[index].MinimumHeight = remainHeight; } break; } } foreach (CAPParameterMsgInfo info in msgInfo) { if (info.ValueName.ToUpper().Contains("DMB")) { int height = this.dgvOrderDetail.Rows.GetRowsHeight(DataGridViewElementStates.Displayed); height += this.dgvOrderDetail.ColumnHeadersHeight + 2; int remainHeight = this.dgvOrderDetail.Height - height; int index = this.dgvOrderDetail.Rows.Add("문안[DMB]", info.Value); if (remainHeight > 0) { //this.dgvOrderDetail.Rows[index].MinimumHeight = remainHeight; } break; } } } else { this.dgvOrderDetail.Rows.Add("문안[TTS]"); this.dgvOrderDetail.Rows.Add("문안[CBS]"); this.dgvOrderDetail.Rows.Add("문안[Board]"); this.dgvOrderDetail.Rows.Add("문안[DMB]"); } }
/// <summary> /// The common start to every capability csv... /// </summary> /// <param name="a_cap">Capability number</param> /// <param name="a_twon">Container</param> /// <param name="a_twty">Data type</param> /// <returns></returns> private CSV Common(CAP a_cap, TWON a_twon, TWTY a_twty) { CSV csv = new CSV(); // Add the capability... string szCap = a_cap.ToString(); if (!szCap.Contains("_")) { szCap = "0x" + ((ushort)a_cap).ToString("X"); } // Build the CSV... csv.Add(szCap); csv.Add("TWON_" + a_twon); csv.Add("TWTY_" + a_twty); // And return it... return (csv); }
/// <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); }
/// <summary> /// CAP 메시지로부터 발령 대상 지역 정보를 추출. /// </summary> /// <param name="msg"></param> /// <returns></returns> public List <RegionDefinition> ExtractTargetRegionsFromCAP(CAP msg) { System.Diagnostics.Debug.Assert(msg != null); if (msg.Scope == CAPLib.ScopeType.Private) { return(null); } if (msg.Info == null || msg.Info.Count < 1) { return(null); } List <RegionDefinition> targets = new List <RegionDefinition>(); InfoType info = msg.Info[0]; if (info == null) { return(null); } if (info.Area == null || info.Area.Count < 1) { return(null); } foreach (AreaType area in info.Area) { int areaIndex = -1; string[] stringSeperators = new string[] { " " }; foreach (NameValueType geoCode in area.GeoCode) { areaIndex++; if (geoCode.Name != "KRDSTGeocode") { continue; } string code = geoCode.Value; RegionProfile profile = BasisData.FindRegion(code); if (profile == null) { string areaDesc = area.AreaDesc; if (areaDesc == null) { continue; } string[] areaNames = areaDesc.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries); if (areaNames != null && areaNames.Count() <= areaIndex) { continue; } RegionDefinition region = new RegionDefinition(code, areaNames[areaIndex]); targets.Add(region); } else { RegionDefinition region = new RegionDefinition(profile.Code, profile.Name); targets.Add(region); } } } return(targets); }
public ReceivedCAPInfo(SenderTypes senderType, CAP msg) { this.msg = msg; this.msgSenderType = senderType; }
public string GetHeadlineString() { if (this == null) { return(string.Empty); } try { CAPHelper helper = new CAPHelper(); StringBuilder headline = new StringBuilder(); string association = string.Empty; if (this.LocationKind == OrderLocationKind.Other) { association = "[연계] "; } CAP msg = new CAP(this.CapText); string headlineNormal = helper.MakeHeadline(msg); if (string.IsNullOrEmpty(headlineNormal)) { headline.Append(headlineNormal); } if (headline.Length < 1) { OrderMode mode = BasisData.FindOrderModeInfoByCode(this.OrderMode); if (mode == null) { headline.Append(this.OrderedTime + " [ Unknown ]"); } else { headline.Append(this.OrderedTime + " [" + mode.Name + "]"); } string targets = helper.ExtractTargetNamesFromCAP(msg); if (!string.IsNullOrEmpty(targets)) { headline.Append("[" + targets.Replace(',', '/') + "] 대상으로"); } else { headline.Append("[ Unknown ] 대상으로"); } string disasterName = "Unknown"; if (msg.Info != null && msg.Info.Count > 0) { disasterName = msg.Info[0].Event; } else { DisasterKind disasterKind = BasisData.FindDisasterKindByCode(this.DisasterKindCode); if (disasterKind != null) { disasterName = disasterKind.Name; } } headline.Append(" [" + disasterName + "]"); headline.Append(" 발령"); if (this.RefType == OrderReferenceType.Cancel) { headline.Append(" 취소"); } } return(association + headline.ToString()); } catch (Exception ex) { System.Console.WriteLine("[OrderInfo] GetHeadlineString( Exception=[" + ex.ToString() + "] )"); FileLogManager.GetInstance().WriteLog("[OrderInfo] GetHeadlineString ( Exception=[" + ex.ToString() + "] )"); return(string.Empty); } }