Exemple #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            StartTask(taskInstance);

            // 1.Get LocatonItem from storage (json)
            var location = Settings.GetLocationAsync(taskInstance.Task.Name);

            if (location == null || !SecondaryTile.Exists(taskInstance.Task.Name))
            {
                EndTask();
                return;
            }

            // 2.Fetch current weather
            var forecast = await FetchCurrentForecast(location.Latitude, location.Longitude);

            // 3.Update secondary tile
            TileDesigner.UpdateSecondary(taskInstance.Task.Name, forecast, location.Town);
            EndTask();
        }
Exemple #2
0
        private async Task <bool> PinLocationOnStart(LocationItem location)
        {
            // 1.Ask for pin
            var locationId = TileDesigner.ConvertLocationNameToTileId(location.Name);
            var isPined    = await TileDesigner.PinSecondaryTile(location);

            if (!isPined)
            {
                return(false);
            }

            // 2.Register task config
            await Settings.SaveSecondaryTaskLocation(locationId, location);

            // 3.Register task
            BackgroundTasks.RegisterSecondaryTileTask(locationId);

            // 4.Update the tile
            var forecast = await App.DataSource.GetCurrentForecast(location.Latitude, location.Longitude);

            TileDesigner.UpdateSecondary(locationId, forecast, location);

            return(true);
        }