Esempio n. 1
0
        /// ************************************************************************************************
        /// <summary>
        /// Build departureDataSourse from departureResponse for now
        /// </summary>
        /// <param name="deserializedDepartures"></param>
        /// <param name="preparedDepartureCollection"></param>
        /// <returns>Hash code for departure response</returns>
        private void BuildDepartureDataSource(DateTime now, DeserializedDepartures[] deserializedDepartures, ObservableCollection <PreparedDeparture> preparedDepartures)
        {
            preparedDepartures.Clear();

            if (connectionStatus == ConnectionState.NOT_CONNECTED)
            {
                AddHeaderToDepartureDataSource(preparedDepartures, empty: true);
                preparedDepartures.Add(SetServiceMessage(Common.WarnMessageType[MessageType.NoConnection], Common.Messages[MessageType.NoConnection]));
            }
            else
            {
                if (connectionStatus == ConnectionState.JUST_STARTED && (deserializedDepartures == null || (deserializedDepartures != null && deserializedDepartures.Length == 0)))
                {
                    AddHeaderToDepartureDataSource(preparedDepartures, empty: true);
                    preparedDepartures.Add(SetServiceMessage(Common.WarnMessageType[MessageType.Waiting], Common.Messages[MessageType.Waiting]));
                }
                else
                {
                    AddHeaderToDepartureDataSource(preparedDepartures, empty: false);

                    if (connectionStatus == ConnectionState.LONG_DISCONNECT)
                    {
                        preparedDepartures.Add(SetServiceMessage(Common.WarnMessageType[MessageType.NoConnection], Common.Messages[MessageType.NoConnection]));
                        preparedDepartures.Add(SetServiceMessage(Common.WarnMessageType[MessageType.Warning], Common.Messages[MessageType.Warning]));
                    }
                    if (deserializedDepartures != null)
                    {
                        foreach (DeserializedDepartures dp in deserializedDepartures)
                        {
                            // Don't include cancelled lines into data source for visualization
                            if (!dp.cancelled)
                            {
                                Common.GetTimes(now, dp.departureTime, dp.delay, out DateTime actualTime, out _, out TimeSpan difference);

                                PreparedDeparture fd = new PreparedDeparture
                                {
                                    Product             = dp.product,
                                    Label               = dp.label,
                                    Destination         = dp.destination,
                                    Platform            = dp.platform,
                                    Station             = StationName,
                                    LineBackgroundColor = dp.lineBackgroundColor,
                                    MinutesToDeparture  = BuildMinutesToDeparture(difference),
                                    DepartureTime       = string.Format(CultureInfo.InvariantCulture, "{0:D2}:{1:D2}", actualTime.Hour, actualTime.Minute),
                                    FontSize            = TableFontSize.ToString(CultureInfo.InvariantCulture),
                                    Sev        = dp.sev,
                                    Delay      = dp.delay.ToString(),
                                    FontFamily = TableFontFamily
                                };

                                preparedDepartures.Add(fd);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// ************************************************************************************************
        /// <summary>
        /// Sets Service Message as PreparedDeparture
        /// </summary>
        /// <param name="type">Type of the Service Message</param>
        /// <param name="message">Service message</param>
        /// <returns>Prepared departure with Service Message</returns>
        private PreparedDeparture SetServiceMessage(string type, string message)
        {
            PreparedDeparture fd = new PreparedDeparture
            {
                DepartureTime      = "",
                Label              = "",
                MinutesToDeparture = "",
                Product            = type,
                Destination        = message,
                FontSize           = TableFontSize.ToString(CultureInfo.InvariantCulture)
            };

            return(fd);
        }