Beispiel #1
0
        /// <summary>Uninitializes this object.</summary>
        /// <param name="force">Indicates if the uninitialization shall be forced.</param>
        private static void Uninitialize(bool force)
        {
            lock (_initializationLock)
            {
                if (_initializationCount < 2 || force)
                {
                    IDisposable disposable = _requestProcessor as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }

                    if (_t2gManager != null)
                    {
                        _t2gManager.Dispose();
                        _t2gManager = null;
                    }
                    _remoteDataStoreFactory = null;
                    _rtpisDataStore         = null;
                    _sessionManager         = null;
                    _notificationSender     = null;
                    _instanceCreator        = null;
                    _requestProcessor       = null;
                }
            }

            if (_initializationCount != 0 && !force)
            {
                _initializationCount--;
            }
        }
Beispiel #2
0
        /// <summary>Initializes this object.</summary>
        private void Initialize()
        {
            lock (_initializationLock)
            {
                if (_initializationCount == 0)
                {
                    try
                    {
                        _instanceCreator = this;
                        _sessionManager  = new SessionManager();

                        _notificationSender = new NotificationSender(_sessionManager);

                        _t2gManager = T2GManagerContainer.T2GManager;

                        _remoteDataStoreFactory = new RemoteDataStoreFactory();

                        _rtpisDataStore = new RTPISDataStore();

                        _requestProcessor = new RequestProcessor(
                            _t2gManager,
                            _rtpisDataStore);

                        _initializationCount = 1;
                    }
                    catch (System.Exception e)
                    {
                        Uninitialize(true);
                        LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.RealTime.RealTimeService.Initialize", e, EventIdEnum.RealTime);
                    }
                }
                else
                {
                    _initializationCount++;
                }
            }
        }
Beispiel #3
0
        /// <summary>Initializes this object.</summary>
        /// <param name="instance">The instance that create this object</param>
        /// <param name="t2gManager">The manager to interact with T2G application.</param>
        /// <param name="sessionManager">Manager for session.</param>
        /// <param name="notificationSender">The object to use to send notifications.</param>
        /// <param name="requestProcessor">The request processor instance.</param>
        /// <param name="remoteDataStoreFactory">The remote data store factory.</param>
        /// <param name="rtpisDataStore">The rtpis data store.</param>
        private static void Initialize(
            RealTimeService instance,
            IT2GManager t2gManager,
            ISessionManagerExtended sessionManager,
            INotificationSender notificationSender,
            IRequestProcessor requestProcessor,
            IRemoteDataStoreFactory remoteDataStoreFactory,
            IRTPISDataStore rtpisDataStore)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            if (t2gManager == null)
            {
                throw new ArgumentNullException("t2gManager");
            }
            if (sessionManager == null)
            {
                throw new ArgumentNullException("sessionManager");
            }

            if (notificationSender == null)
            {
                throw new ArgumentNullException("notificationSender");
            }

            if (requestProcessor == null)
            {
                throw new ArgumentNullException("requestProcessor");
            }

            if (remoteDataStoreFactory == null)
            {
                throw new ArgumentNullException("remoteDataStoreFactory");
            }

            if (rtpisDataStore == null)
            {
                throw new ArgumentNullException("rtpisDataStore");
            }

            lock (_initializationLock)
            {
                try
                {
                    if (_initializationCount != 0)
                    {
                        Uninitialize(true);
                    }

                    RealTimeService._instanceCreator        = instance;
                    RealTimeService._t2gManager             = t2gManager;
                    RealTimeService._sessionManager         = sessionManager;
                    RealTimeService._notificationSender     = notificationSender;
                    RealTimeService._remoteDataStoreFactory = remoteDataStoreFactory;
                    RealTimeService._rtpisDataStore         = rtpisDataStore;
                    RealTimeService._requestProcessor       = requestProcessor;

                    _initializationCount++;
                }
                catch (System.Exception e)
                {
                    Uninitialize(true);
                    LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.RealTime.RealTimeService.Initialize", e, EventIdEnum.RealTime);
                }
            }
        }
Beispiel #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);
                }
            }
        }