private void RemoveAlarm() { List <ScheduledNotification> notifications = ScheduledActionService.GetActions <ScheduledNotification>() as List <ScheduledNotification>; if (notifications.Count > 0) { ScheduledNotification al = notifications.First(r => r.Name == "Sunlight"); ScheduledActionService.Remove(al.Name); } }
public Recordatorios() { InitializeComponent(); IEnumerable <Reminder> recordatorios = ScheduledActionService.GetActions <Reminder>(); recordatorios = recordatorios.OrderByDescending(x => x.BeginTime); lbRecordatorios.ItemsSource = recordatorios; }
public static void RemoveAll() { foreach (Reminder reminder in ScheduledActionService.GetActions <Reminder>()) { try { ScheduledActionService.Remove(reminder.Name); } catch { } } }
protected void DisplayScheduledNotifications() { var items = new List <ScheduledAction>(); var notifications = ScheduledActionService. GetActions <ScheduledNotification>(); foreach (var notification in notifications) { var item = ScheduledActionService.Find(notification.Name); items.Add(item); } notificationList.ItemsSource = items; }
public void Schedule() { foreach (var action in ScheduledActionService.GetActions <Reminder>()) { ScheduledActionService.Remove(action.Name); } foreach (var lembrete in _lembretes.Where(lem => lem.Inicio > DateTime.Now)) { var periodicTask = ScheduledActionService.Find(lembrete.LembreteName) as Reminder; try { if (periodicTask != null) { ScheduledActionService.Remove(lembrete.LembreteName); } periodicTask = new Reminder(lembrete.LembreteName) { Title = "Meu Ponto", Content = lembrete.Mensagem, BeginTime = lembrete.Inicio, ExpirationTime = lembrete.Fim, RecurrenceType = RecurrenceInterval.None }; ScheduledActionService.Add(periodicTask); } 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 ex) { // No user action required. MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public static void RemoveAll(string name) { foreach (Reminder reminder in ScheduledActionService.GetActions <Reminder>()) { try { if (reminder.Name.StartsWith(name)) { ScheduledActionService.Remove(reminder.Name); } } catch { } } }
public void StartPeriodicAgent() { // is old tasks are running, remove them foreach (PeriodicTask pt in ScheduledActionService.GetActions <PeriodicTask>()) { ScheduledActionService.Remove(pt.Name); } // create a new task _periodicTask = new PeriodicTask(PeriodicTaskName) { Description = "This is the Fuel application update agent.", ExpirationTime = DateTime.Now.AddDays(14) }; // load description from localized strings // set expiration days try { // add thas to scheduled action service ScheduledActionService.Add(_periodicTask); // debug, so run in every 10 secs #if (DEBUG) ScheduledActionService.LaunchForTest(PeriodicTaskName, TimeSpan.FromSeconds(10)); System.Diagnostics.Debug.WriteLine("Periodic task is started: " + _periodicTask); #endif } catch (InvalidOperationException exception) { if (exception.Message.Contains("BNS Error: The action is disabled")) { #if (DEBUG) System.Diagnostics.Debug.WriteLine("BNS Error: The action is disabled"); #endif // load error text from localized strings } if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added.")) { #if (DEBUG) System.Diagnostics.Debug.WriteLine("BNS Error: The maximum number of ScheduledActions of this type have already been added."); #endif // 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. } //update tile right now Tools.Tools.UpdateLiveTile(); }
public static void ClearAllRemindersOnUpgrade() { var reminders = ScheduledActionService.GetActions <Reminder>().ToArray(); //delete reminders if (reminders.Length <= 0) { return; } foreach (var reminder in reminders.Where(reminder => ScheduledActionService.Find(reminder.Name) != null)) { ScheduledActionService.Remove(reminder.Name); } }
private void recordar() { string longitud = string.Format("{0:n3}", double.Parse(txtlongitud.Text)); string latitud = string.Format("{0:n3}", double.Parse(txtlatitud.Text)); string revisar = string.Format("{0} / {1}", longitud, latitud); IEnumerable <Reminder> recordatorios = ScheduledActionService.GetActions <Reminder>(); foreach (Reminder item in recordatorios) { if (revisar == item.Content) { MessageBox.Show(string.Format("Estas cerca de un sitio para recordar {0}", item.Content)); } } }
/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// </remarks> protected override void OnInvoke(ScheduledTask task) { DateTime now = DateTime.Now; var notifications = ScheduledActionService. GetActions <ScheduledNotification>(); foreach (var notification in notifications) { if (notification.IsScheduled == false || notification.ExpirationTime < now) { ScheduledActionService.Remove(notification.Name); } } //NotifyComplete(); }
public static List <Reminder> GetAll(string name) { List <Reminder> reminders = new List <Reminder>(); foreach (Reminder reminder in ScheduledActionService.GetActions <Reminder>()) { try { if (reminder.Name.StartsWith(name)) { reminders.Add(reminder); } } catch { } } return(reminders); }
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); } } } }
private void ResetItemsList() { notifications = ScheduledActionService.GetActions <ScheduledNotification>(); if (notifications.Count <ScheduledNotification>() > 0) { EmptyTextBlock.Visibility = Visibility.Collapsed; } else { EmptyTextBlock.Visibility = Visibility.Visible; } // Update the ReminderListBox with the list of reminders. // A full MVVM implementation can automate this step. NotificationListBox.ItemsSource = notifications; }
public static int AlarmCount() { int alarmCount = 0; List <Alarm> alarms = (List <Alarm>)ScheduledActionService.GetActions <Alarm>(); foreach (Alarm alarm in alarms) { if (alarm.Name.Contains(MetroCalendarAlarm)) { if (alarm.IsEnabled && alarm.IsScheduled) { ++alarmCount; } } } return(alarmCount); }
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; }
private void ResetItemsList() { // Use GetActions to retrieve all of the scheduled actions // stored for this application. The type <Reminder> is specified // to retrieve only Reminder objects. reminders = ScheduledActionService.GetActions <Reminder>(); // If there are 1 or more reminders, hide the "no reminders" // TextBlock. IF there are zero reminders, show the TextBlock. if (reminders.Count <Reminder>() > 0) { EmptyTextBlock.Visibility = Visibility.Collapsed; } else { EmptyTextBlock.Visibility = Visibility.Visible; } // Update the ReminderListBox with the list of reminders. // A full MVVM implementation can automate this step. ReminderListBox.ItemsSource = reminders; }
//*********************************************************************************************************************** //----------------------------------------------------------------------------------------------------------------------- #endregion //*********************************************************************************************************************** //*********************************************************************************************************************** #region // Section de Gestion de l'Agent //----------------------------------------------------------------------------------------------------------------------- //*********************************************************************************************************************** /// <summary> /// Contrôle le statut de l'agent. /// </summary> //----------------------------------------------------------------------------------------------------------------------- public static void CheckScheduledAgentStatus() { //------------------------------------------------------------------------------------------------------------------- try { //--------------------------------------------------------------------------------------------------------------- foreach (var Task in ScheduledActionService.GetActions <PeriodicTask> ()) { ScheduledActionService.Remove(Task.Name); } //--------------------------------------------------------------------------------------------------------------- } //------------------------------------------------------------------------------------------------------------------- catch {} //------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------- try { //--------------------------------------------------------------------------------------------------------------- Instance.ScheduledAgentActive = false; if (ScheduledAgent.TileIsActive || ScheduledAgent.ToastDelay > 0) { var PeriodicTask = new PeriodicTask(AppInfos.SchedulerName); PeriodicTask.Description = AppInfos.SchedulerDescription; ScheduledActionService.Add(PeriodicTask); Instance.ScheduledAgentActive = PeriodicTask.IsEnabled && PeriodicTask.IsScheduled; } //--------------------------------------------------------------------------------------------------------------- } //------------------------------------------------------------------------------------------------------------------- catch {} //------------------------------------------------------------------------------------------------------------------- }
/// <summary> /// Clears the application live tile /// </summary> public void cancelAll(string jsonArgs) { // Application Tile is always the first Tile, even if it is not pinned to Start. ShellTile AppTile = ShellTile.ActiveTiles.First(); if (AppTile != null) { // Set the properties to update for the Application Tile // Empty strings for the text values and URIs will result in the property being cleared. FlipTileData TileData = new FlipTileData { Count = 0, BackTitle = "", BackContent = "", WideBackContent = "", SmallBackgroundImage = new Uri("appdata:Background.png"), BackgroundImage = new Uri("appdata:Background.png"), WideBackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileLarge.png", UriKind.Relative), }; // Update the Application Tile AppTile.Update(TileData); // Remove all alarms/reminders try { List <ScheduledNotification> notifications = ScheduledActionService.GetActions <ScheduledNotification>().ToList(); foreach (ScheduledNotification notification in notifications) { ScheduledActionService.Remove(notification.Name); } } catch (Exception ex) { } } DispatchCommandResult(); }
public static void InitHttpNotificationTask() { try { // Obtain a reference to the existing task, if any. var 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; } } // Create a new incoming call task. incomingCallTask = new VoipHttpIncomingCallTask(incomingCallTaskName, Constants.ToastNotificationChannelName); incomingCallTask.Description = "Incoming call task"; foreach (var action in ScheduledActionService.GetActions <ScheduledAction>()) { ScheduledActionService.Remove(action.Name); } ScheduledActionService.Add(incomingCallTask); } catch (Exception ex) { Telegram.Logs.Log.Write("InitHttpNotificationTask ScheduledActionService.Add exception\n" + ex); } }
void buildReminders() { var existingReminders = ScheduledActionService.GetActions <Reminder>(); //check removed reminders foreach (var existingReminder in existingReminders) { try { Guid reminderId = new Guid(existingReminder.Name); var reminderDto = GetItem(reminderId); if (reminderDto == null) {//this reminder has been removed so remove it from the phone ScheduledActionService.Remove(existingReminder.Name); } } catch (Exception) { } } //now check added or updated reminders foreach (var item in Items.Values) { try { var phoneReminder = existingReminders.Where(x => x.Name == item.GlobalId.ToString()).SingleOrDefault(); var reminder = phoneReminder; if (reminder == null) { reminder = new Reminder(item.GlobalId.ToString()); } reminder.Title = item.Name; //reminder.Content = contentTextBox.Text; reminder.BeginTime = item.DateTime.ToLocalTime(); if (item.RemindBefore != null) { var newDate = item.DateTime.ToLocalTime() - item.RemindBefore.Value; reminder.BeginTime = newDate; } if (item.Repetitions == ReminderRepetitions.Once) { if (reminder.BeginTime < DateTime.Now) { reminder.BeginTime = DateTime.Now.AddSeconds(5); } if (reminder.BeginTime < DateTime.Now - TimeSpan.FromDays(2)) {//old reminder. skip it! continue; } reminder.ExpirationTime = reminder.BeginTime.AddDays(1); } //reminder.ExpirationTime = expirationTime; reminder.RecurrenceType = fromReminderRepetitions(item.Repetitions); //reminder.NavigationUri = navigationUri; // Register the reminder with the system. if (phoneReminder == null) { ScheduledActionService.Add(reminder); } else if (phoneReminder.IsScheduled) { ScheduledActionService.Replace(reminder); } } catch (Exception) { } } }
public static List <Reminder> GetAll() { return(ScheduledActionService.GetActions <Reminder>().ToList()); }
public IList <Reminder> GetReminders() { return(ScheduledActionService.GetActions <ScheduledAction>().OfType <Reminder>().Where(x => x.IsEnabled).Where(x => x.IsScheduled).OrderBy(x => x.BeginTime).ToList()); }
private void RefreshReminderList() { IEnumerable <Reminder> reminders = ScheduledActionService.GetActions <Reminder>(); this.lbReminders.ItemsSource = reminders; }
public IEnumerable <T> GetActions <T>() where T : ScheduledAction { return(ScheduledActionService.GetActions <T>()); }