Exemplo n.º 1
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();

            // TODO: Save application state and stop any background activity
            await SuspensionManager.SaveAsync();

            // save app's data
            AppDataManager.SaveTickets(MainPage.tickets);
            AppDataManager.SaveRequests(MainPage.requests);

            deferral.Complete();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // TODO: Prepare page for display here.

            // TODO: If your application contains multiple pages, ensure that you are
            // handling the hardware Back button by registering for the
            // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
            // If you are using the NavigationHelper provided by some templates,
            // this event is handled for you.
            navigationHelper.OnNavigatedTo(e);

            ticketsList.DataContext = null;
            ticketsList.DataContext = tickets;
            AppDataManager.SaveTickets(tickets);

            requestsList.DataContext = null;
            requestsList.DataContext = requests;
            AppDataManager.SaveRequests(requests);

            Notification.ClearBadge();
        }
        private static async Task checkRequestsAsyncHelper()
        {
            IEnumerable <Request> requests = AppDataManager.RetrieveRequests();
            int addedForRequests           = 0;

            try
            {
                foreach (Request req in requests)
                {
                    bool         found    = false;
                    TrainRequest trainReq = new TrainRequest()
                    {
                        from      = req.from,
                        to        = req.to,
                        date      = req.depDateFrame.since,
                        time      = req.depTimeFrame.since,
                        roundTrip = false
                    };
                    TrainResponse trainResp;
                    try
                    {
                        trainResp = Factory.Instance.getTrainResponse(
                            await Requests.makeRequestAsync(Requests.TRAIN_URL, trainReq.getParameters()));
                    }
                    catch (Exception) { continue; }
                    foreach (Train train in trainResp.Trains)
                    {
                        int available = 0;
                        foreach (CoachType type in train.CoachTypes)
                        {
                            try
                            {
                                CoachResponse coachResp = Factory.Instance.getCoachResponse(
                                    await Requests.makeRequestAsync(Requests.COACH_URL, train.getParameters(type, false)));
                                foreach (Coach coach in coachResp.Wrapper.Coaches)
                                {
                                    CarriageResponse carResp = Factory.Instance.getCarriageResponse(
                                        await Requests.makeRequestAsync(Requests.CARRIAGE_URL, train.getParameters(coach)));

                                    available += countAvailavle(req, train, type, coach, carResp.Value.Places);
                                }
                            }
                            catch (Exception) { }
                        }

                        if (!req.available.ContainsKey(train.Number))
                        {
                            req.available[train.Number] = 0;
                        }
                        if (available > req.available[train.Number] + 1)
                        {
                            Notification.SendToast(
                                "З'явилось " + (available - req.available[train.Number]) + " місць",
                                train.Number + " " + req.from.Name + " - " + req.to.Name + ", " + train.From.Date,
                                DateTimeOffset.Now.AddSeconds(15),
                                "UZTracer.TrainPage?" + JsonConvert.SerializeObject(train));

                            found = true;
                        }
                        req.available[train.Number] = available;
                    }
                    addedForRequests += found ? 1 : 0;
                }
            }
            catch (Exception) { }
            finally
            {
                Notification.UpdateBadge(addedForRequests);
                AppDataManager.SaveRequests(requests);
            }
        }