Esempio n. 1
0
        public override bool OnStartJob(JobParameters @params)
        {
            _reschedule   = true;
            _downloadTask = Task.Run(async() =>
            {
                Debug.WriteLine("FETCH");
                try
                {
                    bool success = await WeatherDataFetcher.UpdateWeatherForecastDbAsync();
                    if (!success)
                    {
                        Debug.WriteLine("No new Data was fetched during background task");
                        _reschedule = true;
                    }

                    Debug.WriteLine("Background fetching SUCCESS");
                    _reschedule = false;
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error occured during background fetching: " + e.StackTrace);
                    _reschedule = true;
                }

                Debug.WriteLine("Job finished @ " + DateTime.Now);
                JobFinished(@params, false);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
                {
                    Util.ScheduleJob(this);
                }
            });
            Debug.WriteLine("Service running @ " + DateTime.Now);
            return(true);
        }
Esempio n. 2
0
        public override void PerformFetch(UIApplication app, Action <UIBackgroundFetchResult> completionHandler)
        {
            Debug.WriteLine("FETCH");
            try
            {
                bool success = WeatherDataFetcher.UpdateWeatherForecastDbAsync().Result;
                if (!success)
                {
                    completionHandler(UIBackgroundFetchResult.NoData);
                }

                completionHandler(UIBackgroundFetchResult.NewData);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error occured during Background Fetching: " + e.StackTrace);
            }
        }
Esempio n. 3
0
        public MainPage(int id)
        {
            _mId = id;
            InitializeComponent();

            Options.IsEnabled = DependencyService.Get <ISettingsService>().SettingsDialogueAvailable;

            DependencyService.Get <ISettingsService>().PropertyChanged += (sender, e) =>
            {
                DemoList.BeginRefresh();
                DemoList.RefreshCommand.Execute(DemoList);
                DemoList.EndRefresh();
            };

            if (WeatherDataFetcher.LastUpDate.Date <= DateTime.Now.AddDays(-2)) //is this how you use async things???
            {
                WeatherDataFetcher.UpdateWeatherForecastDbAsync();
            }
        }