Ejemplo n.º 1
0
        public void InitializeMissionInvalidMissionCode()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                string.Empty,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidMissionCode, result.ResultCode);
            Assert.AreEqual(requestId, result.RequestId);
            Assert.IsNullOrEmpty(result.MissionCode);
            Assert.IsNull(result.InvalidStationList);
        }
Ejemplo n.º 2
0
        public void InitializeMissionErrorOpeningLMTDb()
        {
            AvailableElementData elementData = InitTrainElement();
            Guid requestId = Guid.NewGuid();

            File.Copy(this._dbSourcePath, Path.Combine(this._dbWorkingPath, "file.db"));

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);
            this._remoteDataStoreFactoryMock.Setup(z => z.GetRemoteDataStoreInstance()).Returns(new RemoteDataStoreSimulator.RemoteDataStore(this._dbWorkingPath, "1.1.1.1"));

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorOpeningLMTDb, result.ResultCode);
            Assert.AreEqual(result.RequestId, requestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Search AvailableElementData By TargetAddress (By Element, MissionOperatorCode, or MissionId)
        /// </summary>
        /// <param name="targetAddress">Target address.</param>
        /// <param name="lstAvailableElementData">[out] Information describing the list available element.</param>
        /// <returns>List of AvailableElementData matching TargetAddress criteria.</returns>
        public T2GManagerErrorEnum GetAvailableElementDataByTargetAddress(TargetAddressType targetAddress, out ElementList <AvailableElementData> lstAvailableElementData)
        {
            T2GManagerErrorEnum lReturn = T2GManagerErrorEnum.eFailed;

            lstAvailableElementData = new ElementList <AvailableElementData>();

            if (targetAddress != null && !string.IsNullOrEmpty(targetAddress.Id))
            {
                // Resolve target elements
                switch (targetAddress.Type)
                {
                case AddressTypeEnum.Element:
                    AvailableElementData element = new AvailableElementData();
                    lReturn = GetAvailableElementDataByElementNumber(targetAddress.Id, out element);
                    if (lReturn == T2GManagerErrorEnum.eSuccess)
                    {
                        lstAvailableElementData.Add(element);
                    }
                    break;

                case AddressTypeEnum.MissionOperatorCode:
                    lReturn = GetAvailableElementDataListByMissionOperatorCode(targetAddress.Id, out lstAvailableElementData);
                    break;

                case AddressTypeEnum.MissionCode:
                    lReturn = GetAvailableElementDataListByMissionCode(targetAddress.Id, out lstAvailableElementData);
                    break;
                }
            }

            return(lReturn);
        }
Ejemplo n.º 4
0
        public void InitializeMissionInvalidSessionId()
        {
            Guid requestId = Guid.NewGuid();
            AvailableElementData elementData = null;

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(false);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                Guid.NewGuid(),
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            this._train2groundClientMock.Verify(a => a.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData), Times.Never());

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidSessionId, result.ResultCode);
            Assert.AreEqual(Guid.Empty, result.RequestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
            Assert.IsNull(result.InvalidStationList);
        }
Ejemplo n.º 5
0
        public void CancelMissionInvalidElementId()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eElementNotFound);

            MissionCancelMissionResult result = this._missionService.CancelMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.Timeout);

            this._train2groundClientMock.Verify(a => a.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData), Times.Once());

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidElementId, result.ResultCode);
            Assert.AreEqual(requestId, result.RequestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
        }
Ejemplo n.º 6
0
        /// <summary>Search AvailableElementData by mission code (aka commercial number).</summary>
        /// <param name="commercialNumber">Mission code (aka commercial number)</param>
        /// <returns>list of found AvailableElementData.</returns>
        internal ElementList <AvailableElementData> GetAvailableElementDataListByMissionCode(string commercialNumber)
        {
            ElementList <AvailableElementData> elementDataList = new ElementList <AvailableElementData>();

            if (!string.IsNullOrEmpty(commercialNumber))
            {
                IList <SystemInfo> systemList;
                lock (_systemListLock)
                {
                    systemList = _systemList.Where(element => (element.Value.PisMission != null && element.Value.PisMission.CommercialNumber == commercialNumber)).Select(e => e.Value).ToList();
                }

                elementDataList.Capacity = systemList.Count;
                foreach (SystemInfo system in systemList)
                {
                    AvailableElementData elementData = T2GDataConverter.BuildAvailableElementData(system);

                    if (elementData != null)
                    {
                        elementDataList.Add(elementData);
                    }
                }
            }

            return(elementDataList);
        }
Ejemplo n.º 7
0
        public void CancelMissionInvalidRequestTimeout()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                50000);

            MissionCancelMissionResult result = this._missionService.CancelMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.Timeout);

            this._sessionManagerMock.Verify(a => a.IsSessionValid(It.IsAny <Guid>()), Times.Never());
            this._sessionManagerMock.Verify(b => b.GenerateRequestID(It.IsAny <Guid>(), out requestId), Times.Never());
            this._train2groundClientMock.Verify(c => c.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData), Times.Never());

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidRequestTimeout, result.ResultCode);
            Assert.AreEqual(Guid.Empty, result.RequestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
        }
Ejemplo n.º 8
0
        /// <summary>Search AvailableElementData By ElementNumber.</summary>
        /// <param name="elementNumber">element number.</param>
        /// <param name="objAvailableElementData">[out] Information describing the object available element.</param>
        /// <returns>The success of the operation. Possible values are:
        /// <list type="table">
        /// <listheader><term>Error code</term><description>Description</description></listheader>
        /// <item><term>T2GManagerErrorEnum.eSuccess</term><description>Queryed element found.</description></item>
        /// <item><term>T2GManagerErrorEnum.eElementNotFound</term><description>Queried element is unknown.</description></item>
        /// <item><term>T2GManagerErrorEnum.eT2GServerOffline</term><description>T2G services are down.</description></item>
        /// </list>
        /// </returns>
        public T2GManagerErrorEnum GetAvailableElementDataByElementNumber(string elementNumber, out AvailableElementData objAvailableElementData)
        {
            if (LogManager.IsTraceActive(TraceType.INFO))
            {
                LogManager.WriteLog(TraceType.INFO, "GetAvailableElementDataByElementNumber called for element '" + elementNumber ?? string.Empty + "'.", "PIS.Ground.Core.T2G.T2GManager.GetAvailableElementDataByElementNumber", null, EventIdEnum.GroundCore);
            }


            T2GManagerErrorEnum result = T2GManagerErrorEnum.eFailed;

            if (T2GServerConnectionStatus)
            {
                AvailableElementData elementData = _localDataStorage.GetAvailableElementDataByElementNumber(elementNumber);

                if (elementData != null)
                {
                    objAvailableElementData = elementData;                     // copy reference

                    result = T2GManagerErrorEnum.eSuccess;
                }
                else
                {
                    objAvailableElementData = new AvailableElementData(); // always return an object
                    result = T2GManagerErrorEnum.eElementNotFound;
                }
            }
            else
            {
                objAvailableElementData = new AvailableElementData(); // always return an object
                result = T2GManagerErrorEnum.eT2GServerOffline;
            }

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>Initialises the train element.</summary>
        /// <returns>An instance of AvailableElementData for testing purpose.</returns>
        private AvailableElementData InitTrainElement()
        {
            AvailableElementData element = new AvailableElementData();

            element.ElementNumber          = "TRAIN-150";
            element.PisBasicPackageVersion = "3.0.13.0";
            element.LmtPackageVersion      = "3.0.13.0";
            element.PisBaselineData        = new PisBaseline();
            element.PisBaselineData.CurrentVersionLmtOut            = "3.0.13.0";
            element.PisBaselineData.CurrentVersionPisBaseOut        = "3.0.13.0";
            element.PisBaselineData.CurrentVersionPisMissionOut     = "3.0.13.0";
            element.PisBaselineData.FutureVersionPisInfotainmentOut = "3.0.13.0";

            element.OnlineStatus = true;

            return(element);
        }
Ejemplo n.º 10
0
        /// <summary>Search AvailableElementData By ElementNumber.</summary>
        /// <param name="elementNumber">element number.</param>
        /// <param name="objAvailableElementData">[out] Information describing the object available element.</param>
        /// <returns>if found return AvailableElementData else null.</returns>
        internal AvailableElementData GetAvailableElementDataByElementNumber(string elementNumber)
        {
            AvailableElementData elementData = null;

            if (!string.IsNullOrEmpty(elementNumber))
            {
                lock (_systemListLock)
                {
                    SystemInfo system;
                    if (_systemList.TryGetValue(elementNumber, out system))
                    {
                        elementData = T2GDataConverter.BuildAvailableElementData(system);
                    }
                }
            }

            return(elementData);
        }
Ejemplo n.º 11
0
        /// <summary>Get all AvailableElementData</summary>
        /// <returns>list of all AvailableElementData.</returns>
        internal ElementList <AvailableElementData> GetAvailableElementDataList()
        {
            ElementList <AvailableElementData> elementDataList = new ElementList <AvailableElementData>();

            lock (_systemListLock)
            {
                elementDataList.Capacity = _systemList.Count;
                foreach (KeyValuePair <string, SystemInfo> system in _systemList)
                {
                    AvailableElementData elementData = T2GDataConverter.BuildAvailableElementData(system.Value);

                    if (elementData != null)
                    {
                        elementDataList.Add(elementData);
                    }
                }
            }

            return(elementDataList);
        }
Ejemplo n.º 12
0
        public void InitializeMissionNewMissionRequestAccepted()
        {
            AvailableElementData elementData = InitTrainElement();
            Guid requestId = Guid.NewGuid();

            File.Copy(this._dbSourcePath, Path.Combine(this._dbWorkingPath, "file.db"));
            List <string> inputStationList = InitStationList(StationListTypeEnum.VALID_ONLY);

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._newMissionCode,
                this._elementId,
                inputStationList,
                1);

            ServiceInfo serviceInfo = this.InitServiceInfo();

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);
            this._remoteDataStoreFactoryMock.Setup(z => z.GetRemoteDataStoreInstance()).Returns(new RemoteDataStoreSimulator.RemoteDataStore(this._dbWorkingPath, "3.0.13.0"));

            T2GManagerErrorEnum rslt = T2GManagerErrorEnum.eSuccess;

            this._train2groundClientMock.Setup(x => x.GetAvailableServiceData(
                                                   missionParams.ElementId,
                                                   (int)eServiceID.eSrvSIF_MissionServer,
                                                   out serviceInfo)).Returns(rslt);

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.RequestAccepted, result.ResultCode);
            Assert.AreEqual(result.RequestId, requestId);
            Assert.AreEqual(result.MissionCode, this._newMissionCode);
        }
Ejemplo n.º 13
0
        /// <summary>Builds available element data.</summary>
        /// <param name="system">The system.</param>
        /// <returns>.</returns>
        internal static AvailableElementData BuildAvailableElementData(SystemInfo system)
        {
            AvailableElementData elementData = null;

            if (system != null)
            {
                elementData = new AvailableElementData();

                elementData.OnlineStatus    = system.IsOnline;
                elementData.PisBaselineData = new PisBaseline(system.PisBaseline);                 // deep copy
                elementData.ElementNumber   = system.SystemId;

                if (system.PisMission != null)
                {
                    elementData.MissionCommercialNumber = system.PisMission.CommercialNumber;
                    elementData.MissionOperatorCode     = system.PisMission.OperatorCode;
                    elementData.MissionState            = system.PisMission.MissionState;
                }
                else
                {
                    elementData.MissionCommercialNumber = string.Empty;
                    elementData.MissionOperatorCode     = string.Empty;
                    elementData.MissionState            = MissionStateEnum.NI;
                }

                if (elementData.PisBaselineData != null)
                {
                    elementData.PisBasicPackageVersion = elementData.PisBaselineData.CurrentVersionPisBaseOut;
                    elementData.LmtPackageVersion      = elementData.PisBaselineData.CurrentVersionLmtOut;
                }
                else
                {
                    elementData.PisBasicPackageVersion = string.Empty;
                    elementData.LmtPackageVersion      = string.Empty;
                }
            }

            return(elementData);
        }
Ejemplo n.º 14
0
        public void CancelMissionRequestAccepted()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            ServiceInfo serviceInfo = this.InitServiceInfo();

            T2GManagerErrorEnum rslt = T2GManagerErrorEnum.eSuccess;

            this._train2groundClientMock.Setup(x => x.GetAvailableServiceData(
                                                   missionParams.ElementId,
                                                   (int)eServiceID.eSrvSIF_MissionServer,
                                                   out serviceInfo)).Returns(rslt);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);
            this._remoteDataStoreFactoryMock.Setup(z => z.GetRemoteDataStoreInstance()).Returns(new RemoteDataStoreSimulator.RemoteDataStore(this._dbWorkingPath, "3.0.13.0"));

            MissionCancelMissionResult result = this._missionService.CancelMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.RequestAccepted, result.ResultCode);
            Assert.AreEqual(result.RequestId, requestId);
            Assert.AreEqual(result.MissionCode, this._existingMissionCode);
        }
Ejemplo n.º 15
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;
                }
            }
        }
Ejemplo n.º 16
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);
                }
            }
        }
Ejemplo n.º 17
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);
        }