/// <summary>Updates from data described by src.</summary>
 /// <param name="src">Source for the update.</param>
 public void UpdateFrom(RealTimeStationInformationType src)
 {
     if (src != null)
     {
         if (string.Compare(this.StationCode, src.StationCode) == 0)
         {
             this.StationData = (src.StationData != null) ? src.StationData.Clone() : null;
             SetUpdateDate(DateTime.Now);
         }
     }
 }
        /// <summary>Initializes a new instance of the RealTimeStationStatusType class.</summary>
        /// <param name="src">RealTimeStationInformationType to copy data from.</param>
        public RealTimeStationStatusType(RealTimeStationInformationType src)
        {
            if (src != null)
            {
                this.StationID = src.StationCode;

                if (src.StationData != null && !(src.StationData.StationDelay == null && src.StationData.StationPlatform == null &&
                                                 src.StationData.StationConnectionList == null && src.StationData.StationWeather == null))
                {
                    this.StationDelay          = src.StationData.StationDelay;
                    this.StationPlatform       = src.StationData.StationPlatform;
                    this.StationConnectionList = src.StationData.StationConnectionList;
                    this.StationWeather        = src.StationData.StationWeather;
                    this.StationResult         = RealTimeStationResultEnum.DataOk;
                }
                else
                {
                    this.StationResult = RealTimeStationResultEnum.InfoNoData;
                }
            }
        }
        /// <summary>Sets station real time information.</summary>
        /// <param name="missionCode">The mission code.</param>
        /// <param name="stationInformationList">List of station informations.</param>
        /// <param name="stationResultList">[out] List of station results.</param>
        void IRTPISDataStore.SetStationRealTimeInformation(string missionCode, List <RealTimeStationInformationType> stationInformationList, out List <RealTimeStationResultType> stationResultList)
        {
            bool dataUpdated = false;

            stationResultList = new List <RealTimeStationResultType>();

            if (!string.IsNullOrEmpty(missionCode) && stationInformationList != null && stationInformationList.Count > 0)
            {
                KeyValuePair <string, List <string> > stationUpdateList = new KeyValuePair <string, List <string> >(missionCode, new List <string>());

                lock (_stationData)
                {
                    foreach (var stationInfo in stationInformationList)
                    {
                        if (stationInfo != null)
                        {
                            RealTimeStationResultType      stationUpdate   = null;
                            RealTimeStationInformationType stationInfoType = null;

                            try
                            {
                                stationInfoType = _stationData[missionCode].Find(x => x.StationCode == stationInfo.StationCode);
                                if (stationInfoType != null)
                                {
                                    _stationData[missionCode].Remove(stationInfoType);
                                    stationInfoType.UpdateFrom(stationInfo);
                                }
                                else
                                {
                                    stationInfoType = stationInfo;
                                    stationInfoType.SetUpdateDate(DateTime.Now);
                                }
                            }
                            catch (KeyNotFoundException)
                            {
                                // key not found, we will use the newly created instance
                                _stationData.Add(missionCode, new List <RealTimeStationInformationType>());
                                stationInfoType = stationInfo;
                                stationInfoType.SetUpdateDate(DateTime.Now);
                            }

                            stationUpdate = new RealTimeStationResultType()
                            {
                                StationID = stationInfoType.StationCode
                            };

                            if (stationInfoType != null)
                            {
                                if (stationInfo.StationData != null)
                                {
                                    if (stationInfo.StationData.StationDelay != null)
                                    {
                                        stationUpdate.DelayResult = RealTimeStationResultEnum.DataOk;
                                    }
                                    else
                                    {
                                        stationUpdate.DelayResult = RealTimeStationResultEnum.InfoNoData;
                                    }

                                    if (stationInfo.StationData.StationPlatform != null)
                                    {
                                        stationUpdate.PlatformResult = RealTimeStationResultEnum.DataOk;
                                    }
                                    else
                                    {
                                        stationUpdate.PlatformResult = RealTimeStationResultEnum.InfoNoData;
                                    }

                                    if (stationInfo.StationData.StationWeather != null)
                                    {
                                        stationUpdate.WeatherResult = RealTimeStationResultEnum.DataOk;
                                    }
                                    else
                                    {
                                        stationUpdate.WeatherResult = RealTimeStationResultEnum.InfoNoData;
                                    }

                                    if (stationInfo.StationData.StationConnectionList != null)
                                    {
                                        stationUpdate.ConnectionsResultList = new List <RealTimeConnectionResultType>();

                                        foreach (var connectionData in stationInfoType.StationData.StationConnectionList)
                                        {
                                            stationUpdate.ConnectionsResultList.Add(new RealTimeConnectionResultType()
                                            {
                                                Operator         = connectionData.Operator,
                                                CommercialNumber = connectionData.CommercialNumber,
                                                ConnectionResult = RealTimeStationResultEnum.InfoNoData
                                            });
                                        }

                                        foreach (var connectionData in stationInfo.StationData.StationConnectionList)
                                        {
                                            if (connectionData != null)
                                            {
                                                var connection = stationUpdate.ConnectionsResultList.Find(x => string.Compare(x.Operator, connectionData.Operator) == 0 && string.Compare(x.CommercialNumber, connectionData.CommercialNumber) == 0);
                                                if (connection != null)
                                                {
                                                    stationUpdate.ConnectionsResultList.Remove(connection);
                                                }

                                                stationUpdate.ConnectionsResultList.Add(new RealTimeConnectionResultType()
                                                {
                                                    Operator         = connectionData.Operator,
                                                    CommercialNumber = connectionData.CommercialNumber,
                                                    ConnectionResult = RealTimeStationResultEnum.DataOk
                                                });
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    stationUpdate.DelayResult           = RealTimeStationResultEnum.InfoNoData;
                                    stationUpdate.PlatformResult        = RealTimeStationResultEnum.InfoNoData;
                                    stationUpdate.WeatherResult         = RealTimeStationResultEnum.InfoNoData;
                                    stationUpdate.ConnectionsResultList = null;
                                }

                                _stationData[missionCode].Add(stationInfoType);
                                stationUpdateList.Value.Add(stationUpdate.StationID);
                                stationResultList.Add(stationUpdate);
                                dataUpdated = true;
                            }
                        }
                    }

                    ///Call event
                    if (dataUpdated)
                    {
                        OnChanged(new RTPISDataStoreEventArgs(null, stationUpdateList));
                    }
                }
            }
        }