示例#1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            NetworkStateChangeEventDetails details = taskInstance.TriggerDetails as NetworkStateChangeEventDetails;

            if (!details.HasNewNetworkConnectivityLevel)
            {
                return;
            }

            var connectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (connectionProfile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
            {
                return;
            }

            var deferral = taskInstance.GetDeferral();

            var settings   = new BackgroundSettingsViewModel();
            var dataSource = new MobileServicesDataSource(settings.MobileServicesUserId,
                                                          new AccessTokenRetriever(),
                                                          new BugSenseLogger());
            bool couldLogIn = await dataSource.Login(false, true);

            if (couldLogIn)
            {
                await dataSource.PushLocalChangesToServer();
            }

            deferral.Complete();
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();

            tileUpdater.EnableNotificationQueue(true);
            tileUpdater.Clear();

            var settings   = new BackgroundSettingsViewModel();
            var dataSource = new MobileServicesDataSource(settings.MobileServicesUserId,
                                                          new AccessTokenRetriever(),
                                                          new BugSenseLogger());
            bool couldLogIn = await dataSource.Login(false, true);

            if (couldLogIn)
            {
                var babies = await dataSource.GetBabies(settings.FamilyId);

                var babyActiviyScheduleTasks = babies.Select(async baby =>
                {
                    var activitySchedule = await dataSource.GetActivitySchedule(baby.Id);
                    ScheduleToastNotifications(activitySchedule, baby, settings);
                    return(Tuple.Create(baby, activitySchedule));
                });
                var babyActivitySchedules = await Task.WhenAll(babyActiviyScheduleTasks.ToArray());

                UpdateTiles(babyActivitySchedules, tileUpdater, settings);
            }

            deferral.Complete();
        }