示例#1
0
        /// <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)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                rootFrame.NavigationFailed += OnNavigationFailed;
                // 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(ShellPage), e.Arguments);
                }

                // Ensure the current window is active
                Window.Current.Activate();
            }

            Settings.SettingsViewModel.InitAppTheme();
            BackgroundTaskService.RegisterBackgroundTasks();
            await StateService.Instance.RestoreStateAsync(e.PreviousExecutionState, e.Arguments);
        }
示例#2
0
        public async Task StopListener()
        {
            datagramSocket.MessageReceived -= DatagramSocket_MessageReceived;
            await datagramSocket.CancelIOAsync();

            datagramSocket = null;
            await BackgroundTaskService.Unregister <BroadcastListenerBackgroundTask>();
        }
示例#3
0
        protected override void doWork()
        {
            logService.Debug(DateTime.Now);
            IBackgroundTaskService backgroundTaskService = BackgroundTaskService.GetInstance();

            backgroundTaskService.doWork();
            logService.Debug("CloudflareLogHandleService start.");
        }
 public ChallengeController(
     IOptions <SegmentChallengeConfiguration> siteConfiguration,
     Func <DbConnection> dbConnectionFactory,
     BackgroundTaskService taskService)
 {
     this.siteConfiguration   = siteConfiguration;
     this.dbConnectionFactory = dbConnectionFactory;
     this.taskService         = taskService;
 }
示例#5
0
        public MainWindowViewModel(IDatabaseService databaseService, IStorageService storageService)
        {
            databaseService.InitializeDatabase();
            Employees           = databaseService.GetEmployees();
            this.storageService = storageService;

            BackgroundTaskService backgroundTaskService = new BackgroundTaskService();

            backgroundTaskService.RegisterBackgroundTask();
        }
示例#6
0
        public async Task StartListener()
        {
            var backgroundTaskRegistration = await BackgroundTaskService.Register <BroadcastListenerBackgroundTask>(new SocketActivityTrigger());

            datagramSocket = new DatagramSocket();
            datagramSocket.EnableTransferOwnership(backgroundTaskRegistration.TaskId, SocketActivityConnectedStandbyAction.DoNotWake);
            await datagramSocket.BindServiceNameAsync("4536");

            datagramSocket.MessageReceived += DatagramSocket_MessageReceived;
        }
        private void InitializeBackgroundCommunication()
        {
            MessagingCenter.Subscribe <StartLongRunningTaskMessage>(this, "StartLongRunningTaskMessage", async message =>
            {
                backgroundSender = new BackgroundTaskService();
                await backgroundSender.Start();
            });

            MessagingCenter.Subscribe <StopLongRunningTaskMessage>(this, "StopLongRunningTaskMessage", message =>
            {
                backgroundSender.Stop();
            });
        }
示例#8
0
        protected async override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            await InitializeLogger();

            var taskInstance = args.TaskInstance;

            Logger.Current.Info($"Background task '{taskInstance.Task.Name}' activated");
            switch (taskInstance.Task.Name)
            {
            case InProcessTestBackgroundTask.Name:
                BackgroundTaskService.Run <InProcessTestBackgroundTask>(taskInstance);
                break;

            default:
                Logger.Current.Warn($"Unknown background task '{taskInstance.Task.Name}'");
                break;
            }
        }
示例#9
0
        public async void AutoSaveSetup()
        {
            IsAutoSaveBackgroundTaskLoading = true;

            if (AutoSave)
            {
                //AutoSave = await BackgroundTaskService.RegisterBackgroundTaskAsync(
                //    BackgroundTaskService.AUTO_SAVE_BACKGROUND_TASK_NAME,
                //    typeof(Tasks.AutoSaveBackgroundTask).FullName);
            }
            else
            {
                if (BackgroundTaskService.UnregisterbackgroundTask(BackgroundTaskService.AUTO_SAVE_BACKGROUND_TASK_NAME))
                {
                    AppSettingsService.SaveSetting(AppSettingsService.LAST_AUTO_SAVE_IMAGE, string.Empty);
                }
            }

            AppSettingsService.SaveSetting(AppSettingsService.AUTO_SAVE_SETTINGS, AutoSave);

            IsAutoSaveBackgroundTaskLoading = false;
        }
示例#10
0
        public async void AutoWallpaperSetup()
        {
            IsAutoWallpaperTaskLoading = true;

            if (AutoWallpaper)
            {
                //AutoWallpaper = await BackgroundTaskService.RegisterBackgroundTaskAsync(
                //    BackgroundTaskService.AUTO_START_BACKGROUND_TASK_NAME,
                //    typeof(Tasks.StartImageBackgroundTask).FullName);
            }
            else
            {
                if (BackgroundTaskService.UnregisterbackgroundTask(BackgroundTaskService.AUTO_START_BACKGROUND_TASK_NAME))
                {
                    AppSettingsService.SaveSetting(AppSettingsService.LAST_AUTO_START_IMAGE, string.Empty);
                }
            }

            AppSettingsService.SaveSetting(AppSettingsService.AUTO_WALLPAPER_SETTINGS, AutoWallpaper);

            IsAutoWallpaperTaskLoading = false;
        }
示例#11
0
        public async void LiveTileSetup()
        {
            IsLiveTileBackgroundTaskLoading = true;

            if (LiveTile)
            {
                //LiveTile = await BackgroundTaskService.RegisterBackgroundTaskAsync(
                //    BackgroundTaskService.LIVE_TILE_BACKGROUND_TASK_NAME,
                //    typeof(Tasks.LiveTileBackgroundTask).FullName);
            }
            else
            {
                if (BackgroundTaskService.UnregisterbackgroundTask(BackgroundTaskService.LIVE_TILE_BACKGROUND_TASK_NAME))
                {
                    TileUpdateManager.CreateTileUpdaterForApplication().Clear();
                    AppSettingsService.SaveSetting(AppSettingsService.LAST_LIVE_TILE_IMAGE, string.Empty);
                }
            }

            AppSettingsService.SaveSetting(AppSettingsService.LIVE_TILE_SETTINGS, LiveTile);

            IsLiveTileBackgroundTaskLoading = false;
        }
示例#12
0
 protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
 {
     BackgroundTaskService.Start(args.TaskInstance);
 }
示例#13
0
        private async void OnLaunchedOrActivated(IActivatedEventArgs args)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }
            if (args is LaunchActivatedEventArgs launchArgs)
            {
                if (!launchArgs.PrelaunchActivated)
                {
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(null);
                        (Window.Current.Content as Page).OpenFromSplashScreen(launchArgs.SplashScreen.ImageLocation);
                    }
                }
                Activate();
                Window.Current.Activate();
                BackgroundTaskService.RegisterAppTriggerBackgroundTasks();
            }
            else if (args is ToastNotificationActivatedEventArgs toastActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.Protocol)
                {
                    if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                    {
                        await HandleProtocolActivationArguments(args);
                    }
                    else
                    {
                        if (Window.Current.Content == null)
                        {
                            Window.Current.Content = new MainPage(args);
                        }
                        Activate();
                    }
                }
                else if (args.Kind == ActivationKind.ToastNotification)
                {
                    var mainPageType = typeof(FeedView);
                    var backPageType = typeof(NotificationsView);
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    else
                    {
                        var svc = SimpleIoc
                                  .Default
                                  .GetInstance <IAsyncNavigationService>();
                        try
                        {
                            var toastArgs      = QueryString.Parse(toastActivatedEventArgs.Argument);
                            var notificationId = toastArgs["notificationId"] as string;
                            var repoId         = long.Parse(toastArgs["repoId"]);

                            string group = null,
                                   tag   = $"N{notificationId}+R{repoId}";

                            var repo = await RepositoryUtility.GetRepository(repoId);

                            switch (toastArgs["action"])
                            {
                            case "showIssue":
                                var issueNumber = int.Parse(toastArgs["issueNumber"]);

                                var issue = await IssueUtility.GetIssue(repo.Id, issueNumber);

                                tag  += $"+I{issueNumber}";
                                group = "Issues";
                                await svc.NavigateAsync(typeof(IssueDetailView), new Tuple <Repository, Issue>(repo, issue), backPageType : backPageType);

                                break;

                            case "showPr":
                                var prNumber = int.Parse(toastArgs["prNumber"]);
                                var pr       = await PullRequestUtility.GetPullRequest(repoId, prNumber);

                                tag  += $"+P{pr.Number}";
                                group = "PullRequests";
                                await svc.NavigateAsync(typeof(PullRequestDetailView), new Tuple <Repository, PullRequest>(repo, pr), backPageType : backPageType);

                                break;
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(tag) && !StringHelper.IsNullOrEmptyOrWhiteSpace(group))
                            {
                                ToastNotificationManager.History.Remove(tag, group);
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(notificationId))
                            {
                                await NotificationsService.MarkNotificationAsRead(notificationId);
                            }
                        }
                        catch
                        {
                            await svc.NavigateAsync(mainPageType);
                        }
                    }

                    Activate();
                    Window.Current.Activate();
                }
            }
            else if (args is StartupTaskActivatedEventArgs startupTaskActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.StartupTask)
                {
                    var payload = ActivationKind.StartupTask.ToString();
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    (Window.Current.Content as Frame).Navigate(typeof(NotificationsView));
                }
            }
        }
示例#14
0
        protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            var taskInstance = args.TaskInstance;

            taskInstance.Canceled += TaskInstance_Canceled;
            base.OnBackgroundActivated(args);
            var triggerDetails = taskInstance.TriggerDetails;
            var taskName       = taskInstance.Task.Name;

            switch (taskName)
            {
            case "AppTrigger":
                _AppTriggerDeferral = taskInstance.GetDeferral();
                if (!(triggerDetails is ApplicationTriggerDetails appTriggerDetails))
                {
                    throw new InvalidOperationException();
                }
                await _ExExecSession.RunActionAsExtentedAction(() =>
                {
                    ExecutionService.RunActionInUiThread(async() =>
                    {
                        try
                        {
                            var appArgs = appTriggerDetails.Arguments;
                            if (!appArgs.TryGetValue("action", out object action))
                            {
                                throw new ArgumentNullException(nameof(action));
                            }
                            if (!appArgs.TryGetValue("what", out object what))
                            {
                                throw new ArgumentNullException(nameof(what));
                            }
                            if (!appArgs.TryGetValue("type", out object type))
                            {
                                throw new ArgumentNullException(nameof(type));
                            }
                            if (!appArgs.TryGetValue("location", out object location))
                            {
                                throw new ArgumentNullException(nameof(location));
                            }
                            if (!appArgs.TryGetValue("filter", out object filter))
                            {
                                throw new ArgumentNullException(nameof(filter));
                            }
                            if (!appArgs.TryGetValue("sendMessage", out object sendMessage))
                            {
                                throw new ArgumentNullException(nameof(type));
                            }

                            if (!(action is string a) || StringHelper.IsNullOrEmptyOrWhiteSpace(a))
                            {
                                throw new ArgumentException($"'{nameof(action)}' has an invalid value");
                            }

                            if (!(what is string w) || StringHelper.IsNullOrEmptyOrWhiteSpace(w))
                            {
                                throw new ArgumentException($"'{nameof(what)}' has an invalid value");
                            }

                            if (!(type is string t) || StringHelper.IsNullOrEmptyOrWhiteSpace(t))
                            {
                                throw new ArgumentNullException(nameof(type));
                            }

                            if (!(location is string l) || StringHelper.IsNullOrEmptyOrWhiteSpace(l))
                            {
                                throw new ArgumentException($"'{nameof(location)}' has an invalid value");
                            }

                            if (!(filter is string f) || StringHelper.IsNullOrEmptyOrWhiteSpace(f))
                            {
                                throw new ArgumentException($"'{nameof(filter)}' has an invalid value");
                            }

                            if (!(sendMessage is bool sm))
                            {
                                throw new ArgumentException($"'{nameof(sendMessage)}' has an invalid value");
                            }

                            if (a == "sync")
                            {
                                if (w == "notifications")
                                {
                                    var notifications = new ObservableCollection <Octokit.Notification>();
                                    if (l == "online")
                                    {
                                        var filters = f.Split(',');
                                        bool isAll  = false, isParticipating = false, isUnread = true;
                                        if (filter != null && filters.Length > 0)
                                        {
                                            isAll           = filters.Contains("all", StringComparer.OrdinalIgnoreCase);
                                            isParticipating = filters.Contains("participating", StringComparer.OrdinalIgnoreCase);
                                            isUnread        = filters.Contains("unread", StringComparer.OrdinalIgnoreCase);
                                        }
                                        notifications = await NotificationsService.GetAllNotificationsForCurrentUser(isAll, isParticipating);

                                        if (t == "toast")
                                        {
                                            if (sm)
                                            {
                                                if (isAll)
                                                {
                                                    NotificationsViewmodel.AllNotifications = notifications;
                                                    SendMessage(new UpdateAllNotificationsCountMessageType {
                                                        Count = notifications?.Count ?? 0
                                                    });
                                                }
                                                else if (isParticipating)
                                                {
                                                    NotificationsViewmodel.ParticipatingNotifications = notifications;
                                                    SendMessage(new UpdateParticipatingNotificationsCountMessageType {
                                                        Count = notifications?.Count ?? 0
                                                    });
                                                }
                                                else if (isUnread)
                                                {
                                                    AppViewmodel.UnreadNotifications = notifications;
                                                    SendMessage(new UpdateUnreadNotificationsCountMessageType {
                                                        Count = notifications?.Count ?? 0
                                                    });
                                                }
                                            }
                                            if (SettingsService.Get <bool>(SettingsKeys.IsToastEnabled))
                                            {
                                                await AppViewmodel.UnreadNotifications?.ShowToasts();
                                            }
                                        }
                                        else if (t == "tiles")
                                        {
                                            var tile = await notifications[0].BuildTiles();
                                            TileUpdateManager
                                            .CreateTileUpdaterForApplication()
                                            .Update(tile);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            ToastHelper.ShowMessage(ex.Message, ex.ToString());
                        }
                    });
                }, ExExecSession_Revoked, _AppTriggerDeferral);

                break;

            case "SyncNotifications":
                _SyncDeferral = taskInstance.GetDeferral();
                await _ExExecSession.RunActionAsExtentedAction(() =>
                {
                    ExecutionService.RunActionInUiThread(async() =>
                    {
                        await BackgroundTaskService.LoadUnreadNotifications(true);
                    });
                }, ExExecSession_Revoked, _SyncDeferral);

                break;

            case "ToastNotificationAction":
                _ToastDeferral = taskInstance.GetDeferral();
                if (!(triggerDetails is ToastNotificationActionTriggerDetail toastTriggerDetails))
                {
                    throw new ArgumentException();
                }
                await _ExExecSession.RunActionAsExtentedAction(() =>
                {
                    ExecutionService.RunActionInUiThread(async() =>
                    {
                        try
                        {
                            var toastArgs      = QueryString.Parse(toastTriggerDetails.Argument);
                            var notificationId = toastArgs["notificationId"] as string;
                            await NotificationsService.MarkNotificationAsRead(notificationId);
                            await BackgroundTaskService.LoadUnreadNotifications(true);
                        }
                        catch (Exception ex)
                        {
                            ToastHelper.ShowMessage(ex.Message, ex.ToString());
                        }
                    });
                }, ExExecSession_Revoked, _ToastDeferral);

                break;

                //case "ToastNotificationChangedTask":
                //var toastChangedTriggerDetails = taskInstance.TriggerDetails as ToastNotificationHistoryChangedTriggerDetail;
                //var collectionId = toastChangedTriggerDetails.CollectionId;
                //var changedType = toastChangedTriggerDetails.ChangeType;
                //if (changedType == ToastHistoryChangedType.Removed)
                //{

                //}
                //break;
            }
        }