Esempio n. 1
0
        /// <summary>
        /// The function commands the retreival of the station list from an addressee. If a mission code
        /// is provided, only the stations of that mission are returned. By default, all the station list
        /// from the database are returned.
        /// </summary>
        /// <param name="sessionId">Identifier for the session.</param>
        /// <param name="missionCode">The mission code.</param>
        /// <param name="elementId">Identifier for the element.</param>
        /// <returns>
        /// The code “request accepted” when the command is valid and the list of stations for the given
        /// mission code/element id, or and error code when the command is rejected.
        /// </returns>
        RealTimeRetrieveStationListResult IRealTimeService.RetrieveStationList(Guid sessionId, string missionCode, string elementId)
        {
            var result = new RealTimeRetrieveStationListResult();

            result.RequestId   = Guid.Empty;
            result.ResultCode  = RealTimeServiceErrorEnum.ErrorInvalidSessionId;
            result.MissionCode = missionCode;
            result.ElementID   = elementId;
            result.StationList = null;

            if (_sessionManager.IsSessionValid(sessionId))
            {
                string error = _sessionManager.GenerateRequestID(sessionId, out result.RequestId);

                if (string.IsNullOrEmpty(error))
                {
                    AvailableElementData elementData;
                    T2GManagerErrorEnum  rqstResult = _t2gManager.GetAvailableElementDataByElementNumber(elementId, out elementData);

                    switch (rqstResult)
                    {
                    case T2GManagerErrorEnum.eSuccess:
                    {
                        try
                        {
                            GetStationListFromLMTDataBase(missionCode, elementId, elementData, ref result);
                        }
                        catch (TimeoutException)
                        {
                            result.ResultCode = RealTimeServiceErrorEnum.ErrorRemoteDatastoreUnavailable;
                        }
                        catch (CommunicationException)
                        {
                            result.ResultCode = RealTimeServiceErrorEnum.ErrorRemoteDatastoreUnavailable;
                        }
                    }

                    break;

                    case T2GManagerErrorEnum.eT2GServerOffline:
                        result.ResultCode = RealTimeServiceErrorEnum.T2GServerOffline;
                        break;

                    case T2GManagerErrorEnum.eElementNotFound:
                    default:
                        result.ResultCode = RealTimeServiceErrorEnum.ErrorInvalidElementId;
                        break;
                    }
                }
                else
                {
                    result.ResultCode = RealTimeServiceErrorEnum.ErrorRequestIdGeneration;
                }
            }
            else
            {
                result.ResultCode = RealTimeServiceErrorEnum.ErrorInvalidSessionId;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>Gets station list from lmt data base.</summary>
        /// <param name="missionCode">The mission code.</param>
        /// <param name="elementId">Identifier for the element.</param>
        /// <param name="elementData">Information describing the element.</param>
        /// <param name="result">[in,out] The result.</param>
        public static void GetStationListFromLMTDataBase(string missionCode, string elementId, AvailableElementData elementData, ref RealTimeRetrieveStationListResult result)
        {
            if (_instanceCreator == null)
            {
                throw new InvalidOperationException("The method GetStationListFromLMTDataBase cannot be invoked when no valid instance of Realtime service exist.");
            }

            _instanceCreator.PerformGetStationListFromLMTDataBase(missionCode, elementId, elementData, ref result);
        }
Esempio n. 3
0
        /// <summary>
        /// Performs the get station list from LMT data base.
        /// </summary>
        /// <param name="missionCode">The mission code.</param>
        /// <param name="elementId">Identifier for the element.</param>
        /// <param name="elementData">Information describing the element.</param>
        /// <param name="result">[in, out] The result.</param>
        protected virtual void PerformGetStationListFromLMTDataBase(string missionCode, string elementId, AvailableElementData elementData, ref RealTimeRetrieveStationListResult result)
        {
            if (result == null)
            {
                result            = new RealTimeRetrieveStationListResult();
                result.ResultCode = RealTimeServiceErrorEnum.RequestAccepted;
            }

            if (elementData.PisBaselineData != null)
            {
                if (!string.IsNullOrEmpty(elementData.PisBaselineData.CurrentVersionLmtOut))
                {
                    string lmtVersion = elementData.PisBaselineData.CurrentVersionLmtOut;

                    using (var remoteDataStore = _remoteDataStoreFactory.GetRemoteDataStoreInstance() as RemoteDataStoreProxy)
                    {
                        if (remoteDataStore != null)
                        {
                            if (remoteDataStore.checkIfDataPackageExists("LMT", lmtVersion))
                            {
                                var openPackageResult = remoteDataStore.openLocalDataPackage(
                                    "LMT",
                                    lmtVersion,
                                    string.Empty);

                                if (openPackageResult.Status == OpenDataPackageStatusEnum.COMPLETED)
                                {
                                    string lmtDatabaseFilePath = FindLmtDatabaseFilePath(openPackageResult.LocalPackagePath);
                                    if (!string.IsNullOrEmpty(lmtDatabaseFilePath))
                                    {
                                        using (var lmtDatabaseAccessor = new LmtDatabaseAccessor(lmtDatabaseFilePath, _platformType))
                                        {
                                            result.ResultCode  = RealTimeServiceErrorEnum.RequestAccepted;
                                            result.StationList = new List <string>();

                                            if (string.IsNullOrEmpty(missionCode))
                                            {
                                                foreach (var station in lmtDatabaseAccessor.GetStationList())
                                                {
                                                    if (!result.StationList.Contains(station.OperatorCode))
                                                    {
                                                        result.StationList.Add(station.OperatorCode);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                uint?missionId = lmtDatabaseAccessor.GetMissionInternalCodeFromOperatorCode(missionCode);
                                                if (missionId != null)
                                                {
                                                    List <uint> missionRoute = lmtDatabaseAccessor.GetMissionRoute((uint)missionId);
                                                    foreach (uint stationId in missionRoute)
                                                    {
                                                        result.StationList.Add(lmtDatabaseAccessor.GetStationOperatorCodeFromInternalCode(stationId));
                                                    }
                                                }
                                                else
                                                {
                                                    result.ResultCode = RealTimeServiceErrorEnum.ErrorInvalidMissionCode;
                                                }
                                            }

                                            if (result.ResultCode == RealTimeServiceErrorEnum.RequestAccepted &&
                                                result.StationList.Count == 0)
                                            {
                                                result.ResultCode = RealTimeServiceErrorEnum.InfoNoDataForElement;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        result.ResultCode = RealTimeServiceErrorEnum.ErrorRemoteDatastoreUnavailable;
                                        LogManager.WriteLog(TraceType.ERROR, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_RETRIEVESTATIONLIST_LMT_DB_NOT_FOUND, lmtVersion, elementId), "PIS.Ground.RealTime.RealTimeService.RetrieveStationList", null, EventIdEnum.RealTime);
                                    }
                                }
                                else
                                {
                                    result.ResultCode = RealTimeServiceErrorEnum.ErrorRemoteDatastoreUnavailable;
                                    LogManager.WriteLog(TraceType.ERROR, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_RETRIEVESTATIONLIST_CANT_OPEN_PACKAGE, lmtVersion, elementId), "PIS.Ground.RealTime.RealTimeService.RetrieveStationList", null, EventIdEnum.RealTime);
                                }
                            }
                            else
                            {
                                result.ResultCode = RealTimeServiceErrorEnum.ErrorRemoteDatastoreUnavailable;
                                LogManager.WriteLog(TraceType.ERROR, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_RETRIEVESTATIONLIST_UNKNOWN_EMBEDDED_LMT, lmtVersion), "PIS.Ground.RealTime.RealTimeService.RetrieveStationList", null, EventIdEnum.RealTime);
                            }
                        }
                        else
                        {
                            result.ResultCode = RealTimeServiceErrorEnum.ErrorRemoteDatastoreUnavailable;
                            LogManager.WriteLog(TraceType.ERROR, string.Format(CultureInfo.CurrentCulture, Logs.ERROR_UNKNOWN), "PIS.Ground.RealTime.RealTimeService.RetrieveStationList", null, EventIdEnum.RealTime);
                        }
                    }
                }
                else
                {
                    result.ResultCode = RealTimeServiceErrorEnum.InfoNoDataForElement;
                }
            }
        }
Esempio n. 4
0
        /// <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);
                }
            }
        }