Example #1
0
        public static BackgroundTaskBuilder BuildTask(BackgroundTaskBuilderModel model, bool isNetworkRequested = false, bool cancelOnConditionLoss = true, BackgroundTaskRegistrationGroup group = null)
        {
            // Specify the background task
            var builder = new BackgroundTaskBuilder()
            {
                Name = model.Name
            };

            if (model.Trigger != null)
            {
                builder.SetTrigger(model.Trigger);
            }

            builder.IsNetworkRequested    = isNetworkRequested;
            builder.CancelOnConditionLoss = cancelOnConditionLoss;
            if (group != null)
            {
                builder.TaskGroup = group;
            }

            var conditions = model.GetConditions();

            if (conditions.Count > 0)
            {
                foreach (var condition in conditions)
                {
                    builder.AddCondition(condition);
                }
            }

            return(builder);
        }
Example #2
0
        internal static void RegisterBackgroundTasks()
        {
            IBackgroundCondition internetAvailableCondition     = new SystemCondition(SystemConditionType.InternetAvailable),
                                 userPresentCondition           = new SystemCondition(SystemConditionType.UserPresent),
                                 sessionConnectedCondition      = new SystemCondition(SystemConditionType.SessionConnected),
                                 backgroundCostNotHighCondition = new SystemCondition(SystemConditionType.BackgroundWorkCostNotHigh);

            var conditions = new[] {
                internetAvailableCondition,
                // userPresentCondition,
                //sessionConnectedCondition
            };

            var bgBuilderModel = new BackgroundTaskBuilderModel(
                "ToastNotificationAction",
                new ToastNotificationActionTrigger(),
                conditions
                );
            var toastActionTask = BuildTask(bgBuilderModel, true, true, null);

            toastActionTask.Register(true, false, true);

            bgBuilderModel = new BackgroundTaskBuilderModel(
                "SyncNotifications",
                new TimeTrigger(15, false),
                conditions
                );
            var syncTask = BuildTask(bgBuilderModel, true, true, null);

            syncTask.Register(true, false, true);
        }
Example #3
0
        private static BackgroundTaskBuilder BuildTask(BackgroundTaskBuilderModel model, string taskEntryPointName, bool isNetworkRequested = false, bool cancelOnConditionLoss = true, BackgroundTaskRegistrationGroup group = null)
        {
            // Specify the background task
            var builder = BuildTask(model, isNetworkRequested, cancelOnConditionLoss, group);

            builder.TaskEntryPoint = taskEntryPointName;
            return(builder);
        }
Example #4
0
        public static void RegisterAppTriggerBackgroundTasks()
        {
            IBackgroundCondition internetAvailableCondition     = new SystemCondition(SystemConditionType.InternetAvailable),
                                 userPresentCondition           = new SystemCondition(SystemConditionType.UserPresent),
                                 sessionConnectedCondition      = new SystemCondition(SystemConditionType.SessionConnected),
                                 backgroundCostNotHighCondition = new SystemCondition(SystemConditionType.BackgroundWorkCostNotHigh);

            var conditions = new[]
            {
                internetAvailableCondition,
                //userPresentCondition,
                //sessionConnectedCondition
            };

            var bgBuilderModel = new BackgroundTaskBuilderModel(
                "AppTrigger",
                conditions
                );

            var builder = BuildTask(bgBuilderModel, true, true, null);

            builder.Register(GetAppTrigger(), all: false);
        }
Example #5
0
 public static BackgroundTaskBuilder BuildTask <T>(BackgroundTaskBuilderModel model, bool isNetworkRequested = false, bool cancelOnConditionLoss = true, BackgroundTaskRegistrationGroup group = null)
     where T : IBackgroundTask
 {
     return(BuildTask(model, typeof(T).FullName, isNetworkRequested, cancelOnConditionLoss, group));
 }
Example #6
0
 public static BackgroundTaskBuilder BuildTask(BackgroundTaskBuilderModel model, Type entryPointType, bool isNetworkRequested = false, bool cancelOnConditionLoss = true, BackgroundTaskRegistrationGroup group = null)
 {
     return(BuildTask(model, entryPointType.FullName, isNetworkRequested, cancelOnConditionLoss, group));
 }