private void ApplicationBarSaveButton_Click(object sender, EventArgs e)
        {
            DateTime beginTime = (DateTime)alarmTimePicker.Value;

            if (beginTime < DateTime.Now)
            {
                beginTime = beginTime.AddDays(1);
            }
            DateTime expirationTime = beginTime.AddSeconds(1);

            RecurrenceInterval recurrence = RecurrenceInterval.None;

            Alarm alarm = new Alarm(ALARM_NAME);

            alarm.Content        = ALARM_CONTENT;
            alarm.Sound          = new Uri("/Assets/Sounds/Alarm-06.wma", UriKind.Relative);
            alarm.BeginTime      = beginTime;
            alarm.ExpirationTime = expirationTime;
            alarm.RecurrenceType = recurrence;

            if (ScheduledActionService.Find(ALARM_NAME) != null)
            {
                ScheduledActionService.Remove(ALARM_NAME);
            }
            ScheduledActionService.Add(alarm);

            updateUI();
        }
Example #2
0
        // Exemple de code pour la conception d'une ApplicationBar localisée
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Définit l'ApplicationBar de la page sur une nouvelle instance d'ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Crée un bouton et définit la valeur du texte sur la chaîne localisée issue d'AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Crée un nouvel élément de menu avec la chaîne localisée d'AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}

        // Manage the reminder task
        private void StartPeriodicTask()
        {
            Debug.WriteLine("Trying to open background agent...");
            PeriodicTask periodicTask = new PeriodicTask("RemindAgent");

            periodicTask.Description = "A task reminding the user of its events";
            try
            {
                ScheduledActionService.Add(periodicTask);
                ScheduledActionService.LaunchForTest("RemindAgent", TimeSpan.FromSeconds(3));
                Debug.WriteLine("Open the background agent success");
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("exists already"))
                {
                    Debug.WriteLine("Since then the background agent success is already running");
                }
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    Debug.WriteLine("Background processes for this application has been prohibited");
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    Debug.WriteLine("You open the daemon has exceeded the hardware limitations");
                }
                else
                {
                    Debug.WriteLine("Launching the Agent failed: unknown InvalidOperationException occured.\n" + exception.Message);
                }
            }
            catch (SchedulerServiceException)
            {
            }
        }
Example #3
0
        private void EnableLiveTileUpdateTask(object sender, RoutedEventArgs e)
        {
            _periodicTask = ScheduledActionService.Find(PeriodicTaskName) as PeriodicTask;

            if (_periodicTask != null)
            {
                RemoveAgent(PeriodicTaskName);
            }

            _periodicTask = new PeriodicTask(PeriodicTaskName);

            _periodicTask.Description = "JEVGENIDOTNET live tile update task";

            try
            {
                ScheduledActionService.Add(_periodicTask);

                #if DEBUG
                ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(30));
                #endif

                btnDisableLiveTileUpdate.IsEnabled = true;
                btnEnableLiveTileUpdate.IsEnabled  = false;
            }
            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.");
                }
            }
        }
Example #4
0
        private void StartResourceIntensiveAgent()
        {
            resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask;

            // If the task already exists and the IsEnabled property is false, background
            // agents have been disabled by the user
            if (resourceIntensiveTask != null && !resourceIntensiveTask.IsEnabled)
            {
                MessageBox.Show("Background agents for this application have been disabled by the user.");
                return;
            }

            // 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 && resourceIntensiveTask.IsEnabled)
            {
                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.";
            ScheduledActionService.Add(resourceIntensiveTask);

            ResourceIntensiveStackPanel.DataContext = resourceIntensiveTask;

            // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if (DEBUG_AGENT)
            ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(60));
#endif
        }
Example #5
0
        public void CreatePeriodicTask(string name)
        {
            var task = new PeriodicTask(name)
            {
                Description    = "Live tile updater for Happenings",
                ExpirationTime = DateTime.Now.AddDays(14)
            };

            RemovePeriodicTask(task.Name);

            try
            {
                // Can only be called when application is running in foreground
                ScheduledActionService.Add(task);
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show(AppResources.BackgroundAgentsDisabled);
                }
                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.
                }
            }

            //#if DEBUG
            //ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
            //#endif
        }
        public void Start()
        {
            PeriodicTask periodicTask = new PeriodicTask(Constants.SETTINGS.LIVE_TILE_AGENT);

            WP_to_WP.UI.Services.UiSettings Settings = new WP_to_WP.UI.Services.UiSettings();

            periodicTask.Description    = Settings.AppName() + " Task";
            periodicTask.ExpirationTime = System.DateTime.Now.AddDays(10);

            if (Exists())
            {
                ScheduledActionService.Remove(Constants.SETTINGS.LIVE_TILE_AGENT);
            }

            try
            {
                ScheduledActionService.Add(periodicTask);

#if DEBUG
                ScheduledActionService.LaunchForTest(Constants.SETTINGS.LIVE_TILE_AGENT, TimeSpan.FromSeconds(60));
#endif
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("BNS Error: The action is disabled"))
                {
                    // MessageBox.Show("Background agents for this application have been disabled by the user.");
                }
            }
        }
Example #7
0
        private ScheduledAction AddBackgroundTask()
        {
            // Start background agent
            PeriodicTask periodicTask = new PeriodicTask(TASK_AGENT_NAME);

            periodicTask.Description = "Winsana background task";

            // Place the call to Add in a try block in case the user has disabled agents.
            try
            {
                // only can be called when application is running in foreground.
                ScheduledActionService.Add(periodicTask);

                return(periodicTask);
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("BNS Error: The action is disabled"))
                {
                    Debug.WriteLine("Unable to start service agent");
                }
                if (ex.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    Debug.WriteLine("Unable to start service agent");
                }
            }
            catch (SchedulerServiceException ex)
            {
                Debug.WriteLine("Unable to start service agent");
            }

            return(null);
        }
Example #8
0
        /// <summary>
        /// Starts the push notification task.
        /// </summary>
        public void InitHttpNotificationTask()
        {
            // Obtain a reference to the existing task, if any.
            VoipHttpIncomingCallTask incomingCallTask = ScheduledActionService.Find(incomingCallTaskName) as VoipHttpIncomingCallTask;

            if (incomingCallTask != null)
            {
                if (incomingCallTask.IsScheduled == false)
                {
                    // The incoming call task has been unscheduled due to OOM or throwing an unhandled exception twice in a row
                    ScheduledActionService.Remove(incomingCallTaskName);
                }
                else
                {
                    // The incoming call task has been scheduled and is still scheduled so there is nothing more to do
                    return;
                }
            }

            try
            {
                incomingCallTask             = new VoipHttpIncomingCallTask(incomingCallTaskName, pushChannelName);
                incomingCallTask.Description = "Linphone incoming call task";
                ScheduledActionService.Add(incomingCallTask);
            }
            catch (Exception)
            {
            }
        }
Example #9
0
        void StartPeriodicAgent()
        {
            isEnabled = true;
            string periodicTaskName = "PeriodicAgent";

            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
            if (periodicTask != null)
            {
                RemoveAgent(periodicTaskName);
            }

            periodicTask             = new PeriodicTask(periodicTaskName);
            periodicTask.Description = "Location Periodic Task";

            try
            {
                ScheduledActionService.Add(periodicTask);
                //MessageBox.Show("Started");
#if DEBUG_AGENT
                ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
            }
            catch (InvalidOperationException exception)
            {
                //MessageBox.Show(exception.Message);
                isEnabled = false;
            }
            catch (SchedulerServiceException) { }
        }
Example #10
0
        static public void TaskStart(bool once = false)
        {
            PeriodicTask Task = ScheduledActionService.Find("SimpleTasks_Task") as PeriodicTask;

            if (Task != null)
            {
                if (once)
                {
                    return;
                }
                try
                {
                    ScheduledActionService.Remove("SimpleTasks_Task");
                }
                catch (Exception)
                {
                }
            }

            Task             = new PeriodicTask("SimpleTasks_Task");
            Task.Description = "Task agent for SimpleTasks";

            try
            {
                ScheduledActionService.Add(Task);
                #if (DEBUG)
                ScheduledActionService.LaunchForTest("SimpleTasks_Task", TimeSpan.FromSeconds(30));
                #endif
            }
            catch (Exception)
            {
            }
        }
Example #11
0
        public static void AddAlarm(Entry entry)
        {
            try
            {
                Alarm alarm = new Alarm(MetroCalendarAlarm + entry.EntryId);
                alarm.Content        = entry.Subject;
                alarm.Sound          = RingTone(entry.RingTone);
                alarm.BeginTime      = entry.AlarmTime;
                alarm.ExpirationTime = entry.ExpirationTime;
                alarm.RecurrenceType = Recurrence(entry.RepeatType);

                ScheduledActionService.Add(alarm);
            }
            catch (InvalidOperationException ex)
            {
                Debug.WriteLine(ex.Message);
            }
            catch (SchedulerServiceException sex)
            {
                Debug.WriteLine(sex.Message);
            }
            catch (ArgumentOutOfRangeException aore)
            {
                Debug.WriteLine(aore.Message);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Example #12
0
        void StartBackgroundAgent()
        {
            try
            {
                if (IsLowMemDevice)
                {
                    return;
                }
                var taskName = "BinDays.Agent";

                if (ScheduledActionService.Find(taskName) is PeriodicTask)
                {
                    ScheduledActionService.Remove(taskName);
                }

                ScheduledActionService.Add(new PeriodicTask(taskName)
                {
                    Description = "Updates whether it's a recycling week or not"
                });
            }
            catch
            {
            }

            //ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(15));
        }
Example #13
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";
            //string taskName = "AroundMeLockScreenChangerTask";

            PeriodicTask oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;

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

            // IMPORTANT: You'll get an error in the very next line of code
            // unless you add this to the WMAppManifest.xml beneath <DefaultTask>
            // in the <Tasks> section:

            /*
             *    <ExtendedTask Name="AroundMeLockScreenChangerTask">
             *      <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="AroundMeLockScreenChanger" Source="AroundMe.Scheduler" Type="AroundMe.Scheduler.ScheduledAgent" />
             *    </ExtendedTask>
             */

            PeriodicTask task = new PeriodicTask(taskName);

            task.Description = "Change lockscreen wallpaper";

            ScheduledActionService.Add(task);

            //ScheduledActionService.LaunchForTest(task.Name,TimeSpan.FromSeconds(10));
        }
        private bool Start()
        {
            bool result = false;

            try
            {
                PeriodicTask task = new PeriodicTask(TaskName);
                task.Description = "Service to update Trivia Buff live tile";
                ScheduledActionService.Add(task);
                result = true;
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show(
                    AppResources.ErrorCouldNotEnableLiveTileDescription,
                    AppResources.ErrorCouldNotEnableLiveTileTitle,
                    MessageBoxButton.OK);
            }
            catch (Exception)
            {
                // still show the main UI
            }

            return(result);
        }
Example #15
0
        private void StartPeriodicAgent()
        {
            periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
            if (periodicTask != null && !periodicTask.IsEnabled)
            {
                MessageBox.Show("Background agents for this application have been disabled by the user.");
                return;
            }
            if (periodicTask != null && periodicTask.IsEnabled)
            {
                RemoveAgent(periodicTaskName);
            }
            if (!(App.Current as App).Setting.IsLiveChecked)
            {
                return;
            }

            periodicTask             = new PeriodicTask(periodicTaskName);
            periodicTask.Description = "設定画面でライブタイルの表示をランダムにした際、目標をランダム表示させます。";
            ScheduledActionService.Add(periodicTask);

#if (DEBUG)
            ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
        }
Example #16
0
        private static void StartPeriodicAgent()
        {
            string       periodicTaskName = "SmartGuardPeriodicAgent";
            PeriodicTask periodicTask     = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

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

            periodicTask             = new PeriodicTask(periodicTaskName);
            periodicTask.Description = AppResources.SmartGuardBackgroundAgent;

            #region Try Catch Finally

            try
            {
                ScheduledActionService.Add(periodicTask);
            }

            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                }

                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                }
            }
            catch (SchedulerServiceException)
            { }
            #endregion Try Catch Finally
        }
Example #17
0
        public void Remind(DateTime dateTime, string title, string message)
        {
            string param1Value = title;
            string param2Value = message;
            string queryString = "";

            if (param1Value != "" && param2Value != "")
            {
                queryString = "?param1=" + param1Value + "&param2=" + param2Value;
            }
            else if (param1Value != "" || param2Value != "")
            {
                queryString = (param1Value != null) ? "?param1=" + param1Value : "?param2=" + param2Value;
            }
            Microsoft.Phone.Scheduler.Reminder reminder = new Microsoft.Phone.Scheduler.Reminder("ServiceReminder");
            reminder.Title          = title;
            reminder.Content        = message;
            reminder.BeginTime      = dateTime;
            reminder.ExpirationTime = dateTime.AddDays(1);
            reminder.RecurrenceType = RecurrenceInterval.None;
            reminder.NavigationUri  = new Uri("/MainPage.xaml" + queryString, UriKind.Relative);
            ;

            // Register the reminder with the system.
            ScheduledActionService.Add(reminder);
        }
Example #18
0
        private void StartResourceIntensiveAgent()
        {
            resourceIntensiveTask = ScheduledActionService.Find(_taskName) as ResourceIntensiveTask;

            // If the task already exists and the IsEnabled property is false, background
            // agents have been disabled by the user
            if (resourceIntensiveTask != null && !resourceIntensiveTask.IsEnabled)
            {
                return;
            }

            // 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 && resourceIntensiveTask.IsEnabled)
            {
                RemoveAgent(_taskName);
            }

            resourceIntensiveTask = new ResourceIntensiveTask(_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.

            resourceIntensiveTask.Description = _taskDescription;
            ScheduledActionService.Add(resourceIntensiveTask);
        }
Example #19
0
        public static void StartTaskAgent()
        {
            PeriodicTask task =
                ScheduledActionService.Find(TaskName) as PeriodicTask;

            if (task != null)
            {
                RemoveAgent(TaskName);
            }

            task             = new PeriodicTask(TaskName);
            task.Description = "Screen Tile description";

            try
            {
                ScheduledActionService.Add(task);

#if (DEBUG_AGENT)
                ScheduledActionService.LaunchForTest(TaskName, TimeSpan.FromSeconds(20));
#endif
            }
            catch (InvalidOperationException e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Example #20
0
        public async void StartLockScreenImageChange()
        {
            var photolen = IsolatedStorageSettings.ApplicationSettings["navchk"] as string;

            if (photolen != "0")
            {
                var taskName = "my task";
                if (ScheduledActionService.Find(taskName) != null)
                {
                    ScheduledActionService.Remove(taskName);
                }
                var periodicTask = new PeriodicTask(taskName)
                {
                    Description = "some desc"
                };
                try
                {
                    ScheduledActionService.Add(periodicTask);
                    ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(10));
                }
                catch
                {
                    //handle
                }
            }
        }
        private void StartPeriodicTask()
        {
            PeriodicTask periodicTask = new PeriodicTask("DatingDiaryTask");

            periodicTask.Description = "Are presenting a periodic task";

            try
            {
                ScheduledActionService.Add(periodicTask);
                ScheduledActionService.LaunchForTest("DatingDiaryTask", TimeSpan.FromSeconds(3));
                MessageBox.Show("Open the background agent success");
            }
            catch (InvalidOperationException exception)
            {
                if (exception.Message.Contains("exists already"))
                {
                    MessageBox.Show("Since then the background agent success is already running");
                }
                if (exception.Message.Contains("BNS Error: The action is disabled"))
                {
                    MessageBox.Show("Background processes for this application has been prohibited");
                }
                if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
                {
                    MessageBox.Show("You open the daemon has exceeded the hardware limitations");
                }
            }
            catch (SchedulerServiceException)
            {
            }
        }
        private void AddReminderButton_Click(object sender, RoutedEventArgs e)
        {
            var reminderDtTm = new DateTime(dpReminderDate.Value.Value.Year, dpReminderDate.Value.Value.Month, dpReminderDate.Value.Value.Day,
                                            tpReminderTime.Value.Value.Hour, tpReminderTime.Value.Value.Minute, tpReminderTime.Value.Value.Second);

            if (DateTime.Now > reminderDtTm)
            {
                App.ToastMe(StringResources.RVPage_Reminders_Messages_ReminderPastNow);
                return;
            }

            var s = string.Format(StringResources.RVPage_Reminders_ReminderTitle, App.ViewModel.ReturnVisitData.FullName);


            var r = new Microsoft.Phone.Scheduler.Reminder(Guid.NewGuid().ToString())
            {
                Content       = tbReminderNotes.Text,
                BeginTime     = reminderDtTm,
                Title         = s,
                NavigationUri = NavigationService.CurrentSource
            };

            ScheduledActionService.Add(r);
            tbReminderNotes.Text = "";
            App.ToastMe(StringResources.RVPage_Reminders_ReminderAdded);
            RefreshRemindersList();
        }
Example #23
0
        /// <summary>
        /// 启动
        /// </summary>
        public static void Start()
        {
            if (!AppSetting.IsScheduledAgent)
            {
                return;
            }

            if (isAgentOn)
            {
                return;
            }
            Stop();

            var periodicTask = new PeriodicTask(Params.PeriodicTaskName);

            periodicTask.Description = "腾讯微博客户端Altman后台任务,用于帮助用户检查是否有新微博,您可以在应用设置选项中将其关闭或者在手机的后台任务界面停止它。";

            try
            {
                ScheduledActionService.Add(periodicTask);
                //ScheduledActionService.LaunchForTest(Common.Params.PeriodicTaskName, TimeSpan.FromSeconds(2));
                isAgentOn = true;
            }
            catch { isAgentOn = false; }
        }
 private void EnsureScheduledUpdate()
 {
     this._periodicTask = ScheduledActionService.Find(this._periodicTaskName) as PeriodicTask;
     if (this._periodicTask != null)
     {
         try
         {
             ScheduledActionService.Remove(this._periodicTaskName);
         }
         catch
         {
         }
     }
     this._periodicTask                = new PeriodicTask(this._periodicTaskName);
     this._periodicTask.Description    = "VK LiveTile update agent.";
     this._periodicTask.ExpirationTime = DateTime.Now.AddDays(14.0);
     try
     {
         ScheduledActionService.Add((ScheduledAction)this._periodicTask);
     }
     catch (InvalidOperationException ex)
     {
         ex.Message.Contains("BNS Error: The action is disabled");
         ex.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added.");
     }
     catch
     {
     }
 }
Example #25
0
 public static void SetReminder(RecipeDataItem item)
 {
     if (!IsScheduled(item.UniqueId))
     {
         Microsoft.Phone.Scheduler.Reminder reminder = new Microsoft.Phone.Scheduler.Reminder(item.UniqueId);
         reminder.Title   = item.Title;
         reminder.Content = "Have you finished cooking?";
         if (System.Diagnostics.Debugger.IsAttached)
         {
             reminder.BeginTime = DateTime.Now.AddMinutes(1);
         }
         else
         {
             reminder.BeginTime = DateTime.Now.Add(TimeSpan.FromMinutes(Convert.ToDouble(item.PrepTime)));
         }
         reminder.ExpirationTime = reminder.BeginTime.AddMinutes(5);
         reminder.RecurrenceType = RecurrenceInterval.None;
         reminder.NavigationUri  = new Uri("/RecipeDetailPage.xaml?ID=" + item.UniqueId + "&GID=" + item.Group.UniqueId, UriKind.Relative);
         ScheduledActionService.Add(reminder);
     }
     else
     {
         var schedule = ScheduledActionService.Find(item.UniqueId);
         ScheduledActionService.Remove(schedule.Name);
     }
 }
Example #26
0
        /// <summary>
        /// http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942(v=vs.105).aspx
        ///
        /// </summary>
        private static void TryInitBackgroundTask()
        {
            try {
                var task  = ScheduledActionService.Find(BackgroundTaskName) as PeriodicTask;
                var found = task != null;
                if (!found)
                {
                    task = new PeriodicTask(BackgroundTaskName);
                }
                // shown in WP8 under Settings -> applications -> background tasks -> MusicPimp
                task.Description    = "Updates the live tiles with album covers if available. Also updates the lock screen background if enabled.";
                task.ExpirationTime = DateTime.Now.AddDays(14);
                try {
                    if (found)
                    {
                        ScheduledActionService.Remove(BackgroundTaskName);
                    }
                    ScheduledActionService.Add(task);
                } catch (InvalidOperationException) {
                    /// If you attempt to add a periodic background agent when the device’s limit has been exceeded,
                    /// the call to Add(ScheduledAction) will throw an InvalidOperationException.
                    ///
                    /// If agents have been disabled for your app, attempts to register an agent using the
                    /// Add(ScheduledAction) method of the ScheduledActionService will throw an InvalidOperationException.
                } catch (SchedulerServiceException) {
                    /// A SchedulerServiceException can also be thrown when adding a task, for example,
                    /// if the device has just booted and the Scheduled Action Service hasn’t started yet.
                }
            } catch (Exception) { }


            //#if DEBUG_AGENT
            //                ScheduledActionService.LaunchForTest(BackgroundTaskName, TimeSpan.FromSeconds(10));
            //#endif
        }
Example #27
0
        public void startBackground()
        {
            pollOut = new PeriodicTask("ScheduledAgent");


            try
            {
                pollOut = ScheduledActionService.Find("PollOut") as PeriodicTask;
                if (pollOut != null)
                {
                    ScheduledActionService.Remove("PollOut");
                }

                pollOut             = new PeriodicTask("PollOut");
                pollOut.Description = "waiting to shut down or wake your pc";

                ScheduledActionService.Add(pollOut);

                ScheduledActionService.LaunchForTest("PollOut", TimeSpan.FromSeconds(10));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Example #28
0
        /// <summary>
        /// Creates or renews the periodic agent on the scheduler.
        /// </summary>
        /// <returns>Whether the periodic agent is created or not</returns>
        public bool StartPeriodicAgent()
        {
            periodicDownload = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
            bool wasAdded = true;

            // If the task already exists and the IsEnabled property is false, then background
            // agents have been disabled by the user.
            if (periodicDownload != null && !periodicDownload.IsEnabled)
            {
                // Can't add the agent. Return false!
                wasAdded = false;
            }

            // If the task already exists and background agents are enabled for the
            // application, then remove the agent and add again to update the scheduler.
            if (periodicDownload != null && periodicDownload.IsEnabled)
            {
                ScheduledActionService.Remove(periodicTaskName);
            }

            periodicDownload             = new PeriodicTask(periodicTaskName);
            periodicDownload.Description = "Allows FeedCast to download new articles on a regular schedule.";
            ScheduledActionService.Add(periodicDownload);

            // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if (DEBUG_AGENT)
            ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
            return(wasAdded);
        }
Example #29
0
        public static void StartPeriodicAgent()
        {
            string       periodicTaskName = "OcellPeriodicTask";
            PeriodicTask periodicTask     = null;

            try
            {
                periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
            }
            catch (Exception)
            {
            }

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

            periodicTask             = new PeriodicTask(periodicTaskName);
            periodicTask.Description = "Updates live tile, sends scheduled tweets.";

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                try
                {
                    ScheduledActionService.Add(periodicTask);
                    ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(30));
                }
                catch (Exception)
                {
                }
            });
        }
        private void simpan_Click(object sender, EventArgs e)
        {
            DateTime saiki = DateTime.Now;

            if (timeX.Value.Value <= saiki)
            {
                MessageBox.Show("Pastikan jam sudah di set lebih dari jam sekarang");
            }
            else
            {
                string   reminderName = Guid.NewGuid().ToString();
                Reminder reminder     = new Reminder(reminderName);
                reminder.Title   = this.txtTitle.Text;
                reminder.Content = this.txtContent.Text;

                reminder.BeginTime      = new DateTime(saiki.Year, saiki.Month, saiki.Day, timeX.Value.Value.Hour, timeX.Value.Value.Minute, timeX.Value.Value.Second);
                reminder.RecurrenceType = RecurrenceInterval.Daily;
                reminder.ExpirationTime = reminder.BeginTime.AddSeconds(5.0);
                reminder.RecurrenceType = RecurrenceInterval.Daily;

                ScheduledActionService.Add(reminder);

                this.NavigationService.GoBack();
            }
        }