Ejemplo n.º 1
0
 /// <summary>
 /// The JourneyRequest has completed its web request. Extract the departure time for the first journey and update the saved
 /// departure time if it has changed.
 /// If there was a network problem or the request was cancelled then leave the saved departure time as it is.
 /// If no journeys were found then leave  the saved departure time as it is.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void JourneysAvailable(object sender, JourneyRequest.JourneysAvailableArgs args)
 {
     if (args.JourneysAvailable == true)
     {
         // Extract the next departure time from the returned list and report any changes
         ReportNextDepartureChanges.ReportTimeChanges(MarkJourneyDateChanges(trainJourneyRequest.Journeys, requestDate));
     }
     else if (args.NetworkProblem == true)
     {
         // If there has been a network problem then mark the stored departure time as suspect
         ReportNextDepartureChanges.ReportSuspectStateChanges(true);
     }
     else if (args.RequestCancelled == true)
     {
         // If the request has been cancelled don't update the stored value last retrieved
     }
     else
     {
         // No journeys have been retieved then mark the next departure value as suspect
         ReportNextDepartureChanges.ReportSuspectStateChanges(true);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// The JourneyRequest has completed its web request.
        /// If there was a network problem or the request was cancelled then leave the current set of journeys as they are.
        /// If some journeys were found and this was a new request or an update then replace the current request with the new results.
        /// If this was a request for more journeys then add the returned journeys to the existing set.
        /// If no journeys were found then clear the existing results.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void JourneysAvailable(object sender, JourneyRequest.JourneysAvailableArgs args)
        {
            if (args.JourneysAvailable == true)
            {
                // Some new journeys have been received. If this is a new request then any existing entries can now be cleared.
                // If this is an update request, and it is the first reply received for the update then also clear the existing entries
                if ((currentRequest == RequestType.NewRequest) || ((currentRequest == RequestType.Update) && (updateCount == 0)))
                {
                    retrievedJourneys.Journeys.Clear();
                }

                // Add the new entries to the existing journeys
                // First of all check that the first entry of the new entries is not the same as the last entry of the old entries
                if (((retrievedJourneys.Journeys.Count > 0) && (trainJourneyRequest.Journeys.Count > 0)) &&
                    (retrievedJourneys.Journeys[retrievedJourneys.Journeys.Count - 1].DepartureDateTime == trainJourneyRequest.Journeys[0].DepartureDateTime))
                {
                    // Remove the first entry
                    trainJourneyRequest.Journeys.RemoveAt(0);
                }

                retrievedJourneys.Journeys.AddRange(MarkJourneyDateChanges(trainJourneyRequest.Journeys, requestDate));

                // If this is an update request check if sufficient journeys have been obtained
                if (currentRequest == RequestType.Update)
                {
                    // Report the results back just to let the user know that some results have been obtained
                    JourneyResponse?.JourneysAvailable(retrievedJourneys);

                    updateCount = retrievedJourneys.Journeys.Count;
                    if (updateCount >= updateTarget)
                    {
                        // Request finished
                        JourneyResponse?.JourneyRequestComplete(false, false);
                        currentRequest = RequestType.Idle;
                    }
                    else
                    {
                        // Make the request for one minute from the last time
                        MakeRequestAfterSpecifiedTime(retrievedJourneys.Journeys[retrievedJourneys.Journeys.Count - 1].DepartureDateTime);
                    }
                }
                else
                {
                    // Report back
                    JourneyResponse?.JourneysAvailable(retrievedJourneys);

                    // Extract the next departure time from the returned list and report any changes
                    ReportNextDepartureChanges.ReportTimeChanges(retrievedJourneys.Journeys);

                    // Request finished
                    JourneyResponse?.JourneyRequestComplete(false, false);
                    currentRequest = RequestType.Idle;
                }
            }
            else if (args.NetworkProblem == true)
            {
                // Update the next departure time status
                ReportNextDepartureChanges.ReportSuspectStateChanges(true);

                JourneyResponse?.JourneyRequestComplete(true, false);
                currentRequest = RequestType.Idle;
            }
            else if (args.RequestCancelled == true)
            {
                JourneyResponse?.JourneyRequestComplete(false, false);
                currentRequest = RequestType.Idle;
            }
            else
            {
                ClearJourneys();

                // Update the next departure time status
                ReportNextDepartureChanges.ReportSuspectStateChanges(true);

                JourneyResponse?.JourneyRequestComplete(false, true);
                currentRequest = RequestType.Idle;
            }
        }