/// <summary>Process the mission data sending.</summary> /// <param name="elementId">Identifier for the element.</param> /// <param name="missionCode">The mission code.</param> private static void ProcessMissionDataSending(string elementId, string missionCode) { ServiceInfo serviceInfo = null; T2GManagerErrorEnum t2gResult = _t2gManager.GetAvailableServiceData(elementId, (int)eServiceID.eSrvSIF_RealTimeServer, out serviceInfo); if (t2gResult == T2GManagerErrorEnum.eSuccess) { string endpoint = "http://" + serviceInfo.ServiceIPAddress + ":" + serviceInfo.ServicePortNumber; try { // Call RealTime train service and send the request. using (Train.RealTime.RealTimeTrainServiceClient lTrainClient = new Train.RealTime.RealTimeTrainServiceClient("RealTimeTrainEndpoint", endpoint)) { try { Train.RealTime.DelayType rtinfoDelay = null; Train.RealTime.WeatherType rtinfoWeather = null; RealTimeUtils.ConvertGroundMissionDataToTrainMissionData( _rtpisDataStore.GetMissionRealTimeInformation(missionCode), out rtinfoDelay, out rtinfoWeather); Train.RealTime.SetMissionRealTimeRequest request = new Train.RealTime.SetMissionRealTimeRequest( missionCode, rtinfoDelay != null ? Train.RealTime.ActionTypeEnum.Set : Train.RealTime.ActionTypeEnum.Delete, rtinfoDelay, rtinfoWeather != null ? Train.RealTime.ActionTypeEnum.Set : Train.RealTime.ActionTypeEnum.Delete, rtinfoWeather); Train.RealTime.SetMissionRealTimeResponse response = ((Train.RealTime.IRealTimeTrainService)lTrainClient).SetMissionRealTime(request); ProcessCommandResultList(elementId, missionCode, response.ResultList); } catch (Exception ex) { LogManager.WriteLog(TraceType.EXCEPTION, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_FAILED_SEND_REQUEST_TO_EMBEDDED, elementId), "PIS.Ground.RealTime.RealTimeService.ProcessMissionDataSending", ex, EventIdEnum.RealTime); } finally { if (lTrainClient.State == CommunicationState.Faulted) { lTrainClient.Abort(); } } } } catch (Exception ex) { LogManager.WriteLog(TraceType.EXCEPTION, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_FAILED_SEND_REQUEST_TO_EMBEDDED, elementId), "PIS.Ground.RealTime.RealTimeService.ProcessMissionDataSending", ex, EventIdEnum.RealTime); } } else if (t2gResult == T2GManagerErrorEnum.eElementNotFound) { LogManager.WriteLog(TraceType.WARNING, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_GET_SERVICE_DATA_FOR_ELEMENT, elementId, t2gResult), "PIS.Ground.RealTime.RealTimeService.ProcessMissionDataSending", null, EventIdEnum.RealTime); } else if (LogManager.IsTraceActive(TraceType.DEBUG)) { LogManager.WriteLog(TraceType.DEBUG, string.Format(CultureInfo.CurrentCulture, Logs.DEBUG_GET_SERVICE_DATA_FOR_ELEMENT, elementId, t2gResult), "PIS.Ground.RealTime.RealTimeService.ProcessMissionDataSending", null, EventIdEnum.RealTime); } }
/// <summary>Process the station data sending.</summary> /// <param name="elementId">Identifier for the element.</param> /// <param name="stationCodeList">List of station codes.</param> private static void ProcessStationDataSending(string elementId, KeyValuePair <string, List <string> > stationCodeList) { List <RealTimeStationStatusType> stationDataList = _rtpisDataStore.GetStationRealTimeInformation(stationCodeList.Key, stationCodeList.Value); if (stationDataList == null) { stationDataList = new List <RealTimeStationStatusType>(); } if (stationDataList.Count == 0) { RealTimeRetrieveStationListResult result = new RealTimeRetrieveStationListResult(); AvailableElementData elementData = null; T2GManagerErrorEnum t2gTmpResult = _t2gManager.GetAvailableElementDataByElementNumber(elementId, out elementData); if (t2gTmpResult == T2GManagerErrorEnum.eSuccess) { RealTimeService.GetStationListFromLMTDataBase(stationCodeList.Key, elementId, elementData, ref result); if (result.ResultCode == RealTimeServiceErrorEnum.RequestAccepted) { stationDataList.Capacity = result.StationList.Count; foreach (var station in result.StationList) { stationDataList.Add(new RealTimeStationStatusType() { StationID = station }); } } else { LogManager.WriteLog(TraceType.ERROR, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_ACCESSING_STATIONLIST_FOR_ELEMENT, elementId, "GetStationListFromLMTDataBase", result.ResultCode), "PIS.Ground.RealTime.RealTimeService.ProcessStationDataSending", null, EventIdEnum.RealTime); } } else { LogManager.WriteLog(TraceType.ERROR, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_ACCESSING_STATIONLIST_FOR_ELEMENT, elementId, "GetAvailableElementDataByElementNumber", t2gTmpResult), "PIS.Ground.RealTime.RealTimeService.ProcessStationDataSending", null, EventIdEnum.RealTime); } } // Updating the train is important only when the data of at least one station need to be updated. if (stationDataList.Count != 0) { ServiceInfo serviceInfo = null; T2GManagerErrorEnum t2gResult = _t2gManager.GetAvailableServiceData(elementId, (int)eServiceID.eSrvSIF_RealTimeServer, out serviceInfo); if (t2gResult == T2GManagerErrorEnum.eSuccess) { string endpoint = "http://" + serviceInfo.ServiceIPAddress + ":" + serviceInfo.ServicePortNumber; try { // Call RealTime train service and send the request. using (Train.RealTime.RealTimeTrainServiceClient lTrainClient = new Train.RealTime.RealTimeTrainServiceClient("RealTimeTrainEndpoint", endpoint)) { try { Train.RealTime.ListOfStationDataType stationDataListType = null; RealTimeUtils.ConvertGroundStationDataToTrainStationData( stationDataList, out stationDataListType); Train.RealTime.SetStationRealTimeRequest request = new Train.RealTime.SetStationRealTimeRequest(stationCodeList.Key, stationDataListType); Train.RealTime.SetStationRealTimeResponse response = ((Train.RealTime.IRealTimeTrainService)lTrainClient).SetStationRealTime(request); ProcessCommandResultList(elementId, stationCodeList.Key, response.ResultList); } catch (Exception ex) { LogManager.WriteLog(TraceType.EXCEPTION, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_FAILED_SEND_REQUEST_TO_EMBEDDED, elementId), "PIS.Ground.RealTime.RealTimeService.ProcessStationDataSending", ex, EventIdEnum.RealTime); } finally { if (lTrainClient.State == CommunicationState.Faulted) { lTrainClient.Abort(); } } } } catch (Exception ex) { LogManager.WriteLog(TraceType.EXCEPTION, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_FAILED_SEND_REQUEST_TO_EMBEDDED, elementId), "PIS.Ground.RealTime.RealTimeService.ProcessStationDataSending", ex, EventIdEnum.RealTime); } } else if (t2gResult == T2GManagerErrorEnum.eElementNotFound) { LogManager.WriteLog(TraceType.WARNING, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_GET_SERVICE_DATA_FOR_ELEMENT, elementId, t2gResult), "PIS.Ground.RealTime.RealTimeService.ProcessStationDataSending", null, EventIdEnum.RealTime); } else if (LogManager.IsTraceActive(TraceType.DEBUG)) { LogManager.WriteLog(TraceType.DEBUG, string.Format(CultureInfo.CurrentCulture, Logs.DEBUG_GET_SERVICE_DATA_FOR_ELEMENT, elementId, t2gResult), "PIS.Ground.RealTime.RealTimeService.ProcessStationDataSending", null, EventIdEnum.RealTime); } } }