<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;

namespace SimpleWeather.UWP.BackgroundTasks
{
    public class BackgroundTaskHandler
    {
        private const string taskName = "WeatherUpdateBackgroundTask";
        public ApplicationTrigger AppTrigger = null;

        public BackgroundTaskHandler()
        {
            AppTrigger = new ApplicationTrigger();
        }

        public async void RegisterBackgroundTask()
        {
            // Unregister any previous exising background task
            UnregisterBackgroundTask();

            // Request access
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

            // If allowed
            if (backgroundAccessStatus == BackgroundAccessStatus.AlwaysAllowed ||
                backgroundAccessStatus == BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
            {
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                taskBuilder.Name = taskName;
                taskBuilder.SetTrigger(new TimeTrigger((uint)Utils.Settings.RefreshInterval, false));
                taskBuilder.SetTrigger(new SystemTrigger(SystemTriggerType.SessionConnected, false));
                taskBuilder.SetTrigger(AppTrigger);
                var registration = taskBuilder.Register();
            }
        }

        public void UnregisterBackgroundTask()
        {
            foreach (var task in BackgroundTaskRegistration.AllTasks)
            {
                if (task.Value.Name == taskName)
                {
                    task.Value.Unregister(true);
                }
            }
        }
    }
}<commit_msg>SimpleWeather.UWP: register a background task for each trigger<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;

namespace SimpleWeather.UWP.BackgroundTasks
{
    public class BackgroundTaskHandler
    {
        private const string taskName = "WeatherUpdateBackgroundTask";
        public ApplicationTrigger AppTrigger = null;

        public BackgroundTaskHandler()
        {
            AppTrigger = new ApplicationTrigger();
        }

        public async void RegisterBackgroundTask()
        {
            // Unregister any previous exising background task
            UnregisterBackgroundTask();

            // Request access
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

            // If allowed
            if (backgroundAccessStatus == BackgroundAccessStatus.AlwaysAllowed ||
                backgroundAccessStatus == BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
            {
                // Register a task for each trigger
                var tb1 = new BackgroundTaskBuilder() { Name = taskName };
                tb1.SetTrigger(new TimeTrigger((uint)Utils.Settings.RefreshInterval, false));
                var tb2 = new BackgroundTaskBuilder() { Name = taskName };
                tb2.SetTrigger(new SystemTrigger(SystemTriggerType.SessionConnected, false));
                var tb3 = new BackgroundTaskBuilder() { Name = taskName };
                tb3.SetTrigger(AppTrigger);

                tb1.Register();
                tb2.Register();
                tb3.Register();
            }
        }

        public void UnregisterBackgroundTask()
        {
            foreach (var task in BackgroundTaskRegistration.AllTasks)
            {
                if (task.Value.Name == taskName)
                {
                    task.Value.Unregister(true);
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07225433526011561, 'fraction_numerical': 0.002364687335785602, 'mean_word_length': 2.0383080606544293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561328', 'n_tokens_mistral': 851, 'n_tokens_neox': 818, 'n_words': 191}