/// <summary>Process Service Notification.</summary>
        /// <param name="systemId">system id.</param>
        /// <param name="isSystemOnline">is system online.</param>
        /// <param name="subscriptionId">service subscription id.</param>
        /// <param name="serviceList">list of services.</param>
        public void OnServiceNotification(string systemId, bool isSystemOnline, int subscriptionId, serviceStruct[] serviceList)
        {
            lock (_lock)
            {
                // This notification is sent by T2G for a single subscription, i.e. for a specific service ID. The list is not the
                // complete list of services on a train, it is a list of services with the same service ID. T2G supports multiple
                // services with the same ID present on a train, but PIS ground uses only those services that can only have one
                // instance on a given train.

                if (!string.IsNullOrEmpty(systemId))
                {
                    ServiceInfoList services = T2GDataConverter.BuildServiceList(serviceList);

                    if (services != null)
                    {
                        _localDataStorage.OnServiceChanged(systemId, isSystemOnline, subscriptionId, services);

                        ElementEventArgs elementEventArgs = _localDataStorage.BuildElementInfoChangedEvent(systemId);

                        if (elementEventArgs != null)
                        {
                            _notifierTarget.RaiseOnElementInfoChangeEvent(elementEventArgs);
                        }
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 查询获取服务信息数据到本地
 /// </summary>
 /// <returns></returns>
 public List <ServiceInfo> GetDataList()
 {
     if (ServiceInfoList != null && ServiceInfoList.Any())
     {
         return(ServiceInfoList);
     }
     ServiceInfoList = serviceInfoDataProvider.GetData(1);
     return(ServiceInfoList);
 }
Пример #3
0
        /// <summary>To Get the Service Information.</summary>
        /// <param name="strSystemId">System Id.</param>
        /// <returns>ServiceInfo Data.</returns>
        internal ServiceInfoList GetAvailableServiceData(string systemId)
        {
            ServiceInfoList serviceList = null;

            if (!string.IsNullOrEmpty(systemId))
            {
                lock (_systemListLock)
                {
                    SystemInfo system;
                    if (_systemList.TryGetValue(systemId, out system))
                    {
                        // Copy immutable list ref is ok, keep same references
                        serviceList = system.ServiceList;
                    }
                }
            }

            return(serviceList ?? ServiceInfoList.Empty);
        }
Пример #4
0
        /// <summary>Executes the service changed action.</summary>
        /// <param name="systemId">System id.</param>
        /// <param name="isSystemOnline">True if this object is system online.</param>
        /// <param name="subscriptionId">Identifier for the subscription.</param>
        /// <param name="services">Services that changed.</param>
        /// <returns>true if internal data changed, false otherwise.</returns>
        internal bool OnServiceChanged(string systemId, bool isSystemOnline, int subscriptionId, ServiceInfoList services)
        {
            bool updated = false;

            if (!string.IsNullOrEmpty(systemId) && services != null)
            {
                if (LogManager.IsTraceActive(TraceType.INFO))
                {
                    string message = String.Format(
                        "OnServiceChanged called, systemId={0}, isSystemOnline={1}, subscriptionId={2}, service={3}",
                        systemId, isSystemOnline, subscriptionId, services.Count != 0 ? services[0].ServiceName : "N/A");

                    LogManager.WriteLog(TraceType.INFO, message, "Ground.Core.T2G.T2GNotificationProcessor.OnServiceNotification", null, EventIdEnum.GroundCore);
                }

                bool systemExists;
                lock (_systemListLock)
                {
                    SystemInfo foundSystem;
                    systemExists = _systemList.TryGetValue(systemId, out foundSystem);
                    if (systemExists)
                    {
                        if (foundSystem.IsOnline != isSystemOnline)
                        {
                            // This info is mainly updated in GetSystemList (initially) or OnSystemChanged (after), but
                            // we might as well update it here, since it is returned along with the service list.
                            SystemInfo updatedSystemInfo = new SystemInfo(
                                foundSystem.SystemId,
                                foundSystem.MissionId,
                                foundSystem.VehiclePhysicalId,
                                foundSystem.Status,
                                isSystemOnline,
                                foundSystem.CommunicationLink,
                                foundSystem.ServiceList,
                                foundSystem.PisBaseline,
                                foundSystem.PisVersion,
                                foundSystem.PisMission,
                                foundSystem.IsPisBaselineUpToDate && isSystemOnline);

                            _systemList[foundSystem.SystemId] = updatedSystemInfo;
                            updated = true;
                        }
                    }
                }

                if (systemExists)
                {
                    updated |= UpdateServiceList(systemId, subscriptionId, services);
                }
            }

            DumpCurrentSystemList(TraceType.DEBUG, "After OnServiceListChanged called:", "PIS.Ground.Core.T2G.LocalDataStorage.OnServiceListChanged");
            return(updated);
        }
Пример #5
0
        /// <summary>
        /// Update service list
        /// </summary>
        /// <param name="systemId">Identifier for the system.</param>
        /// <param name="subscriptionId">Notification subscription identifier</param>
        /// <param name="updatedServices">The updated services.</param>
        /// <returns>true if the system has been updated, false otherwise.</returns>
        private bool UpdateServiceList(string systemId, int subscriptionId, ServiceInfoList updatedServices)
        {
            bool listUpdated = false;

            if (LogManager.IsTraceActive(TraceType.INFO))
            {
                string context = string.Format(CultureInfo.CurrentCulture, "{0} of service {1}", "PIS.Ground.Core.T2G.LocalDataStorage.UpdateServiceList", ServiceConfiguration.RunningServiceName);
                LogManager.WriteLog(TraceType.INFO, "Updating service list for systemId=" + systemId, context, null, EventIdEnum.GroundCore);
            }

            try
            {
                ushort subscriptionServiceId = 0;
                lock (_subscriptionAssociationsLock)
                {
                    if (!_associationSubscriptionIdWithServiceId.TryGetValue(subscriptionId, out subscriptionServiceId) && updatedServices.Count != 0)
                    {
                        _associationSubscriptionIdWithServiceId[subscriptionId] = updatedServices[0].ServiceId;
                    }
                }

                lock (_systemListLock)
                {
                    SystemInfo existingSystemInfo;
                    // System is know. Update possible.
                    if (_systemList.TryGetValue(systemId, out existingSystemInfo))
                    {
                        List <ServiceInfo> updatedList = null;

                        // If the array is empty, this mean that we shall remove all services. Later, T2G will send an update.
                        if (updatedServices.Count == 0)
                        {
                            // If serviceId is 0, this means that no mapping existing between the subscription id and the service id.
                            if (subscriptionServiceId != 0)
                            {
                                updatedList = existingSystemInfo.ServiceList.Where(s => s.ServiceId != subscriptionServiceId).ToList();
                                listUpdated = updatedList.Count != existingSystemInfo.ServiceList.Count;
                            }
                        }
                        else
                        {
                            updatedList = new List <ServiceInfo>(existingSystemInfo.ServiceList);

                            foreach (ServiceInfo service in updatedServices)
                            {
                                if (_filterLocalServiceOnly)
                                {
                                    if (service.VehiclePhysicalId != existingSystemInfo.VehiclePhysicalId)
                                    {
                                        continue;
                                    }
                                }

                                int insertIndex = updatedList.FindIndex(i => i.VehiclePhysicalId == service.VehiclePhysicalId &&
                                                                        i.ServiceId == service.ServiceId &&
                                                                        i.ServicePortNumber == service.ServicePortNumber &&
                                                                        i.ServiceIPAddress == service.ServiceIPAddress);

                                if (insertIndex < 0)
                                {
                                    updatedList.Add(service);
                                    listUpdated = true;
                                }
                                else if (!service.Equals(updatedList[insertIndex]))
                                {
                                    updatedList[insertIndex] = service;
                                    listUpdated = true;
                                }
                            }

                            if (listUpdated)
                            {
                                // Service list shall be sorted
                                System.Comparison <ServiceInfo> comparer = (ServiceInfo x, ServiceInfo y) => CompareServiceInfo(x, y, existingSystemInfo.VehiclePhysicalId);
                                updatedList.Sort(comparer);
                            }
                        }

                        if (listUpdated)
                        {
                            // Add updated info
                            SystemInfo updatedSystemInfo = new SystemInfo(
                                existingSystemInfo.SystemId,
                                existingSystemInfo.MissionId,
                                existingSystemInfo.VehiclePhysicalId,
                                existingSystemInfo.Status,
                                existingSystemInfo.IsOnline,
                                existingSystemInfo.CommunicationLink,
                                new ServiceInfoList(updatedList),
                                existingSystemInfo.PisBaseline,
                                existingSystemInfo.PisVersion,
                                existingSystemInfo.PisMission,
                                existingSystemInfo.IsPisBaselineUpToDate && existingSystemInfo.IsOnline);

                            _systemList[existingSystemInfo.SystemId] = updatedSystemInfo;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string context = string.Format(CultureInfo.CurrentCulture, "{0} of service {1}", "PIS.Ground.Core.T2G.LocalDataStorage.UpdateServiceList", ServiceConfiguration.RunningServiceName);
                LogManager.WriteLog(TraceType.ERROR, ex.Message, context, ex, EventIdEnum.GroundCore);
            }

            return(listUpdated);
        }