Inheritance: ISystemCondition, IBackgroundCondition
        private async Task UpdateTile()
        {
            var result = await BackgroundExecutionManager.RequestAccessAsync();
            if (result == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                result == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {
                foreach (var task in BackgroundTaskRegistration.AllTasks)
                {
                    if (task.Value.Name == TASK_NAME)
                        task.Value.Unregister(true);

                    //task.Value.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
                    //task.Value.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
                }

                BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                var condition = new SystemCondition(SystemConditionType.InternetAvailable);

                builder.Name = TASK_NAME;
                builder.AddCondition(condition);
                builder.TaskEntryPoint = TASK_ENTRY;
                builder.SetTrigger(new TimeTrigger(15, false));
                var registration = builder.Register();

                registration.Progress += new BackgroundTaskProgressEventHandler(task_Progress);
                registration.Completed += new BackgroundTaskCompletedEventHandler(task_Completed);

            }
        }
 public static void BacgroundTaskSetup()
 {
     Trigger = new TimeTrigger(15, false);
     SystemCondition userCondition = new SystemCondition(SystemConditionType.UserPresent);
     taskName = "SampleBackgroundTask";
     entryPoint = "WindowsRuntimeComponent.SampleBackgroundTask";
 }
        public static IAsyncOperation<BackgroundTaskRegistration> RegisterTaskAsync()
        {
            return AsyncInfo.Run(async (cancellationToken) =>
            {
                if (IsTaskRegistered())
                    return _current;

                await BackgroundExecutionManager.RequestAccessAsync();


                //http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.background.timetrigger.aspx
                IBackgroundTrigger trigger = new TimeTrigger(6*60, false); //6 hours

                // Builds the background task.
                BackgroundTaskBuilder builder = new BackgroundTaskBuilder();

                builder.Name = FriendlyName;
                builder.TaskEntryPoint = typeof(BackgroundDemoTask).FullName;
                builder.SetTrigger(trigger);

                SystemCondition condition = new SystemCondition(SystemConditionType.InternetAvailable);
                builder.AddCondition(condition);

                // Registers the background task, and get back a BackgroundTaskRegistration object
                // representing the registered task.
                _current = builder.Register();
                return _current;
            });
        }
        private async void RegisterBackgroundTasks()
        {
            var access = await BackgroundExecutionManager.RequestAccessAsync();
            if (access == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity || access == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {
                TimeTrigger taskTrigger = new TimeTrigger(15, false);
                foreach (var _task in BackgroundTaskRegistration.AllTasks)
                {
                    if (_task.Value.Name == "WPGetListUpdateTimer" || _task.Value.Name=="WPGetListUpdateInternet")
                    {
                        _task.Value.Unregister(true);
                    }
                }
                SystemTrigger striger = new SystemTrigger(SystemTriggerType.InternetAvailable, false);
                var bgTaskBuilder = new BackgroundTaskBuilder();
                bgTaskBuilder.Name = "WPGetListUpdateTimer";
                bgTaskBuilder.TaskEntryPoint = "BackgroundTaskWinMD.WPGetListUpdateBackgroundTask";
                bgTaskBuilder.SetTrigger(taskTrigger);
                // условие, согласно которому триггер будет выполнен только если интернет доступен
                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                bgTaskBuilder.AddCondition(internetCondition);
                BackgroundTaskRegistration task = bgTaskBuilder.Register();

                bgTaskBuilder = new BackgroundTaskBuilder();
                bgTaskBuilder.Name = "WPGetListUpdateInternet";
                bgTaskBuilder.TaskEntryPoint = "BackgroundTaskWinMD.WPGetListUpdateBackgroundTask";
                bgTaskBuilder.SetTrigger(striger);
                
                bgTaskBuilder.AddCondition(internetCondition);
                BackgroundTaskRegistration task2 = bgTaskBuilder.Register();

            }
        }
        private void RegisterTaskButton_Click(Object sender, RoutedEventArgs e)
        {
            if (GetRegisteredTask() == null)
            {
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                MaintenanceTrigger trigger = new MaintenanceTrigger(MAINTENANCE_INTERVAL, false);
                taskBuilder.SetTrigger(trigger);
                taskBuilder.TaskEntryPoint = PUSH_NOTIFICATIONS_TASK_ENTRY_POINT;
                taskBuilder.Name = PUSH_NOTIFICATIONS_TASK_NAME;

                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                taskBuilder.AddCondition(internetCondition);

                try
                {
                    taskBuilder.Register();
                    rootPage.NotifyUser("Task registered", NotifyType.StatusMessage);
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error registering task: " + ex.Message, NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Task already registered", NotifyType.ErrorMessage);
            }
        }
Esempio n. 6
0
        private async void registerButton_Click(object sender, RoutedEventArgs e)
        {
            TimeTrigger timetrigger = new TimeTrigger(30, false);
            PushNotificationTrigger notificationTrigger = new PushNotificationTrigger();
            


            var SampleTask = new BackgroundTaskBuilder(); //创建后台任务实例
            SampleTask.Name = "Reminder";  //指定后台任务名称
            SampleTask.TaskEntryPoint = "ReminderComponent.Reminder";//指定后台任务名称
            SampleTask.SetTrigger(timetrigger);//指定后台任务的触发器

            SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
            SampleTask.AddCondition(internetCondition);

            var access = await BackgroundExecutionManager.RequestAccessAsync();
            if (access == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity)
            {
                BackgroundTaskRegistration task = SampleTask.Register();
                task.Progress += Value_Progress; ;
                task.Completed += Value_Completed; ;
                UpdateUI("", "注册成功");

                registerButton.IsEnabled = false;
                cancelButtton.IsEnabled = true;

                var settings = Windows.Storage.ApplicationData.Current.LocalSettings;
                settings.Values.Remove(task.Name);
            }
            else if (access == BackgroundAccessStatus.Denied)//用户禁用后台任务或后台任务数量已达最大
            {
                await new MessageDialog("您已禁用后台任务或后台任务数量已达最大!").ShowAsync();
            }

        }
Esempio n. 7
0
        /// <summary>
        /// The register task.
        /// </summary>
        private static async void PushNotifications()
        {
            const string PushNotificationTaskName = "ToastNotifications";

            if (GetRegisteredTask(PushNotificationTaskName) != null)
            {
                return;
            }

            var ns = new NotificationStore();
            ns.Register();

            await BackgroundExecutionManager.RequestAccessAsync();

            await ObtainLockScreenAccess();
            var taskBuilder = new BackgroundTaskBuilder
                                  {
                                      Name = PushNotificationTaskName,
                                      TaskEntryPoint = typeof(PushNotificationTask).FullName
                                  };

            var trigger = new PushNotificationTrigger();
            taskBuilder.SetTrigger(trigger);

            var internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
            taskBuilder.AddCondition(internetCondition);

            try
            {
                taskBuilder.Register();
            }
            catch (Exception exception)
            {
            }
        }
Esempio n. 8
0
        private async void RegisterBackgroundTasks()
        {
            var builder = new BackgroundTaskBuilder
            {
                Name = "BackgroundUpdateReadingList",
                TaskEntryPoint = "EasyReader.BackgroundTasks.UpdateReadingList"
            };

            try
            {
                await BackgroundExecutionManager.RequestAccessAsync();
            }
            catch (Exception)
            {
                
            }

            IBackgroundTrigger trigger = new TimeTrigger(15, true);
            builder.SetTrigger(trigger);

            IBackgroundCondition condition = new SystemCondition(SystemConditionType.InternetAvailable);
            builder.AddCondition(condition);

            IBackgroundTaskRegistration task = builder.Register();

            task.Progress += task_Progress;
            task.Completed += task_Completed;
        }
Esempio n. 9
0
 private static void RegisterMaintenanceBackgroundTask()
 {
     var builder = new BackgroundTaskBuilder {Name = TaskName, TaskEntryPoint = TaskEntry};
     IBackgroundTrigger trigger = new TimeTrigger(15, false);
     builder.SetTrigger(trigger);
     IBackgroundCondition condition =
         new SystemCondition(SystemConditionType.InternetAvailable);
     builder.AddCondition(condition); 
     IBackgroundTaskRegistration task = builder.Register();
 }
 async Task Register()
 {
     await BackgroundExecutionManager.RequestAccessAsync();
     var builder = new BackgroundTaskBuilder();
     builder.Name = "MyBackgroundTask";
     var condition = new SystemCondition(SystemConditionType.InternetAvailable);
     var trigger = new SystemTrigger(SystemTriggerType.TimeZoneChange, false);
     builder.TaskEntryPoint = typeof(MyBackgroundTask.TimeZoneTask).FullName;
     builder.AddCondition(condition);
     builder.SetTrigger(trigger);
     builder.Register();
 }
Esempio n. 11
0
        /// <summary>
        /// Cannot avoid this method being blocking on the UI thread, because creating the background task requires it
        /// (otherwise creating the LocationTrigger gives a COM exception)
        /// </summary>
        public async Task On(string backgroundTaskEntryPoint)
        {
            if (string.IsNullOrWhiteSpace(backgroundTaskEntryPoint)) throw new ArgumentNullException(nameof(backgroundTaskEntryPoint));

            await _permissionRepository.RequestRequired();

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, 
                () => 
                {
                    var trigger = new LocationTrigger(LocationTriggerType.Geofence);
                    var condition = new SystemCondition(SystemConditionType.InternetAvailable);

                    _backgroundTaskRegistrar.Register(backgroundTaskEntryPoint,
                        BackgroundTaskName, trigger, condition);
                });

            _applicationRepository.UpdateIsEnabled(isEnabled: true);
        }
Esempio n. 12
0
        private const int MAINTENANCE_INTERVAL = 10 * 24 * 60; // Check for channels that need to be updated every 10 days

		public App()
		{
			InitializeComponent();
			this.Suspending += new SuspendingEventHandler(OnSuspending);

            if (!IsTaskRegistered())
            {
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                MaintenanceTrigger trigger = new MaintenanceTrigger(MAINTENANCE_INTERVAL, false);
                taskBuilder.SetTrigger(trigger);
                taskBuilder.TaskEntryPoint = PUSH_NOTIFICATIONS_TASK_ENTRY_POINT;
                taskBuilder.Name = PUSH_NOTIFICATIONS_TASK_NAME;

                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                taskBuilder.AddCondition(internetCondition);

                taskBuilder.Register();
            }
		}
Esempio n. 13
0
        private async void RegisterBackgroundTask()
        {
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();

            if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
                backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {

                foreach (var t in BackgroundTaskRegistration.AllTasks)
                    t.Value.Unregister(true);

                BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                builder.TaskEntryPoint = typeof(SampleRuntimeComponent.DataTask).FullName;
                builder.Name = "DataTask";
                builder.SetTrigger(_trigger);

                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                builder.AddCondition(internetCondition);

                var registration = builder.Register();
            }
        }
        public static async Task<BackgroundTaskRegistration> Register()
        {
            // If the user denies this once, it cannot be re-enabled: uninstall / install from the Start screen...
            var status = await BackgroundExecutionManager.RequestAccessAsync();

            if (status == BackgroundAccessStatus.Denied || status == BackgroundAccessStatus.Unspecified)
            {
                return null;
            }

            var builder = new BackgroundTaskBuilder();

            builder.Name = UpdateTaskName;
            builder.TaskEntryPoint = UpdateTaskEntryPoint;
            builder.SetTrigger(new TimeTrigger(UpdateTaskTimeTriggerInterval, false));

            IBackgroundCondition condition = new SystemCondition(SystemConditionType.InternetAvailable);
            builder.AddCondition(condition);

            BackgroundTaskRegistration task = builder.Register();
            return task;
        }
Esempio n. 15
0
        public async static Task RegBGTask(uint frequency, bool isEnabled)
        {
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
            if (backgroundAccessStatus == BackgroundAccessStatus.AlwaysAllowed ||
                backgroundAccessStatus == BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
            {
                foreach (var t in BackgroundTaskRegistration.AllTasks)
                {
                    if (t.Value.Name == BACKGROUND_NAME || t.Value.Name == TOAST_HANDLER_NAME)
                    {
                        t.Value.Unregister(true);
                    }
                }


                BackgroundTaskBuilder builder = new BackgroundTaskBuilder()
                {
                    Name = TOAST_HANDLER_NAME,
                    TaskEntryPoint = TOAST_HANDLER_ENTRY
                };
                builder.SetTrigger(new ToastNotificationActionTrigger());
                BackgroundTaskRegistration toastreg = builder.Register();


                if (frequency < 30 || !isEnabled)
                {
                    return;
                }
                TimeTrigger hourlyTrigger = new TimeTrigger(frequency, false);
                SystemCondition userCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                taskBuilder.Name = BACKGROUND_NAME;
                taskBuilder.TaskEntryPoint = BACKGROUND_ENTRY;
                taskBuilder.AddCondition(userCondition);
                taskBuilder.SetTrigger(hourlyTrigger);
                var registration = taskBuilder.Register();
            }
        }
Esempio n. 16
0
        /// <summary>
        /// The register push notifications.
        /// </summary>
        private static async void RegisterPushNotifications()
        {
            const string RegisterPushNotificationName = "RegisterNotifications";
            const int RegistrationInterval = 10 * 24 * 60;

            if (GetRegisteredTask(RegisterPushNotificationName) != null)
            {
                return;
            }

            await BackgroundExecutionManager.RequestAccessAsync();

            var taskBuilder = new BackgroundTaskBuilder
                                  {
                                      Name = RegisterPushNotificationName,
                                      TaskEntryPoint = typeof(RegisterPushNotificationTask).FullName
                                  };

            var trigger = new TimeTrigger(RegistrationInterval, false);
            taskBuilder.SetTrigger(trigger);

            var internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
            taskBuilder.AddCondition(internetCondition);

            try
            {
                taskBuilder.Register();
            }
            catch (Exception exception)
            {
            }
        }
        private async void RegisterTask()
        {
            try
            {
                BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();

                if(status == BackgroundAccessStatus.Denied)
                {
                    //Message aan gebruiker, bevoorbeeld
                }
                else
                {
                    //Taak registreren bij systeem
                    BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                    builder.Name = BackgroundTaskName;
                    builder.TaskEntryPoint = BackgroundTaskEntryPoint;

                    var trigger = new TimeTrigger(15,false);//Oneshot, 1x uitvoeren of elke 15 minuten uitvoeren?
                    builder.SetTrigger(trigger);

                    //Er moet iets zijn, conditie
                    var condition = new SystemCondition(SystemConditionType.InternetAvailable);//Als er internet is
                    builder.AddCondition(condition);

                    regTask = builder.Register();
                    regTask.Completed += RegTask_Completed;
                }
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
        public SnooStreamViewModelPlatform()
        {
            try
            {
                SnooStreamViewModel.SystemServices = new SystemServices();
                SnooStreamViewModel.MarkdownProcessor = new MarkdownProvider();
                SnooStreamViewModel.ActivityManager = new SnooStream.PlatformServices.ActivityManager();
                if (!IsInDesignMode)
                {
                    ((SystemServices)SnooStreamViewModel.SystemServices).FinishInitialization(Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher);
                    SnooStreamViewModel.CWD = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
                    SnooStreamViewModel.UserCredentialService = new DefaultUserCredentialService();

                }
                FinishInit();

                if (!IsInDesignMode)
                {
					MakeHubSections();
					RaisePropertyChanged("HubSections");

                    LockScreenSettings lsSettings = new LockScreenSettings();
                    lsSettings.LiveTileSettings = new List<LiveTileSettings>
                    {
                        new LiveTileSettings { CurrentImages = new List<string>(), LiveTileItemsReddit = "/", LiveTileStyle = LiveTileStyle.TextImage}
                    };
                    lsSettings.RedditOAuth = SnooStreamViewModel.RedditUserState != null && SnooStreamViewModel.RedditUserState.OAuth != null ?
                        JsonConvert.SerializeObject(SnooStreamViewModel.RedditUserState) : "";

                    lsSettings.Store();

					MessengerInstance.Register<UserLoggedInMessage>(this, OnUserLoggedIn);

                    Task.Delay(10000).ContinueWith(async (tskTop) =>
                        {
                            try
                            {
                                await BackgroundExecutionManager.RequestAccessAsync();
                                TimeTrigger timeTrigger = new TimeTrigger(30, false);
                                SystemCondition userCondition = new SystemCondition(SystemConditionType.UserPresent);
                                string entryPoint = "SnooStreamBackground.UpdateBackgroundTask";
                                string taskName = "Background task for updating live tile and displaying message notifications from reddit";

                                BackgroundTaskRegistration task = RegisterBackgroundTask(entryPoint, taskName, timeTrigger, userCondition);
                            }
                            catch (Exception ex)
                            {
                                //_logger.Error("failed to register background task", ex);
                            }

                            SystemServices.RunUIIdleAsync(() =>
                                {
                                    return Task.Run(() =>
                                        {
                                            UpdateBackgroundTask tsk = new UpdateBackgroundTask();
                                            try
                                            {
                                                tsk.RunExternal();
                                            }
                                            catch { }
                                        });
                                });
                        }, TaskScheduler.Current);

                }
            }
            catch (Exception ex)
            {
                //_logger.Fatal("fetal error during initialization", ex);
                throw ex;
            }
        }
        private async Task RegisterTask(string BackgroundTaskName, string BackgroundTaskEntryPoint)
        {
            try
            {
                BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
                if (status == BackgroundAccessStatus.Denied)
                {
                    //geen toegang

                }
                else
                {
                    //toegang



                    BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
                    builder.Name = BackgroundTaskName;
                    builder.TaskEntryPoint = BackgroundTaskEntryPoint;

                    var trigger = new TimeTrigger(15, false);// om de 2 minuten


                    builder.SetTrigger(trigger);

                    var condition = new SystemCondition(SystemConditionType.InternetAvailable);

                    builder.AddCondition(condition);


                    regTask = builder.Register();
                    regTask.Completed += RegTask_Completed;

                }
            }
            catch (Exception ex)
            {

                Debug.WriteLine(ex);
            }
        }
        public void RegisterIt()
        {
            foreach (var _task in BackgroundTaskRegistration.AllTasks)
            {
                if (_task.Value.Name == "My demo task")
                {
                    _task.Value.Unregister(true);
                }
            }

            TimeTrigger taskTrigger = new TimeTrigger(15, false);
            var bgTaskBuilder = new BackgroundTaskBuilder();
            bgTaskBuilder.Name = "My demo task";
            bgTaskBuilder.TaskEntryPoint = "BGTaskMD.ExampleBackgroundTask";
            bgTaskBuilder.SetTrigger(taskTrigger);
            SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
            bgTaskBuilder.AddCondition(internetCondition);
            BackgroundTaskRegistration task = bgTaskBuilder.Register();

            task.Completed += task_Completed;
        }
        private async void CheckBackGroundStatus()
        {
            try
            {



                int c = BackgroundTaskRegistration.AllTasks.Count;
                if (c > 1)
                {
                    foreach (var bTasks in BackgroundTaskRegistration.AllTasks)
                    {
                        bTasks.Value.Unregister(true);
                    }
                }
                else if (c == 0)
                {
                    await BackgroundExecutionManager.RequestAccessAsync();
                    var background = new BackgroundTaskBuilder();
                    background.Name = "Metro Player";
                    background.TaskEntryPoint = "IPlayer_BackgroundTask.Task";
                    var sc = new SystemCondition(SystemConditionType.UserPresent);
                    background.AddCondition(sc);
                    background.SetTrigger(new TimeTrigger(45, false));
                    var btr = background.Register();
                }

                //string s = null;
                //foreach (var VARIABLE in BackgroundTaskRegistration.AllTasks)
                //{
                //    s += VARIABLE.Value.Name + "\n";

                //}
                // new MessageDialog(c.ToString()).ShowAsync();
            }
            catch
            {
                ErrorCorrecting("001");
            }
        }
        /// <summary>
        /// Registriert eine Hintergrundaufgabe, die durch eine eingehende RawNotification ausgelöst wird. Es muss beachtet werden, dass 
        /// hierfür Zugriff auf den LockScreen gewährt sein muss. Es muss sichergestellt werden, dass RequestAccessAsync() aufgerufen wurde, 
        /// bevor die Registrierung erfolgt.
        /// </summary>
        public static void Register()
        {
            // Registriere die Task, wenn sie nicht bereits registriert wurde.
            if (!IsTaskRegistered()){
                var builder = new BackgroundTaskBuilder();

                // Setze den eindeutigen Namen, den EntryPoint für die BG Task und den Trigger, der die BG Task auslöst.
                builder.Name = BG_TASK_NAME;
                builder.TaskEntryPoint = typeof(PushNotificationManager).FullName;
                builder.SetTrigger(new PushNotificationTrigger());

                // Lege Bedingung für die Ausführung der BackgroundTask fest. Hier, InternetAvailable muss zutreffen.
                SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable);
                builder.AddCondition(internetCondition);

                // Registriere die Task.
                BackgroundTaskRegistration task = builder.Register();
                Debug.WriteLine("Background task PushNotificationManager is registered.");
            }
            else {
                Debug.WriteLine("PushNotificationManager background task already registered. Not necessary to perform registration once again.");
            }
        }
Esempio n. 23
0
        private void RegisterBackgroundTasks()
        {
            BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
            // Friendly string name identifying the background task             
            builder.Name = "BackgroundLiveTiles";
            // Class name             
            builder.TaskEntryPoint = "TileBackground.Class1";
            IBackgroundTrigger trigger = new TimeTrigger(15, true);
            builder.SetTrigger(trigger);
            IBackgroundCondition condition = new SystemCondition(SystemConditionType.InternetAvailable);
            builder.AddCondition(condition);
            IBackgroundTaskRegistration task = builder.Register();

            //YOu have the option of implementing these events to do something upon completion          
            //task.Progress += task_Progress;            
            //task.Completed += task_Completed;        
        }