Esempio n. 1
0
        public void RegisterBGTask(BGTaskKey key, IBackgroundTrigger trigger, IEnumerable <SystemConditionType> condition)
        {
            var taskRegistered = false;

            foreach (var tsk in BackgroundTaskRegistration.AllTasks)
            {
                if (tsk.Value.Name == key.GetTaskName())
                {
                    taskRegistered = true;
                    break;
                }
            }

            if (taskRegistered)
            {
                return;
            }

            var builder = new BackgroundTaskBuilder()
            {
                Name           = key.GetTaskName(),
                TaskEntryPoint = key.GetTaskEnty()
            };

            builder.SetTrigger(trigger);
            foreach (var con in condition)
            {
                builder.AddCondition(new SystemCondition(con));
            }

            BackgroundTaskRegistration task = builder.Register();
        }
Esempio n. 2
0
        public static string GetTaskEnty(this BGTaskKey key)
        {
            switch (key)
            {
            case BGTaskKey.UpdateDailyImageBGTask: return(UpdateDailyImageBGTaskEndPoint);
            }

            throw new ArgumentException();
        }
Esempio n. 3
0
        public void UnRegisterBGTask(BGTaskKey key, bool cancelTask)
        {
            var task = BackgroundTaskRegistration.AllTasks.FirstOrDefault(t => t.Value.Name == key.GetTaskName()).Value;

            if (task != null)
            {
                task.Unregister(cancelTask);
            }
        }
Esempio n. 4
0
 public bool IsBGTaskRegistered(BGTaskKey key)
 {
     return(BackgroundTaskRegistration.AllTasks.Any(t => t.Value.Name == key.GetTaskName()));
 }