public DepartureBoard(DepartureBoardResponse departureBoardResponseModel)
 {
     DateTime.TryParseExact(string.Format("{0} {1}", departureBoardResponseModel.ServerDate, departureBoardResponseModel.ServerTime), "yyyy-MM-dd HH:mm", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedDt);
     BoardDateTime        = parsedDt;
     ErrorMessage         = departureBoardResponseModel.Error;
     ErrorMessageDetailed = departureBoardResponseModel.ErrorText;
     Departures           = departureBoardResponseModel.Departures?.Select(departureRm => new Departure(departureRm));
 }
Beispiel #2
0
        public DepartureBoardResultsWindow(DepartureBoardResponse dbReponse, string title, DateTime dateTime, bool isStationInfo, DockContent win = null) : this(isStationInfo, win)
        {
            Results = dbReponse;

            Text = $"{ Settings.Localization.Departures } ({ dbReponse.Departures.Count }) - { title } - { dateTime.ToShortTimeString() } { dateTime.ToShortDateString() }";

            resultsWebBrowser.DocumentText = dbReponse.TransformToHtml(Settings.DepartureBoardSimpleXslt.FullName, Settings.DepartureBoardSimpleCss.FullName, Settings.OnLoadActionsJavaScript.FullName);
        }
Beispiel #3
0
        public DepartureBoardResultsWindow(Departure departure, bool isStationInfo, DockContent win = null) : this(isStationInfo, win)
        {
            Results = new DepartureBoardResponse(new List <Departure> {
                departure
            });

            Text = $"{ Settings.Localization.Departure } - { (isStationInfo ? DataFeedDesktop.Basic.Stops.FindByIndex(departure.StopID).Name : departure.LineLabel) } - { departure.DepartureDateTime.ToShortTimeString() } { departure.DepartureDateTime.ToShortDateString() }";

            resultsWebBrowser.DocumentText = Results.Departures[0].TransformToHtml(Settings.DepartureBoardDetailXslt.FullName, Settings.DepartureBoardDetailCss.FullName, Settings.OnLoadActionsJavaScript.FullName);
        }
Beispiel #4
0
        private static async Task <DepartureBoardResponse> SendDepartureBoardRequestAsync(LineInfoRequest dbRequest, bool forceCache = false)
        {
            DepartureBoardResponse dbResponse = null;

            using (var dbProcessing = new DepartureBoardProcessing())
            {
                var cached = LineInfoCached.Select(dbRequest.RouteInfoID);

                if (cached == null || (cached.ShouldBeUpdated || forceCache))
                {
                    try
                    {
                        if (!await CheckBasicDataValidity())
                        {
                            var results = cached?.FindResultsSatisfyingRequest(dbRequest);
                            return(results?.Departures.Count == 0 ? null : results);
                        }

                        // Process the request immediately so the user does not have to wait until the caching is completed.

                        dbResponse = await dbProcessing.ProcessAsync(dbRequest, dbRequest.Count == -1?int.MaxValue : Settings.TimeoutDuration);

                        // Then update the cache.

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                        if (cached != null && cached.ShouldBeUpdated && dbRequest.Count != -1 && CanBeCached)
                        {
                            Task.Run(async() => cached.UpdateCache(await dbProcessing.ProcessAsync(cached.ConstructNewRequest(), int.MaxValue)));
                        }
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    }
                    catch (System.Net.WebException)
                    {
                        PlatformDependentSettings.ShowMessage(Settings.Localization.UnreachableHost);
                    }
                }

                else
                {
                    dbResponse = cached?.FindResultsSatisfyingRequest(dbRequest);
                    if (dbResponse?.Departures.Count == 0)
                    {
                        dbResponse = await dbProcessing.ProcessAsync(dbRequest, Settings.TimeoutDuration);
                    }
                }
            }

            return(dbResponse);
        }
Beispiel #5
0
        /// <summary>
        /// Processes the request async.
        /// </summary>
        public async override Task ProcessAsync()
        {
            try
            {
                DepartureBoardRequest dbRequest = await Receive <DepartureBoardRequest>();

                Logging.Log($"Received departure board request from { ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString() }. Data: { dbRequest.ToString() }");

                DepartureBoardResponse dbRes = null;

                await Task.Run(() =>
                {
                    if (dbRequest is StationInfoRequest)
                    {
                        using (var dbProcessing = new Interop.DepartureBoardManaged(DataFeed.Full, (StationInfoRequest)dbRequest))
                        {
                            dbProcessing.ObtainDepartureBoard();
                            dbRes = dbProcessing.ShowDepartureBoard();
                        }
                    }
                    else if (dbRequest is LineInfoRequest)
                    {
                        using (var dbProcessing = new Interop.DepartureBoardManaged(DataFeed.Full, (LineInfoRequest)dbRequest))
                        {
                            dbProcessing.ObtainDepartureBoard();
                            dbRes = dbProcessing.ShowDepartureBoard();
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                });

                Send(dbRes);

                Logging.Log($"Departure board response to { ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString() } was successfully send.");
            }
            catch (Exception ex)
            {
                Logging.Log($"Departure board request from { ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString() } could not be processed. { Logging.LogException(ex) }");
            }
            Dispose();
        }
Beispiel #6
0
        public DepartureBoardResultsPage(DepartureBoardResponse res, bool stationInfo, string name)
        {
            InitializeComponent();

            Title = (stationInfo ? Settings.Localization.Station : Settings.Localization.Line) + " " + name;

            Response = res;

            resultsWebView.Scripting = new DepartureBoardScripting(resultsWebView, this);

            resultsWebView.Source = new HtmlWebViewSource
            {
                Html = Response.TransformToHtml(
                    PlatformDependentSettings.GetStream(Settings.DepartureBoardSimpleXslt),
                    PlatformDependentSettings.GetStream(Settings.DepartureBoardSimpleCss),
                    PlatformDependentSettings.GetStream(Settings.OnLoadActionsJavaScript)
                    )
            };
        }
Beispiel #7
0
        public DepartureBoardResultsPage(Departure dep)
        {
            InitializeComponent();

            Title = Settings.Localization.Departure + " " + dep.Headsign;

            Response = new DepartureBoardResponse(new List <Departure> {
                dep
            });

            resultsWebView.Scripting = new DepartureBoardScripting(resultsWebView, this);

            resultsWebView.Source = new HtmlWebViewSource
            {
                Html = Response.Departures[0].TransformToHtml(
                    PlatformDependentSettings.GetStream(Settings.DepartureBoardDetailXslt),
                    PlatformDependentSettings.GetStream(Settings.DepartureBoardDetailCss),
                    PlatformDependentSettings.GetStream(Settings.OnLoadActionsJavaScript)
                    )
            };
        }
Beispiel #8
0
        private static async Task <DepartureBoardResponse> SendDepartureBoardRequestAsync(StationInfoRequest dbRequest, bool forceCache = false)
        {
            DepartureBoardResponse dbResponse = null;

            if (DataFeedDesktop.OfflineMode)
            {
                await Task.Run(() =>
                {
                    using (var dbProcessing = new Interop.DepartureBoardManaged(DataFeedDesktop.Full, dbRequest))
                    {
                        dbProcessing.ObtainDepartureBoard();
                        dbResponse = dbProcessing.ShowDepartureBoard();
                    }
                });
            }

            else
            {
                using (var dbProcessing = new DepartureBoardProcessing())
                {
                    var cached = StationInfoCached.Select(dbRequest.StopID);

                    if (cached == null || (cached.ShouldBeUpdated || forceCache))
                    {
                        try
                        {
                            if (!await CheckBasicDataValidity())
                            {
                                var results = cached?.FindResultsSatisfyingRequest(dbRequest);
                                return(results?.Departures.Count == 0 ? null : results);
                            }

                            // Process the request immediately so the user does not have to wait until the caching is completed.

                            dbResponse = await dbProcessing.ProcessAsync(dbRequest, dbRequest.Count == -1?int.MaxValue : Settings.TimeoutDuration);

                            // Then update the cache.

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                            if (cached != null && cached.ShouldBeUpdated && dbRequest.Count != -1)
                            {
                                Task.Run(async() => cached.UpdateCache(await dbProcessing.ProcessAsync(cached.ConstructNewRequest(), int.MaxValue)));
                            }
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                        }
                        catch (System.Net.WebException)
                        {
                            MessageBox.Show(Settings.Localization.UnreachableHost, Settings.Localization.Offline, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    else
                    {
                        dbResponse = cached?.FindResultsSatisfyingRequest(dbRequest);
                        if (dbResponse?.Departures.Count == 0)
                        {
                            dbResponse = await dbProcessing.ProcessAsync(dbRequest, Settings.TimeoutDuration);
                        }
                    }
                }
            }
            return(dbResponse);
        }