当前位置: 首页>>代码示例>>C#>>正文


C# IBackgroundTaskInstance.?.GetDeferral方法代码示例

本文整理汇总了C#中IBackgroundTaskInstance.?.GetDeferral方法的典型用法代码示例。如果您正苦于以下问题:C# IBackgroundTaskInstance.?.GetDeferral方法的具体用法?C# IBackgroundTaskInstance.?.GetDeferral怎么用?C# IBackgroundTaskInstance.?.GetDeferral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBackgroundTaskInstance的用法示例。


在下文中一共展示了IBackgroundTaskInstance.?.GetDeferral方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {

            Defferal = taskInstance?.GetDeferral();

            //var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
            //if (details != null)
            //{
            //    await Launcher.LaunchUriAsync(new Uri(details.Argument));
            //    Defferal.Complete();
            //    return;
            //}

            try
            {
                if (taskInstance != null) //we are already running -> started on demand
                {
                    ResourceLocator.RegisterAppDataServiceAdapter(new ApplicationDataServiceService());
                    ResourceLocator.RegisterPasswordVaultAdapter(new PasswordVaultProvider());
                    ResourceLocator.RegisterMessageDialogAdapter(new MessageDialogProvider());
                    Credentials.Init();
                }
            }
            catch (Exception)
            {
               //may be already registered... voodoo I guess
            }


            List<MalNotification> notifications = new List<MalNotification>();

            if (
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.FriendRequestAcceptDeny) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.NewRelatedAnime) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.BlogComment) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.ClubMessages) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.ForumQuoute) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.FriendRequest) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.NowAiring) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.ProfileComment) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.Payment) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.UserMentions) ||
                Settings.EnabledNotificationTypes.HasFlag(MalNotificationsTypes.WatchedTopics))
            {
                notifications.AddRange(await MalNotificationsQuery.GetNotifications());
                notifications =
                    notifications.Where(
                        notification =>
                            !notification.IsRead &&
                            (Settings.EnabledNotificationTypes & notification.Type) == notification.Type).ToList();
            }

            if ((Settings.EnabledNotificationTypes & MalNotificationsTypes.Messages) == MalNotificationsTypes.Messages)
            {
                try
                {
                    var msgs = await AccountMessagesManager.GetMessagesAsync(1);
                    foreach (var malMessageModel in msgs)
                    {
                        if (!malMessageModel.IsRead)
                        {
                            notifications.Add(new MalNotification(malMessageModel)); //I'm assuming that Ids are unique
                        }
                    }
                }
                catch (Exception)
                {
                    //no messages
                }

            }

            var allTriggeredNotifications = (string)(ResourceLocator.ApplicationDataService[nameof(RoamingDataTypes.ReadNotifications)] ?? string.Empty);
            var triggeredNotifications = allTriggeredNotifications.Split(';').ToList();

            //trigger new notifications
            foreach (var notification in notifications)
            {
                if(triggeredNotifications.Contains(notification.Id))
                    continue;

                triggeredNotifications.Add(notification.Id);
                ScheduleToast(notification);
            }

            //remove old triggered entries
            var presentNotifications = new List<string>();

            foreach (var triggeredNotification in triggeredNotifications)
            {
                if (notifications.Any(notif => notif.Id == triggeredNotification))
                    presentNotifications.Add(triggeredNotification);
            }

            ResourceLocator.ApplicationDataService[nameof(RoamingDataTypes.ReadNotifications)] = string.Join(";",presentNotifications);
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:96,代码来源:NotificationsBackgroundTask.cs


注:本文中的IBackgroundTaskInstance.?.GetDeferral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。