Beispiel #1
0
 private async void defaultViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "UseBackgroundTasks" && defaultViewModel.UseBackgroundTasks)
     {
         await BackgroundTaskRegistrar.RegisterBackgroundTask(resourceLoader.GetString("Dialog_BackgroundTasksDisabled"));
     }
 }
        /// <summary>
        /// Attempts to register a background task.
        /// </summary>
        private async Task <bool> TryRegisterBackgroundTask()
        {
            try
            {
                // We should always register these
                BackgroundTaskRegistrar.RegisterBackgroundTask(
                    typeof(AddedToLockScreenBackgroundTask),
                    new SystemTrigger(SystemTriggerType.LockScreenApplicationAdded, false),
                    new SystemCondition(SystemConditionType.InternetAvailable));

                BackgroundTaskRegistrar.RegisterBackgroundTask(
                    typeof(RemovedFromLockScreenBackgroundTask),
                    new SystemTrigger(SystemTriggerType.LockScreenApplicationRemoved, false));

                // Try and register the rest of our background tasks. The user could say no!
                var access = await BackgroundExecutionManager.RequestAccessAsync();

                if (access == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                    access == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
                {
                    BackgroundTaskRegistrar.TryRegisterAllBackgroundTasks();
                }
            }
            catch
            {
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            statusBar.ProgressIndicator.ProgressValue = 0;
            statusBar.ProgressIndicator.Text          = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_DEFAULT);
            await statusBar.ProgressIndicator.ShowAsync();

            DefaultViewModel.ResetFlags();
            var currentSettings   = SettingsViewModel.Current;
            var currentDataSource = DataSourceFactory.Current;

            // This can happen when navigating back after creating a feed, sleep, change or measure
            // I.e. don't allow the user to return to the 'create' page for that item once it is created
            if (e.NavigationParameter != null &&
                string.Equals(Constants.NAVIGATION_PARAMETER_CLEARLASTBACKENTRY,
                              e.NavigationParameter.ToString(),
                              StringComparison.OrdinalIgnoreCase))
            {
                Frame.BackStack.RemoveAt(1);
            }

            // Set the default display units based on the user setting
            // Conversion of values between units is handled by the Model <-> ViewModel extensions
            DefaultViewModel.CurrentWeightUnit = currentSettings.UseMetricUnits
                                                        ? ResourceLoader.GetString(Constants.RESOURCEKEY_UNIT_WEIGHT_METRIC)
                                                        : ResourceLoader.GetString(Constants.RESOURCEKEY_UNIT_WEIGHT_IMPERIAL);
            DefaultViewModel.CurrentLengthUnit = currentSettings.UseMetricUnits
                                                        ? ResourceLoader.GetString(Constants.RESOURCEKEY_UNIT_LENGTH_METRIC)
                                                        : ResourceLoader.GetString(Constants.RESOURCEKEY_UNIT_LENGTH_IMPERIAL);

            await BackgroundTaskRegistrar.RegisterBackgroundTask(ResourceLoader.GetString(Constants.RESOURCEKEY_DIALOG_BACKGROUNDTASKSDISABLED));

            // Push any local changes, i.e. changes made while offline, to the server
            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_UPDATINGSERVER);
            await currentDataSource.PushLocalChangesToServer();

            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_BABY);
            var babyId = await RetrieveMostRecentlyAccessedBaby(currentSettings, currentDataSource);

            DefaultViewModel.Babies.Add(CurrentBaby);
            statusBar.ProgressIndicator.ProgressValue = 0.1;

            // Retrieve the activity schedule for the current baby,
            // may have already been downloaded by the background task
            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_SCHEDULE);
            var currentBabiesSchedule = (await currentDataSource.GetActivitySchedule(babyId)).AsViewModel(currentSettings.UseMetricUnits,
                                                                                                          CurrentBaby.AsModel());

            DefaultViewModel.NextActivity             = GetNextActivityFromSchedule(CurrentBaby, currentBabiesSchedule);
            statusBar.ProgressIndicator.ProgressValue = 0.25;

            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_FEED);
            RetrieveCurrentFeed(currentSettings, currentBabiesSchedule);
            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_SLEEP);
            RetrieveCurrentSleep(currentSettings, currentBabiesSchedule);

            DefaultViewModel.MainLoadingComplete      = true;
            statusBar.ProgressIndicator.ProgressValue = 0.5;

            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_BABIES);
            await RetrieveAllBabies(currentSettings, currentDataSource);

            statusBar.ProgressIndicator.ProgressValue = 0.6;

            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_MEASUREMENTS);
            await RetrieveLatestMeasurementsForCurrentBaby(currentSettings, currentDataSource, babyId);

            statusBar.ProgressIndicator.ProgressValue = 0.75;

            // Retrieve the status of the current baby
            if (currentBabiesSchedule.LastFeed != null)
            {
                DefaultViewModel.MostRecentActivities.Add(currentBabiesSchedule.LastFeed);
            }
            if (currentBabiesSchedule.LastSleep != null)
            {
                DefaultViewModel.MostRecentActivities.Add(currentBabiesSchedule.LastSleep);
            }
            if (currentBabiesSchedule.LastChange != null)
            {
                DefaultViewModel.MostRecentActivities.Add(currentBabiesSchedule.LastChange);
            }

            statusBar.ProgressIndicator.Text = ResourceLoader.GetString(Constants.RESOURCEKEY_LOADINGSTATUS_RHYTHM);
            await RetrieveDataTrendsForCurrentBaby(currentDataSource, babyId);

            statusBar.ProgressIndicator.ProgressValue = 1;

            statusBar.ProgressIndicator.Text = string.Empty;
            await statusBar.ProgressIndicator.HideAsync();
        }