예제 #1
0
        private async void FindButtonClicked(object sender, EventArgs e)
        {
            try
            {
                Structures.Basic.RoutesInfoBasic.RouteInfoBasic route = Request.GetRouteInfoFromLabel(lineEntry.Text);

                if (route == null)
                {
                    return;
                }

                var dbRequest = new LineInfoRequest(leavingTimeDatePicker.Date.Add(leavingTimeTimePicker.Time),
                                                    (int)countSlider.Value, route.ID);

                findButton.IsEnabled = false;
                var dbResponse = await Request.SendDepartureBoardRequestAsync(dbRequest);

                findButton.IsEnabled = true;

                if (dbResponse != null)
                {
                    await Navigation.PushAsync(new DepartureBoardResultsPage(dbResponse, false, route.Label), true);
                }
            }
            catch
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Request.CheckBasicDataValidity();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }
예제 #2
0
        /// <summary>
        /// Tries to obtain station info and return window with results.
        /// </summary>
        /// <param name="dt">Datetime.</param>
        /// <param name="count">Number of departures.</param>
        /// <param name="routeLabel">Route label.</param>
        /// <param name="win">Window with request.</param>
        /// <returns>Window with results.</returns>
        public static async Task <DepartureBoardResultsWindow> GetLineInfoWindowAsync(DateTime dt, int count, string routeLabel, NewLineInfoWindow win)
        {
            Structures.Basic.RoutesInfoBasic.RouteInfoBasic route = GetRouteInfoFromLabel(routeLabel);

            if (route == null)
            {
                return(null);
            }

            var dbRequest  = new LineInfoRequest(dt, count, route.ID);
            var dbResponse = await SendDepartureBoardRequestAsync(dbRequest);

            return(dbResponse == null ? null : new DepartureBoardResultsWindow(dbResponse, routeLabel, dt, false, win));
        }
예제 #3
0
 /// <summary>
 /// Caches the departures according to departure board request.
 /// </summary>
 private static async Task <bool> CacheDepartureBoardAsync(LineInfoRequest dbRequest, bool forceCache = false) =>
 LineInfoCached.CacheResults(DataFeedDesktop.Basic.RoutesInfo.FindByIndex(dbRequest.RouteInfoID), DataFeedDesktop.OfflineMode ? new DepartureBoardResponse() : await SendDepartureBoardRequestAsync(dbRequest, forceCache)) != null;
예제 #4
0
        private static async Task <DepartureBoardResponse> SendDepartureBoardRequestAsync(LineInfoRequest 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 = 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)
                            {
                                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);
        }
예제 #5
0
 /// <summary>
 /// Caches the departures according to departure board request.
 /// </summary>
 private static async Task <bool> CacheDepartureBoardAsync(LineInfoRequest dbRequest, bool forceUpdate = false) => CanBeCached?
 LineInfoCached.CacheResults(DataFeedClient.Basic.RoutesInfo.FindByIndex(dbRequest.RouteInfoID), await SendDepartureBoardRequestAsync(dbRequest, forceUpdate)) != null : false;