/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { CoreApp.CurrentPlatform = AppPlatform.UWP; base.OnLaunched(e); #if !DEBUG AppCenter.Start("1fba816a-eea6-42a8-bf46-0c0fcc1589db", typeof(Analytics), typeof(Crashes)); #endif if (e.PreviousExecutionState != ApplicationExecutionState.Running) { ApplicationLanguages.PrimaryLanguageOverride = GlobalizationPreferences.Languages[0]; Xamarin.Forms.Forms.Init(e); new MoneyFox.App(); BackgroundTaskHelper.Register(typeof(ClearPaymentsTask), new TimeTrigger(60, false)); BackgroundTaskHelper.Register(typeof(RecurringPaymentTask), new TimeTrigger(60, false)); mainView.ViewModel = Mvx.IoCProvider.Resolve <MainViewModel>(); (mainView.ViewModel as MainViewModel)?.ShowAccountListCommand.ExecuteAsync(); OverrideTitleBarColor(); //If Jump Lists are supported, add them if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { await SetJumplist(); } await CallRateReminder(); } }
/// <summary> /// Arrival event as a NetworkMonitorEventListener /// </summary> /// <param name="nme"> NetworkMonitorEvent add </param> public virtual void deviceArrival(DeviceMonitorEvent dme) { for (int i = 0; i < dme.DeviceCount; i++) { Debug.WriteLine("ADD: " + dme.getPathForContainerAt(i) + dme.getAddressAsStringAt(i)); // if new devices is a TemperatureContainter the start a thread to read it OneWireContainer owc = dme.getContainerAt(i); if (owc is TemperatureContainer) { //TODO SetValue("TemperatureContainer", owc); //TODO SetValue("OWPath", dme.getPathForContainerAt(i)); var t = Task <BackgroundTaskRegistration> .Run(() => { return(BackgroundTaskHelper.Register( WatchTempBackgroundTaskEntryPoint, WatchTempBackgroundTaskName, new SystemTrigger(SystemTriggerType.TimeZoneChange, false), null)); }); t.Wait(); // add to vector for later cleanup watchers.Add(t.Result); } } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if !DEBUG MobileCenter.Start("1fba816a-eea6-42a8-bf46-0c0fcc1589db", typeof(Analytics), typeof(Crashes)); #endif if (e.PreviousExecutionState != ApplicationExecutionState.Running) { var mainView = new MainView { Language = ApplicationLanguages.Languages[0] }; Window.Current.Content = mainView; ApplicationLanguages.PrimaryLanguageOverride = GlobalizationPreferences.Languages[0]; Xamarin.Forms.Forms.Init(e); // When the navigation stack isn't restored, navigate to the first page // suppressing the initial entrance animation. var setup = new Setup(mainView.MainFrame); setup.Initialize(); var start = Mvx.Resolve <IMvxAppStart>(); start.Start(); BackgroundTaskHelper.Register(typeof(ClearPaymentsTask), new TimeTrigger(60, false)); BackgroundTaskHelper.Register(typeof(RecurringPaymentTask), new TimeTrigger(60, false)); Mvx.Resolve <IBackgroundTaskManager>().StartBackupSyncTask(60); mainView.ViewModel = Mvx.Resolve <MenuViewModel>(); OverrideTitleBarColor(); //If Jump Lists are supported, add them if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { await SetJumplist(); } await CallRateReminder(); } //OverrideTitleBarColor(); //When jumplist is selected navigate to appropriate tile var tileHelper = Mvx.Resolve <TileHelper>(); if (e.Arguments == Constants.ADD_INCOME_TILE_ID) { await tileHelper.DoNavigation(Constants.ADD_INCOME_TILE_ID); } else if (e.Arguments == Constants.ADD_EXPENSE_TILE_ID) { await tileHelper.DoNavigation(Constants.ADD_EXPENSE_TILE_ID); } else if (e.Arguments == Constants.ADD_TRANSFER_TILE_ID) { await tileHelper.DoNavigation(Constants.ADD_TRANSFER_TILE_ID); } // Ensure the current window is active Window.Current.Activate(); }
private void RegisterBackgroundTask() { var task = BackgroundTaskHelper.Register(typeof(BiliBili.Background.BackgroundTask), new TimeTrigger(15, true), true, true, null); task.Progress += TaskOnProgress; task.Completed += TaskOnCompleted; }
private static void HandleBackgroundSnoozeActivation(ToastNotificationActionTriggerDetail details) { string snoozeMinutesTxt = (string)details.UserInput[INPUT_SNOOZEMINUTES]; uint snoozeMinutes = uint.Parse(snoozeMinutesTxt); // Register a time trigger background task to fire at the requested snooze time, which will then pop a new notification BackgroundTaskHelper.Register(TOAST_TIME_TRIGGER_BACKGROUND_TASK, new TimeTrigger(snoozeMinutes, oneShot: true)); }
/// <inheritdoc /> public void StartBackupSyncTask() { BackgroundTaskRegistration registered = BackgroundTaskHelper.Register(typeof(SyncBackupTask), new TimeTrigger((uint)(settingsManager.BackupSyncRecurrence * 60), true)); registered.Completed += RegisteredOnCompleted; }
public static void RegesterLiveTile(bool reg) { if (reg) { BackgroundTaskHelper.Register(typeof(LiveTileTask), new TimeTrigger(15, false), true); } else { BackgroundTaskHelper.Unregister(typeof(LiveTileTask)); } }
private async void Init() { await BackgroundTaskHelper.Register(); #if WINDOWS_APP Logger.LogAgent.GetInstance().Register("MS-UAP", "CNBlogs-Win8.1"); #endif #if WINDOWS_PHONE_APP Logger.LogAgent.GetInstance().Register("MS-UAP", "CNBlogs-WP8.1"); #endif }
public void RegisterLiveTile(bool reg) { if (reg) { BackgroundTaskHelper.Register(typeof(LiveTileTask), new TimeTrigger(15, false), true, true, new SystemCondition(SystemConditionType.InternetAvailable)); } else { BackgroundTaskHelper.Unregister(typeof(LiveTileTask)); } }
/// <summary> /// Registers a particular bg tasks specified by <paramref name="backgroundTask"/> /// </summary> /// <param name="backgroundTask">The background task to register</param> /// <param name="restart">Indicates if the registration of the bg task is mandatory(True by default)</param> public static void RegisterBackgroundTask(BackgroundTaskType backgroundTask, int bgTaskInterval = 0, bool restart = true) { string bgTaskName; Type bgTaskType; IBackgroundTrigger trigger; var conditions = new List <IBackgroundCondition>(); switch (backgroundTask) { case BackgroundTaskType.ANY: throw new ArgumentException("Is not allowed to register all bg tasks at the same time"); case BackgroundTaskType.SYNC: bgTaskName = nameof(SyncBackgroundTask); bgTaskType = typeof(SyncBackgroundTask); trigger = new TimeTrigger((uint)bgTaskInterval, false); conditions.Add(new SystemCondition(SystemConditionType.FreeNetworkAvailable)); conditions.Add(new SystemCondition(SystemConditionType.InternetAvailable)); break; case BackgroundTaskType.MARK_AS_COMPLETED: bgTaskName = nameof(MarkAsCompletedBackgroundTask); bgTaskType = typeof(MarkAsCompletedBackgroundTask); trigger = new ToastNotificationActionTrigger(); break; default: throw new ArgumentOutOfRangeException($"Provided bg task {backgroundTask} does not exists"); } bool isBgTaskAlreadyRegistered = BackgroundTaskHelper.IsBackgroundTaskRegistered(bgTaskType); if (isBgTaskAlreadyRegistered && !restart) { return; } if (isBgTaskAlreadyRegistered) { UnregisterBackgroundTask(backgroundTask); } if (bgTaskInterval <= 0 && backgroundTask != BackgroundTaskType.MARK_AS_COMPLETED) { return; } BackgroundTaskHelper.Register( bgTaskName, trigger, false, true, conditions.ToArray()); }
public void RegisterLogin(bool reg) { if (reg) { BackgroundTaskHelper.Register(typeof(LoginTask), new SystemTrigger(SystemTriggerType.NetworkStateChange, false), true, true); } else { BackgroundTaskHelper.Unregister(typeof(LoginTask)); } }
public void Test_BackgroundTaskHelper_GetBackgroundTask_WithValidTask() { BackgroundTaskRegistration registeredTask = BackgroundTaskHelper.Register("TaskName", new TimeTrigger(15, true)); if (registeredTask == null) { Assert.Inconclusive("Task failed to register"); } Assert.IsNotNull(BackgroundTaskHelper.GetBackgroundTask("TaskName")); }
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- #endregion #region --Misc Methods (Private)-- /// <summary> /// Registers the socket background task if necessary. /// </summary> public async static Task registerBackgroundTask() { if (BackgroundTaskHelper.IsBackgroundTaskRegistered(BACKGROUND_TASK_NAME)) { removeBackgroundTask(); } await BackgroundExecutionManager.RequestAccessAsync(); socketTask = BackgroundTaskHelper.Register(BACKGROUND_TASK_NAME, BACKGROUND_TASK_ENTRY_POINT, new SocketActivityTrigger(), false, true); Logger.Info("Registered the " + BACKGROUND_TASK_NAME + " background task."); }
public async static void Register() { //这里就是磁贴更新周期的一些逻辑处理 var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity || backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity) { BackgroundTaskHelper.Register(typeof(LastNewNotifitionBackgroundTask), new TimeTrigger(60, false), false, true, new SystemCondition(SystemConditionType.InternetAvailable), new SystemCondition(SystemConditionType.UserPresent)); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="activationArgs">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs activationArgs) { CoreApp.CurrentPlatform = AppPlatform.UWP; base.OnLaunched(activationArgs); if (activationArgs.PreviousExecutionState != ApplicationExecutionState.Running) { ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current); ApplicationLanguages.PrimaryLanguageOverride = GlobalizationPreferences.Languages[0]; #if !DEBUG AppCenter.Start(ConfigurationManager.AppSettings["WindowsAppcenterSecret"], typeof(Analytics), typeof(Crashes)); #endif Xamarin.Forms.Forms.Init(activationArgs); var app = new Presentation.App(); BackgroundTaskHelper.Register(typeof(ClearPaymentsTask), new TimeTrigger(60, false)); BackgroundTaskHelper.Register(typeof(RecurringPaymentTask), new TimeTrigger(60, false)); BackgroundTaskHelper.Register(typeof(LiveTiles), new TimeTrigger(15, false)); mainView.ViewModel = Mvx.IoCProvider.Resolve <MainViewModel>(); if (!Mvx.IoCProvider.CanResolve <Session>()) { return; } if (Mvx.IoCProvider.Resolve <Session>().ValidateSession()) { (mainView.ViewModel as MainViewModel)?.ShowAccountListCommand.ExecuteAsync(); } else if (Mvx.IoCProvider.CanResolve <IMvxNavigationService>()) { await Mvx.IoCProvider .Resolve <IMvxNavigationService>() .Navigate <LoginViewModel>() ; } ((MainViewModel)mainView.ViewModel)?.ShowAccountListCommand.ExecuteAsync(); OverrideTitleBarColor(); //If Jump Lists are supported, add them if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { await SetJumplist(); } await CallRateReminder(); } }
public void Test_BackgroundTaskHelper_Unregister() { BackgroundTaskHelper.Register("TaskName", new TimeTrigger(15, true)); if (!BackgroundTaskHelper.IsBackgroundTaskRegistered("TaskName")) { Assert.Inconclusive("Task failed to register!"); } BackgroundTaskHelper.Unregister("TaskName"); Assert.IsFalse(BackgroundTaskHelper.IsBackgroundTaskRegistered("TaskName")); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { CoreApp.CurrentPlatform = AppPlatform.UWP; base.OnLaunched(e); #if !DEBUG AppCenter.Start("1fba816a-eea6-42a8-bf46-0c0fcc1589db", typeof(Analytics), typeof(Crashes)); #endif if (e.PreviousExecutionState != ApplicationExecutionState.Running) { ApplicationLanguages.PrimaryLanguageOverride = GlobalizationPreferences.Languages[0]; Xamarin.Forms.Forms.Init(e); new MoneyFox.App(); BackgroundTaskHelper.Register(typeof(ClearPaymentsTask), new TimeTrigger(60, false)); BackgroundTaskHelper.Register(typeof(RecurringPaymentTask), new TimeTrigger(60, false)); mainView.ViewModel = Mvx.Resolve <MainViewModel>(); (mainView.ViewModel as MainViewModel)?.ShowAccountListCommand.ExecuteAsync(); OverrideTitleBarColor(); //If Jump Lists are supported, add them if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { await SetJumplist(); } await CallRateReminder(); } //When jumplist is selected navigate to appropriate tile var tileHelper = Mvx.Resolve <ITileManager>(); switch (e.Arguments) { case Constants.ADD_INCOME_TILE_ID: await tileHelper.DoNavigation(Constants.ADD_INCOME_TILE_ID); break; case Constants.ADD_EXPENSE_TILE_ID: await tileHelper.DoNavigation(Constants.ADD_EXPENSE_TILE_ID); break; case Constants.ADD_TRANSFER_TILE_ID: await tileHelper.DoNavigation(Constants.ADD_TRANSFER_TILE_ID); break; } }
public static void RegisterToastActionBackgroundTask() { try { // Register a background task to handle the toast button click action BackgroundTaskHelper.Register(TOAST_ACTION_BACKGROUND_TASK, new ToastNotificationActionTrigger()); IsToastBackgroundTaskRegistered = true; } catch { // Report to telemetry } }
private async void RegisterSpmButton_Click(object sender, RoutedEventArgs e) { if (IsBackgroundTaskRegistered(Constants.TestBackgroundTaskName)) { return; } // Check for background access. await BackgroundExecutionManager.RequestAccessAsync(); // Registering Single-Process Background task BackgroundTaskHelper.Register(Constants.TestBackgroundTaskName, new TimeTrigger(15, false)); StatusMessage.Text = "Background Task registered (SPM)"; }
private async void RegisterMpmButton_Click(object sender, RoutedEventArgs e) { if (IsBackgroundTaskRegistered(nameof(TestBackgroundTask))) { return; } // Check for background access. await BackgroundExecutionManager.RequestAccessAsync(); // Registering Multi-Process Background task BackgroundTaskHelper.Register(nameof(TestBackgroundTask), "Microsoft.Toolkit.Uwp.Samples.BackgroundTasks.TestBackgroundTask", new TimeTrigger(15, false), false, true, new SystemCondition(SystemConditionType.InternetAvailable)); StatusMessage.Text = "Background Task registered (MPM)"; }
public void UpdateWorkRegister() { var Timer_Condition = new IBackgroundCondition[] { new SystemCondition(SystemConditionType.FreeNetworkAvailable) }; bool HasRegistered = BackgroundTaskHelper.IsBackgroundTaskRegistered(typeof(TileRefreshUtils)); if (Enabled) { BackgroundTaskHelper.Register(typeof(TileRefreshUtils), new TimeTrigger(TimerSpan, false), false, true, Timer_Condition); } else if (HasRegistered) { BackgroundTaskHelper.Unregister(typeof(TileRefreshUtils)); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (!(Window.Current.Content is Frame rootFrame)) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(WelcomeView), e.Arguments); } SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested; rootFrame.Navigated += RootFrame_Navigated; // Ensure the current window is active Window.Current.Activate(); } var titleBar = ApplicationView.GetForCurrentView().TitleBar; // Set active window colors titleBar.ForegroundColor = Colors.White; titleBar.BackgroundColor = Color.FromArgb(255, 21, 21, 21); titleBar.ButtonBackgroundColor = Color.FromArgb(255, 21, 21, 21); HockeyClient.Current.TrackEvent("App Launch"); // Background task runs every 60 minutes to look for fresh content BackgroundTaskHelper.Register("FloatPlane.ContentChecker", new TimeTrigger(60, false), true); }
private async void RegisterButton_Click(object sender, RoutedEventArgs e) { if (BackgroundTaskHelper.IsBackgroundTaskRegistered("TestBackgroundTaskName")) { // Background task already registered. StatusMessage.Text = "Background Task already registered"; return; } // Check for background access. await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskHelper.Register("TestBackgroundTaskName", new TimeTrigger(15, false)); // If registering Multi-Process Background task // BackgroundTaskHelper.Register("TestName", "TestEntryPoint", new TimeTrigger(15, false), false, true, new SystemCondition(SystemConditionType.InternetAvailable)); StatusMessage.Text = "Background Task registered"; }
private void RegisterBackgroundTasks() { // Remove old Background Tasks if (BackgroundTaskHelper.IsBackgroundTaskRegistered("NewEpisodesBackgroundTask")) { BackgroundTaskHelper.Unregister("NewEpisodesBackgroundTask"); } // Check if Background Task is already registered and register new ones if (!BackgroundTaskHelper.IsBackgroundTaskRegistered(typeof(NewEpisodesV2BackgroundTask))) { BackgroundTaskHelper.Register( nameof(NewEpisodesV2BackgroundTask), new TimeTrigger(15, false), conditions: new SystemCondition(SystemConditionType.InternetAvailable) ); } }
// Include code to be executed when the system has transitioned from the splash screen to the extended splash screen (application's first view). void DismissedEventHandler(SplashScreen sender, object e) { // Navigate away from the app's extended splash screen after completing setup operations here... if (!Dismissed) { Dismissed = true; var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { Window.Current.Content = new ShellPage { Language = ApplicationLanguages.Languages[0] }; ApplicationLanguages.PrimaryLanguageOverride = GlobalizationPreferences.Languages[0]; var shell = (ShellPage)Window.Current.Content; // When the navigation stack isn't restored, navigate to the first page // suppressing the initial entrance animation. var setup = new Setup(shell.Frame); setup.Initialize(); var start = Mvx.Resolve <IMvxAppStart>(); start.Start(); var registeredClearPaymentTask = BackgroundTaskHelper.Register(typeof(ClearPaymentsTask), new TimeTrigger(60, false)); var registeredRecurringJob = BackgroundTaskHelper.Register(typeof(RecurringPaymentTask), new TimeTrigger(60, false)); registeredClearPaymentTask.Completed += RegisteredClearPaymentTaskOnCompleted; registeredRecurringJob.Completed += RegisteredRecurringPaymentTaskOnCompleted; shell.ViewModel = Mvx.Resolve <ShellViewModel>(); //If Jump Lists are supported, add them if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { await SetJumplist(); } await CallRateReminder(); }); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if !DEBUG MobileCenter.Start("1fba816a-eea6-42a8-bf46-0c0fcc1589db", typeof(Analytics), typeof(Crashes)); #endif if (e.PreviousExecutionState != ApplicationExecutionState.Running) { Window.Current.Content = new ShellPage { Language = ApplicationLanguages.Languages[0] }; ApplicationLanguages.PrimaryLanguageOverride = GlobalizationPreferences.Languages[0]; var shell = (ShellPage)Window.Current.Content; // When the navigation stack isn't restored, navigate to the first page // suppressing the initial entrance animation. var setup = new Setup(shell.Frame); setup.Initialize(); var start = Mvx.Resolve <IMvxAppStart>(); start.Start(); BackgroundTaskHelper.Register(typeof(ClearPaymentsTask), new TimeTrigger(60, false)); BackgroundTaskHelper.Register(typeof(RecurringPaymentTask), new TimeTrigger(60, false)); Mvx.Resolve <IBackgroundTaskManager>().StartBackupSyncTask(60); shell.ViewModel = Mvx.Resolve <ShellViewModel>(); //If Jump Lists are supported, add them if (ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList")) { await SetJumplist(); } await CallRateReminder(); } OverrideTitleBarColor(); // Ensure the current window is active Window.Current.Activate(); }
private async void NetworkStateChangeLoginSetter(object original_sender, RoutedEventArgs e) { var sender = original_sender as ToggleSwitch; MyNetworkStateChangeLoginSetting.ApplySetting(sender.IsOn); if (sender.IsOn) { if (!BackgroundTaskHelper.IsBackgroundTaskRegistered(NameManager.LIVETILETASK_NetWorkChanged)) { await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskHelper.Register( NameManager.LIVETILETASK_NetWorkChanged, typeof(TileRefresh.TileRefreshUtils).FullName, new SystemTrigger(SystemTriggerType.NetworkStateChange, false)); } //RefreshLoginSetting_UI.IsEnabled = true; //await App.RegisterLiveTileTask( // NameManager.LIVETILETASK_UserPresent, // typeof(TileRefresh.TileRefreshUtils).FullName, // new SystemTrigger(SystemTriggerType.UserPresent, false), // null //); } else { //RefreshLoginSetting_UI.IsOn = false; //MyRefreshLoginSetting.ApplySetting(false); //RefreshLoginSetting_UI.IsEnabled = false; //if (BackgroundTaskHelper.IsBackgroundTaskRegistered(NameManager.LIVETILETASK_NetWorkChanged)) //{ // BackgroundTaskHelper.Unregister(NameManager.LIVETILETASK_NetWorkChanged); //} //await App.RegisterLiveTileTask( // NameManager.LIVETILETASK_UserPresent, // typeof(TileRefresh.TileRefreshUtils).FullName, // null, // null //); } }
/// <summary> /// 注册后台任务 /// </summary> /// <param name="type">注册类型</param> /// <returns></returns> public async Task <bool> RegisterBackgroundTask(string type) { string backgroundTaskName = $"{type}NotificationTask"; if (BackgroundTaskHelper.IsBackgroundTaskRegistered(backgroundTaskName)) { return(true); } var status = await BackgroundExecutionManager.RequestAccessAsync(); if (status.ToString().Contains("Allowed")) { BackgroundTaskHelper.Register(backgroundTaskName, $"BiliBili_Notification.{type}Notification", new TimeTrigger(15, false), false, true, new SystemCondition(SystemConditionType.InternetAvailable)); return(true); } else { new TipPopup("需要开启后台通知").ShowError(); return(false); } }
//private async Task<bool> CredentialsVerifier() //{ // if (User.Text.Length != 0 && Pass.Password.Length != 0) // { // register.IsEnabled = true; // LoginButton.IsEnabled = true; // LogoutButton.IsEnabled = true; // var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; // localSettings.Values["user"] = User.Text; // localSettings.Values["pass"] = Pass.Password; // await Network.Pronto.Login(); // return true; // } // else // register.IsEnabled = false; // LoginButton.IsEnabled = false; // LogoutButton.IsEnabled = false; // return false; //} private async void Register(object sender, RoutedEventArgs e) { if (!isValid) { if (Registered) { UnRegisterTasks(); return; } else { ShowDialog("Please Fill Your Credentials Correctly"); return; } } if (Registered) { UnRegisterTasks(); } else { var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if (backgroundAccessStatus == BackgroundAccessStatus.DeniedByUser || backgroundAccessStatus == BackgroundAccessStatus.DeniedBySystemPolicy) { ShowDialog("BackgroundAcess Denied By User or System Please Allow to automate Login"); return; } var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["user"] = User.Text; localSettings.Values["pass"] = Pass.Password; BackgroundTaskHelper.Register("SampleBackgroundTask", "Tasks.SampleBackgroundTask", new SystemTrigger(SystemTriggerType.NetworkStateChange, false), false, false, null); BackgroundTaskHelper.Register("ToastBackgroundTask", "Tasks.ToastBackgroundTask", new ToastNotificationActionTrigger(), false, false, null); RegisterTask(); register.Content = "Forget Me"; Registered = true; } }
/// <summary> /// Performs a registration of a background task. /// </summary> private async void RegisterBackgroundTask() { const string taskName = "ArcadeBackgroundTask"; const string taskEntryPoint = "BackgroundTasks.ArcadeBackgroundTask"; var accessStatus = await BackgroundExecutionManager.RequestAccessAsync(); var isRegistered = BackgroundTaskHelper.IsBackgroundTaskRegistered(taskName); if (accessStatus == BackgroundAccessStatus.DeniedByUser || accessStatus == BackgroundAccessStatus.DeniedBySystemPolicy || isRegistered) { return; } var trigger = new TimeTrigger(120, false); BackgroundTaskHelper.Register(taskName, taskEntryPoint, trigger, conditions: new SystemCondition(SystemConditionType.InternetAvailable)); }