Пример #1
0
        private void StartPeriodicAgent()
        {
            // is old task running, remove it
            _periodicTask = ScheduledActionService.Find(PeriodicTaskName) as PeriodicTask;
            if (_periodicTask != null)
            {
                try
                {
                    ScheduledActionService.Remove(PeriodicTaskName);
                }
                catch (Exception)
                {
                }
            }
            // create a new task
            _periodicTask = new PeriodicTask(PeriodicTaskName);
            // load description from localized strings
            _periodicTask.Description = "This is LiveTile application update agent.";
            // set expiration days
            _periodicTask.ExpirationTime = DateTime.Now.AddDays(14);
            try
            {
                // add thas to scheduled action service
                ScheduledActionService.Add(_periodicTask);
                // debug, so run in every 30 secs
#if DEBUG_AGENT
                ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(10));
                System.Diagnostics.Debug.WriteLine("Periodic task is started: " + PeriodicTaskName);
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    // load error text from localized strings
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
        public void StartPeriodicAgent()
        {
            // Variable for tracking enabled status of background agents for this app.
            AgentsAreEnabled = true;

            // Obtain a reference to the period task, if one exists
            _periodicTask = ScheduledActionService.Find(PeriodicTaskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (_periodicTask != null)
            {
                RemoveAgent(PeriodicTaskName);
            }

            _periodicTask = new PeriodicTask(PeriodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            _periodicTask.Description = "Booktera másodlagos csempe képek frissítése. ";

            // Place the call to Add in a try block in case the user has disabled agents
            try
            {
                ScheduledActionService.Add(_periodicTask);

                // If debugging is enabled, use LaunchForTest to launch the agent in 5s.
                ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(5));
            }
            catch (InvalidOperationException e)
            {
                if (e.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                    AgentsAreEnabled = false;
                }
                if (e.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            PeriodicTask cleanupTask;

            cleanupTask = ScheduledActionService.
                          Find("NotificationCleanupTask") as PeriodicTask;
            if (cleanupTask != null)
            {
                if (cleanupTask.LastExitReason != AgentExitReason.Completed &&
                    cleanupTask.LastExitReason != AgentExitReason.None)
                {
                    AgentStatus += string.Format("The background task failed to complete its last execution at {0:g} with an exit reason of {1}. ",
                                                 cleanupTask.LastScheduledTime, cleanupTask.LastExitReason);
                }

                if (!cleanupTask.IsEnabled)
                {
                    AgentStatus += "The background task was blocked by the user. ";
                }

                if (cleanupTask.ExpirationTime < DateTime.Now)
                {
                    AgentStatus = "The background task was expired. ";
                }

                ScheduledActionService.Remove(cleanupTask.Name);
            }

            try
            {
                cleanupTask             = new PeriodicTask("NotificationCleanupTask");
                cleanupTask.Description = "A background agent responsible for removing expired Windows Phone 8 in Action notifications";
                ScheduledActionService.Add(cleanupTask);
            }
            catch (InvalidOperationException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                AgentStatus += "Unable to create the background task.";
                cleanupTask  = null;
            }

            if (cleanupTask != null)
            {
                ScheduledActionService.LaunchForTest(cleanupTask.Name,
                                                     TimeSpan.FromSeconds(3));
            }
        }
Пример #4
0
        private void StartResourceIntensiveAgent()
        {
            agentsAreEnabled = true;

            resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule.
            if (resourceIntensiveTask != null)
            {
                RemoveAgent(resourceIntensiveTaskName);
            }

            resourceIntensiveTask = new ResourceIntensiveTask(resourceIntensiveTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            resourceIntensiveTask.Description = "This demonstrates a resource-intensive task.";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(resourceIntensiveTask);
                //ResourceIntensiveStackPanel.DataContext = resourceIntensiveTask;

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.

#if (DEBUG_AGENT)
                ScheduledActionService.LaunchForTest(resourceIntensiveTask.Name, TimeSpan.FromSeconds(10));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                    agentsAreEnabled = false;
                }
                // ResourceIntensiveCheckBox.IsChecked = false;
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
                //   ResourceIntensiveCheckBox.IsChecked = false;
            }
        }
Пример #5
0
        /// <summary>
        /// The Periodic Agent code runner, only needs to be called once when the app starts
        /// </summary>
        private void StartPeriodicAgent()
        {
            // is old task running, remove it
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
            if (periodicTask != null)
            {
                try
                {
                    ScheduledActionService.Remove(periodicTaskName);
                }
                catch (Exception)
                {
                }
            }
            // create a new task
            periodicTask = new PeriodicTask(periodicTaskName);
            // load description from localized strings
            periodicTask.Description = "Updates lockscreen for Outset app";
            // set expiration days
            periodicTask.ExpirationTime = DateTime.Now.AddDays(14);
            try
            {
                // add thas to scheduled action service
                ScheduledActionService.Add(periodicTask);

                // debug, so run in every 30 secs
                ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(30));
            }
            catch (InvalidOperationException exception)
            {
                Debug.WriteLine(exception.ToString());

                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    // load error text from localized strings
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Пример #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Referenz auf die PeriodicTask ermitteln
            var periodicTask = ScheduledActionService.Find("PeriodicAgent") as PeriodicTask;

            if (periodicTask != null)
            {
                RemoveAgent("PeriodicAgent");
            }

            // Eine periodic Task muss eine Beschreibung enthalten, die auf der Settings Seite vom OS angzeigt werden kann
            periodicTask = new PeriodicTask("PeriodicAgent")
            {
                Description = "This demos a periodic task."
            };


            //// Eine ResourceIntensiveTask muss eine Beschreibung enthalten, die auf der Settings Seite vom OS angzeigt werden kann
            //var intensivTask = new ResourceIntensiveTask("PeriodicAgent") {
            //  Description = "This demos a periodic task."
            //};

            // Das Hinzufügen eines Agants sollte immer in einem Try-Block erfolgen, der Benutzer könnte Agants für diese
            // App oder alle Agants deaktiviert haben, bzw. es könnten keine Ressourcen mehr übrig sein.
            try {
                ScheduledActionService.Add(periodicTask);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if (DEBUG)
                ScheduledActionService.LaunchForTest("PeriodicAgent", TimeSpan.FromSeconds(30));
#endif
            } catch (InvalidOperationException exception) {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Hintergrundaufgaben sind für diese App deaktiviert.");
                }

                if (
                    exception.Message.Contains(
                        "BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // Keine Aktion erforderlihc, das System gibt selständig keine Meldung mit dem aktuellen Limit aus.
                }
            } catch (SchedulerServiceException) {
                // Keine weitere aktion erforderlich
            }
        }
Пример #7
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            string       taskName = "AroundMeLockScreenChanger";
            PeriodicTask oldTask  = ScheduledActionService.Find(taskName) as PeriodicTask;

            if (oldTask != null)
            {
                ScheduledActionService.Remove(taskName);
            }

            PeriodicTask task = new PeriodicTask(taskName);

            task.Description = "Change Lockscreen Wallpaper";
            ScheduledActionService.Add(task);

            //ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(10));
        }
        private void StartPeriodicAgent()
        {
            PeriodicTask periodicTask = new PeriodicTask("ScheduledTaskAgent1");

            periodicTask.Description = "test";

            // If the agent is already registered with the system,
            if (ScheduledActionService.Find(periodicTask.Name) != null)
            {
                ScheduledActionService.Remove("ScheduledTaskAgent1");
            }

            //only can be called when application is running in foreground
            ScheduledActionService.Add(periodicTask);

            ScheduledActionService.LaunchForTest(periodicTask.Name, TimeSpan.FromSeconds(5.0f));
        }
Пример #9
0
        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}


        private void ToastNotificationSetup()
        {
            PeriodicTask periodicTask;
            string       periodicTaskName = "PeriodicAgent";

            // Obtain a reference to the period task, if one exists
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

            if (periodicTask != null)
            {
                RemoveAgent(periodicTaskName);
            }

            periodicTask = new PeriodicTask(periodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            periodicTask.Description = "BirthdayBumper Wish reminding periodic task.";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(periodicTask);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
                #if (DEBUG_AGENT)
                ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
                #endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Пример #10
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += (sender, args) =>
            {
                var periodic = new PeriodicTask("Temp");
                periodic.Description = "A";

                if (ScheduledActionService.Find("Temp") != null)
                {
                    ScheduledActionService.Remove("Temp");
                }
                ScheduledActionService.Add(periodic);

                ScheduledActionService.LaunchForTest("Temp", TimeSpan.FromSeconds(30));
            };
        }
Пример #11
0
        private void StartBackgroundProcess()
        {
            // Obtain a reference to the period task, if one exists
            _periodicTask = ScheduledActionService.Find(_periodicTaskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (_periodicTask != null)
            {
                RemoveAgent(_periodicTaskName);
            }

            _periodicTask = new PeriodicTask(_periodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            _periodicTask.Description = "This demonstrates a periodic task.";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(_periodicTask);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if DEBUG
                ScheduledActionService.LaunchForTest(_periodicTaskName, TimeSpan.FromSeconds(60));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    AppLogs.WriteWarning("StartBackgroundProcess", "Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    AppLogs.WriteWarning("StartBackgroundProcess", "The system prompts the user when the hard limit of periodic tasks has been reached.");
                }
            }
            catch (Exception ex)
            {
                AppLogs.WriteWarning("StartBackgroundProcess", ex.Message);
            }
        }
Пример #12
0
        private void LiveTileCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            usingLiveTile = (bool)((CheckBox)sender).IsChecked;
            UpdateLiveTileButton.IsEnabled = usingLiveTile;

            if (!(bool)((CheckBox)sender).IsChecked)
            {
                PeriodicTask tileUpdaterTask;
                string       taskName = "TileUpdateAgent";
                tileUpdaterTask = ScheduledActionService.Find(taskName) as PeriodicTask;

                if (tileUpdaterTask != null)
                {
                    ScheduledActionService.Remove(taskName);
                }
            }
        }
Пример #13
0
        private void AlarmButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (ScheduledActionService.Find("newalarm") != null)
            {
                ScheduledActionService.Remove("newalarm");
            }

            Alarm a = new Alarm("newalarm");

            a.Content = "Wira Setiawan Alarm";
            //a.Sound = new Uri("aaa.mp3", UriKind.Relative);
            a.BeginTime      = DateTime.Now.AddSeconds(15);
            a.ExpirationTime = DateTime.Now.AddDays(7);
            a.RecurrenceType = RecurrenceInterval.Daily;

            ScheduledActionService.Add(a);
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //ScheduledAgent

            var oldTask = ScheduledActionService.Find("ScheduledAgent") as PeriodicTask;

            if (oldTask != null)
            {
                ScheduledActionService.Remove("ScheduledAgent");
            }

            Microsoft.Phone.Scheduler.PeriodicTask task = new Microsoft.Phone.Scheduler.PeriodicTask("ScheduledAgent");
            task.Description = "Updates theme live tiles";

            ScheduledActionService.Add(task);
            ScheduledActionService.LaunchForTest("ScheduledAgent", TimeSpan.FromMilliseconds(1200));
        }
Пример #15
0
        private void ReminderButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (ScheduledActionService.Find("newreminder") != null)
            {
                ScheduledActionService.Remove("newreminder");
            }

            Reminder r = new Reminder("newreminder");

            r.Title          = "Reminder";
            r.Content        = "Wira Setiawan Reminder";
            r.BeginTime      = DateTime.Now.AddSeconds(15);
            r.ExpirationTime = DateTime.Now.AddDays(7);
            r.RecurrenceType = RecurrenceInterval.Daily;

            ScheduledActionService.Add(r);
        }
Пример #16
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            string       taskName = "GaurdApplication";
            PeriodicTask oldTask  = ScheduledActionService.Find(taskName) as PeriodicTask;

            if (oldTask != null)
            {
                ScheduledActionService.Remove(taskName);
            }


            PeriodicTask task = new PeriodicTask(taskName);

            task.Description = "Protect your Phone";
            ScheduledActionService.Add(task);
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(10));
        }
Пример #17
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Adding an agent...");
            task = ScheduledActionService.Find("TileUpdaterAgent") as PeriodicTask;
            if (task != null)
            {
                System.Diagnostics.Debug.WriteLine("Existing agent found, removing it.");
                ScheduledActionService.Remove("TileUpdaterAgent");
            }
            task             = new PeriodicTask("TileUpdaterAgent");
            task.Description = "Periodically does cache cleaning functions.";

            ScheduledActionService.Add(task);
            ScheduledActionService.LaunchForTest("TileUpdaterAgent", TimeSpan.FromSeconds(10));

            System.Diagnostics.Debug.WriteLine("Agent added (hopefully)");
        }
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            _periodicTask = ScheduledActionService.Find(_periodicTaskName) as PeriodicTask;

            if (_periodicTask != null)
            {
                ScheduledActionService.Remove(_periodicTaskName);
            }

            _periodicTask             = new PeriodicTask(_periodicTaskName);
            _periodicTask.Description = "testing";

            try
            {
                ScheduledActionService.Add(_periodicTask);

#if DEBUG_AGENT
                ScheduledActionService.LaunchForTest(_periodicTaskName, TimeSpan.FromSeconds(10));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }

            // Set the data context of the listbox control to the sample data
            //DataContext = App.ViewModel;

            //RecentReleaseList.ItemsSource = new List<string>();
            //RecentReleaseList.ItemsSource = _recentReleaseVersionInfo;
        }
Пример #19
0
        // Code, der beim Starten der Anwendung ausgeführt werden soll (z. B. über "Start")
        // Dieser Code wird beim Reaktivieren der Anwendung nicht ausgeführt
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            // Obtain a reference to the period task, if one exists
            var task = ScheduledActionService.Find("DataUpdate") as PeriodicTask;

            if (task != null)
            {
                ScheduledActionService.Remove("DataUpdate");
            }

            task = new PeriodicTask("DataUpdate")
            {
                Description = "Hier aktualisieren wir den Zähler auf der Kachel. Uuuunglaublich!"
            };

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(task);

                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if DEBUG
                ScheduledActionService.LaunchForTest("DataUpdate", TimeSpan.FromSeconds(30));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MainPage.ShowBgDisabBox = true;
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Пример #20
0
        private void StartPeriodicAgent()
        {
            // Obtain a reference to the period task, if one exists
            mPeriodicTask = ScheduledActionService.Find(TILE_NAME) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (mPeriodicTask != null)
            {
                RemoveAgent(TILE_NAME);
            }

            mPeriodicTask = new PeriodicTask(TILE_NAME);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            mPeriodicTask.Description = "將晴時多雲偶陣雨APP釘選到開始畫面後,會自動更新氣象資訊。";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(mPeriodicTask);
                // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if (DEBUG_AGENT)
                ScheduledActionService.LaunchForTest(TILE_NAME, TimeSpan.FromSeconds(60));
#endif
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    //MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Пример #21
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            var periodicTask = new PeriodicTask("PeriodicAgent")
            {
                // The description is required. This is the string that the user
                // will see in the background services Settings page on the device.
                Description = "Periodic task for updating the tile"
            };

            // If the agent is already registered with the system,
            // call the StopPeriodicAgent helper method.
            if (ScheduledActionService.Find(periodicTask.Name) != null)
            {
                ScheduledActionService.Remove("PeriodicAgent");
            }

            ScheduledActionService.Add(periodicTask);
        }
Пример #22
0
        private void DeleteButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            IEnumerable <Reminder> reminders = ScheduledActionService.GetActions <Reminder>();

            if (reminders != null)
            {
                foreach (Reminder re in reminders)
                {
                    string          reminderName = re.Name;
                    ScheduledAction sa           = ScheduledActionService.Find(reminderName);
                    if (sa != null)
                    {
                        ScheduledActionService.Remove(reminderName);
                        System.Diagnostics.Debug.WriteLine("Remove a reminder: " + reminderName);
                    }
                }
            }
        }
Пример #23
0
        private void StartPeriodicAgent()
        {
            PeriodicTask periodicTask = null;

            string periodicTaskName = "MyConferenceCallsTaskAgent";

            // Obtain a reference to the period task, if one exists
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (periodicTask != null)
            {
                if (periodicTask.IsEnabled && periodicTask.IsScheduled)
                {
                    return;
                }

                RemoveAgent(periodicTaskName);
            }

            periodicTask = new PeriodicTask(periodicTaskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            periodicTask.Description = AppResources.PeriodicTaskDescription;

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(periodicTask);

                // ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(10));
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    //MessageBox.Show("Background agents for this application have been disabled by the user.");
                    //agentsAreEnabled = false;
                }
            }
        }
Пример #24
0
        private async void agent_enabledisable(object sender, EventArgs e)
        {
            string message = String.Empty;

            if (!CurrentApp.LicenseInformation.ProductLicenses.ContainsKey(IAPs.IAP_PushNotification))
            {
                var agent = ScheduledActionService.Find(UpdateCreditAgent.AgentName);


                if (agent != null)
                {
                    WPUtils.RemoveAgent(UpdateCreditAgent.AgentName);
                    message = AppResources.BADisabled;
                }
                else
                {
                    WPUtils.StartPeriodicAgent(UpdateCreditAgent.AgentName);
                    message = AppResources.BAEnabled;
                }
            }
            else
            {
                var hub     = WPUtils.NotificationGet();
                var channel = HttpNotificationChannel.Find(Constants.CnName);

                if (channel != null && channel.ConnectionStatus == ChannelConnectionStatus.Connected)
                {
                    channel.Close();
                    await hub.UnregisterNativeAsync();

                    message = AppResources.BADisabled;
                }
                else
                {
                    await WPUtils.PushNotificationSetUp(this);

                    return;
                }
            }

            new ToastPrompt {
                Message = message
            }.Show();
        }
Пример #25
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            agentMessage.Text = ((App)Application.Current).AgentStatus;

            ScheduledAgent.UpdateDefaultTile();

            List <ScheduledAction> items = new List <ScheduledAction>();

            var notifications = ScheduledActionService
                                .GetActions <ScheduledNotification>()
                                .OrderBy((item) => item.BeginTime);

            foreach (ScheduledNotification notification in notifications)
            {
                ScheduledAction item = ScheduledActionService.Find(notification.Name);
                items.Add(item);
            }
            notificationList.ItemsSource = items;
        }
Пример #26
0
        private void TogglePush_Checked(object sender, RoutedEventArgs e)
        {
            if (ScheduledActionService.Find("LatestChatty") == null)
            {
                PeriodicTask task = new PeriodicTask("LatestChatty");
                task.Description = "Periodically checks for replies to threads you posted in LatestChatty.  Updates LiveTile with results.";

                task.ExpirationTime = DateTime.Now.AddDays(14);
                try
                {
                    ScheduledActionService.Add(task);
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("Can't schedule agent; either there are too many other agents scheduled or you have disabled this agent in Settings.");
                    return;
                }
            }
        }
Пример #27
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            ignoreCheckBoxEvents = true;

            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

            if (periodicTask != null)
            {
                PeriodicStackPanel.DataContext = periodicTask;
            }

            resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask;
            if (resourceIntensiveTask != null)
            {
                ResourceIntensiveStackPanel.DataContext = resourceIntensiveTask;
            }

            ignoreCheckBoxEvents = false;
        }
Пример #28
0
        private void RegisterBackgroundTask()
        {
            var taskName = "taskname";
            var oldTask  = ScheduledActionService.Find(taskName) as PeriodicTask;

            if (oldTask != null)
            {
                ScheduledActionService.Remove(taskName);
            }
            PeriodicTask task = new PeriodicTask(taskName);

            task.Description = "task description";

            //at this point there are no tasks in background tasks of phone settings
            ScheduledActionService.Add(task);
            #if (DEBUG_AGENT)
            ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(60));
            #endif
        }
Пример #29
0
        private void StartPeriodicAgent()
        {
            var taskName = "MyTask";

            // Obtain a reference to the period task, if one exists
            var oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;

            // If the task already exists and background agents are enabled for the
            // application, you must remove the task and then add it again to update
            // the schedule
            if (oldTask != null)
            {
                RemoveAgent(taskName);
            }

            PeriodicTask task = new PeriodicTask(taskName);

            // The description is required for periodic agents. This is the string that the user
            // will see in the background services Settings page on the device.
            task.Description = "Updates LiveTile Counts for Pinned Task Lists.";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                ScheduledActionService.Add(task);
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background agents for this application have been disabled by the user.");
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    // No user action required. The system prompts the user when the hard limit of periodic tasks has been reached.
                }
            }
            catch (SchedulerServiceException)
            {
                // No user action required.
            }
        }
Пример #30
0
        private void btnAddTile_Click(object sender, RoutedEventArgs e)
        {
            //add tile
            //start background agent
            PeriodicTask periodicTask = new PeriodicTask("PeriodicAgent");

            periodicTask.Description    = "Live Tile Update - TileProject";
            periodicTask.ExpirationTime = System.DateTime.Now.AddDays(1);

            // If the agent is already registered with the system,
            if (ScheduledActionService.Find(periodicTask.Name) != null)
            {
                ScheduledActionService.Remove("PeriodicAgent");
            }

            ScheduledActionService.Add(periodicTask);

            ScheduledActionService.LaunchForTest(periodicTask.Name, TimeSpan.FromSeconds(10));
        }