本文整理汇总了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);
}