private void Button_Click_2(object sender, RoutedEventArgs e) { string name = "ResourceIntensiveTask"; ResourceIntensiveTask resourceIntensiveTask = ScheduledActionService.Find(name) as ResourceIntensiveTask; if (resourceIntensiveTask == null) { resourceIntensiveTask = new ResourceIntensiveTask(name); } else { ScheduledActionService.Remove(name); resourceIntensiveTask = new ResourceIntensiveTask(name); } resourceIntensiveTask.Description = "描述我们的ResourceIntensiveTask后台任务是干什么的"; try { ScheduledActionService.Add(resourceIntensiveTask); ScheduledActionService.LaunchForTest(name, TimeSpan.FromSeconds(1)); } catch (InvalidOperationException ioe) { } }
private void StartAutoUpload(bool enabled) { resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask; if (resourceIntensiveTask != null) { RemoveAgent(resourceIntensiveTaskName); } if (!enabled) { return; } resourceIntensiveTask = new ResourceIntensiveTask(resourceIntensiveTaskName) { Description = "This is Cloudy Box autoupload service" }; try { ScheduledActionService.Add(resourceIntensiveTask); #if DEBUG_AGENT ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(10)); #endif } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
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 }
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); }
// Used to start the agent. public void startAgent() { stopAgent(); // Prevent two agents from running. ResourceIntensiveTask task = new ResourceIntensiveTask(agentName); task.Description = "This task uploads photos from the Camera Roll."; ScheduledActionService.Add(task); }
public static bool SetAutoCameraUpload(bool onOff) { var resourceIntensiveTask = ScheduledActionService.Find("ScheduledCameraUploadTaskAgent") 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) { ScheduledActionService.Remove("ScheduledCameraUploadTaskAgent"); } if (!onOff) { LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Disable CAMERA UPLOADS service"); return(false); } resourceIntensiveTask = new ResourceIntensiveTask("ScheduledCameraUploadTaskAgent") { // 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. Description = AppMessages.ResourceIntensiveTaskDescription }; // Place the call to Add in a try block in case the user has disabled agents. try { ScheduledActionService.Add(resourceIntensiveTask); // If debugging is enabled, use LaunchForTest to launch the agent in one minute. #if DEBUG ScheduledActionService.LaunchForTest("ScheduledCameraUploadTaskAgent", TimeSpan.FromSeconds(5)); #endif LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Enable CAMERA UPLOADS service"); return(true); } catch (InvalidOperationException exception) { if (exception.Message.Contains("BNS Error: The action is disabled")) { new CustomMessageDialog(AppMessages.BackgroundAgentDisabled_Title, AppMessages.BackgroundAgentDisabled, App.AppInformation).ShowDialog(); } } catch (SchedulerServiceException) { /* Do nothing */ } catch (ArgumentException) { /* Do nothing - Possible Bug #4942 */ } LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error enabling CAMERA UPLOADS service"); return(false); }
public static bool GetAutoCameraUploadStatus() { ResourceIntensiveTask resourceIntensiveTask = null; try { resourceIntensiveTask = ScheduledActionService.Find("ScheduledCameraUploadTaskAgent") as ResourceIntensiveTask; } catch (InvalidOperationException) { /* Do nothing - Possible Bug #4941 */ } catch (SchedulerServiceException) { /* Do nothing */ } return(resourceIntensiveTask != null && resourceIntensiveTask.IsScheduled); }
private void StartResourceIntensiveAgent() { // Variable for tracking enabled status of background agents for this app. ///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 = "My Phone Info 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 || FORCE_COMPILE_DEMO_MODE ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, 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."); ///agentsAreEnabled = false; } ///ResourceIntensiveCheckBox.IsChecked = false; } catch (SchedulerServiceException) { // No user action required. ///ResourceIntensiveCheckBox.IsChecked = false; } }
private void StartResourceIntensiveAgent() { // Variable for tracking enabled status of background agents for this app. 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(resourceIntensiveTaskName, 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."); agentsAreEnabled = false; } ResourceIntensiveCheckBox.IsChecked = false; } catch (SchedulerServiceException) { // No user action required. ResourceIntensiveCheckBox.IsChecked = false; } }
private static void CreateResourceTask() { var resourceTask = new ResourceIntensiveTask(FootprintTaskName); resourceTask.Description = "Footprint task"; resourceTask.ExpirationTime = DateTime.Now.AddDays(1); // If the agent is already registered with the system, RemoveResourceTask(); //not supported in current version //periodicTask.BeginTime = DateTime.Now.AddSeconds(10); //only can be called when application is running in foreground ScheduledActionService.Add(resourceTask); }
public void ScheduleSync() { // Obtain a reference to the period task, if one exists var periodicTask = ScheduledActionService.Find(TaskName) 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 (periodicTask != null) { RemoveAgent(TaskName); } periodicTask = new ResourceIntensiveTask(TaskName) { Description = "Synchronization of new JIRA issues" }; // 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(TaskName, 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. } }
public bool CreateTask() { try { RemoveTask(); var resourceTask = new ResourceIntensiveTask(Constants.PhotoUploadBackgroundTaskName) { Description = AppResources.BackgroundTaskDescription }; ScheduledActionService.Add(resourceTask); return(true); } catch (Exception ex) { return(false); } }
public bool CreateTask() { try { RemoveTask(); var resourceTask = new ResourceIntensiveTask(Constants.PhotoUploadBackgroundTaskName) { Description = AppResources.BackgroundTaskDescription }; ScheduledActionService.Add(resourceTask); return true; } catch (Exception ex) { return false; } }
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; }
public static bool ActivateAgent() { // Wenn der Task bereits hinzugefügt wurde. dann diesen stoppen PeriodicTask syncTask = ScheduledActionService.Find(AgentName) as PeriodicTask; if (syncTask != null) { StopAgent(AgentName); } // Task anlegen und Beschreibung für Einstellungs-UI setzen syncTask = new PeriodicTask(AgentName); syncTask.Description = "Download der neusten Nachrichten von Spiegel Online"; ResourceIntensiveTask intensiveTask = ScheduledActionService.Find(AgentIntensiveName) as ResourceIntensiveTask; if (intensiveTask != null) { StopAgent(AgentIntensiveName); } intensiveTask = new ResourceIntensiveTask(AgentIntensiveName); try { // Tasks im System registrieren für Ausführung ScheduledActionService.Add(syncTask); ScheduledActionService.Add(intensiveTask); #if DEBUG // Für's Debuggen: Tasks in 30 bzw. 90sek ausführen ScheduledActionService.LaunchForTest(AgentName, TimeSpan.FromSeconds(30)); ScheduledActionService.LaunchForTest(AgentIntensiveName, TimeSpan.FromSeconds(90)); #endif return(true); } catch (InvalidOperationException ex) { return(false); } }
public static bool ActivateAgent() { // Wenn der Task bereits hinzugefügt wurde. dann diesen stoppen PeriodicTask syncTask = ScheduledActionService.Find(AgentName) as PeriodicTask; if (syncTask != null) { StopAgent(AgentName); } // Task anlegen und Beschreibung für Einstellungs-UI setzen syncTask = new PeriodicTask(AgentName); syncTask.Description = "Download der neusten Nachrichten von Spiegel Online"; ResourceIntensiveTask intensiveTask = ScheduledActionService.Find(AgentIntensiveName) as ResourceIntensiveTask; if (intensiveTask != null) { StopAgent(AgentIntensiveName); } intensiveTask = new ResourceIntensiveTask(AgentIntensiveName); try { // Tasks im System registrieren für Ausführung ScheduledActionService.Add(syncTask); ScheduledActionService.Add(intensiveTask); #if DEBUG // Für's Debuggen: Tasks in 30 bzw. 90sek ausführen ScheduledActionService.LaunchForTest(AgentName, TimeSpan.FromSeconds(30)); ScheduledActionService.LaunchForTest(AgentIntensiveName, TimeSpan.FromSeconds(90)); #endif return true; } catch (InvalidOperationException ex) { return false; } }
private void StartResourceIntensiveAgent() { string resourceIntensiveTaskName = "ResourceIntensiveAgent"; ResourceIntensiveTask resourceIntensiveTask; resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask; if (resourceIntensiveTask != null) { RemoveAgent(resourceIntensiveTaskName); } resourceIntensiveTask = new ResourceIntensiveTask(resourceIntensiveTaskName); resourceIntensiveTask.Description = "This demonstrates a resource-intensive task."; try { ScheduledActionService.Add(resourceIntensiveTask); #if DEBUG ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(6)); #else ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(30)); #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."); } } catch (SchedulerServiceException) { } }
private void StartResourceIntensiveAgent() { Debug.WriteLine("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) Debug.WriteLine("Start LaunchForTest"); ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(5)); #endif }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { #region Trial Mode Check //if (App.IsTrial == true) //{ // // enable ads // adControl.Visibility = System.Windows.Visibility.Visible; // //adControl.IsAutoRefreshEnabled = true; // adControl.IsEnabled = true; // adControl.IsAutoCollapseEnabled = false; // btnBuyApp.IsEnabled = true; // btnBuyApp.Visibility = System.Windows.Visibility.Visible; //} //else //{ // // disables ads // adControl.Visibility = System.Windows.Visibility.Collapsed; // //adControl.IsAutoRefreshEnabled = false; // adControl.IsEnabled = false; // adControl.IsAutoCollapseEnabled = false; // btnBuyApp.IsEnabled = false; // btnBuyApp.Visibility = System.Windows.Visibility.Collapsed; //} #endregion try { // Get the settings for this application. isolatedStorage = IsolatedStorageSettings.ApplicationSettings; } catch (Exception err) { Debug.WriteLine("Exception while using IsolatedStorageSettings: " + err.ToString()); } if (isolatedStorage.Contains("BackgroundService")) { Background_Service.IsChecked = (bool)isolatedStorage["BackgroundService"]; Debug.WriteLine("BackgroundService = " + Background_Service.IsChecked.ToString()); } if (isolatedStorage.Contains("RadiusDisplay")) { RadiusDisplayCheckBox.IsChecked = (bool)isolatedStorage["RadiusDisplay"]; Debug.WriteLine("RadiusDisplay = " + RadiusDisplayCheckBox.IsChecked.ToString()); } if (isolatedStorage.Contains("TrackPosition")) { TrackPositionCheckBox.IsChecked = (bool)isolatedStorage["TrackPosition"]; Debug.WriteLine("TrackPosition = " + TrackPositionCheckBox.IsChecked.ToString()); } if (isolatedStorage.Contains("AerialView")) { AerialViewToggle.IsChecked = (bool)isolatedStorage["AerialView"]; Debug.WriteLine("AerialView = " + AerialViewToggle.IsChecked.ToString()); } 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; }
private void AddScheduledTask() { RemoveSchedule(); ResourceIntensiveTask resourceIntensiveTask = new ResourceIntensiveTask(RIT_NAME); resourceIntensiveTask.Description = "This demonstrates a resource-intensive task."; ScheduledActionService.Add(resourceIntensiveTask); Settings.Enabled = true; }