Esempio n. 1
0
        public override void UpdateAlerts()
        {
            base.UpdateAlerts();
            if
            (
                String.IsNullOrWhiteSpace(Settings.UserName) ||
                default(DateTime) == LastPublicActivity
            )
            {
                System.Diagnostics.Debug.WriteLine("OmegaDomain::CancelAllAlerts");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("OmegaDomain::UpdateAlerts");
                var Limit = LastPublicActivity.AddHours(24);
                var Now   = DateTime.Now;
                int id    = BaseUpdateId;
                foreach
                (
                    var Span in
                    Settings.AlertTimeSpanTable
                    .Union(Enumerable.Range(0, 24).Select(i => TimeSpan.FromHours(i)))
                    .Where(i => Now < Limit.Add(-i).AddSeconds(-300))                                     // 基準時刻が過去あるいは5分以内場合は実行しない
                )
                {
                    //	基準時刻の90秒前に
                    var updateAt = Limit - (Span + TimeSpan.FromSeconds(90));

                    GetAlarmManager().Set
                    (
                        AlarmType.ElapsedRealtime,
                        ToAndroidTicks(updateAt),
                        PendingIntent.GetBroadcast
                        (
                            Forms.Context,
                            id++,
                            new Intent(Context, typeof(UpdateWakefulReceiver)),
                            PendingIntentFlags.UpdateCurrent
                        )
                    );
                }
            }
        }
Esempio n. 2
0
        public override void UpdateAlerts()
        {
            base.UpdateAlerts();

            if
            (
                String.IsNullOrWhiteSpace(Settings.UserName) ||
                default(DateTime) == LastPublicActivity
            )
            {
            }
            else
            {
                var binding = new TileBinding()
                {
                    Branding = TileBranding.NameAndLogo,
                    Content  = new TileBindingContentAdaptive()
                    {
                        BackgroundImage = new TileBackgroundImage
                        {
                            Source = "Assets/TileBackGround.png",
                        },
                        Children =
                        {
                            new TileText()
                            {
                                Text  = Settings.UserName,
                                Style = TileTextStyle.Body,
                            },
                            new TileText()
                            {
                                Text  = L["Last Stamp"] + ": " + LastPublicActivity.ToString("yyyy-MM-dd HH:mm"),
                                Wrap  = true,
                                Style = TileTextStyle.CaptionSubtle,
                            },
                        },
                    },
                };
                ;
                TileUpdateManager.CreateTileUpdaterForApplication().Update
                (
                    new TileNotification
                    (
                        new TileContent()
                {
                    Visual = new TileVisual()
                    {
                        TileMedium = binding,
                        TileWide   = binding,
                        TileLarge  = binding
                    }
                }
                        .GetXml()
                    )
                {
                    ExpirationTime = LastPublicActivity.AddHours(24),
                }
                );

                Debug.Write("BackgroundUpdateLastPublicActivityTask: " + typeof(BackgroundUpdateLastPublicActivityTask).FullName);
                var BackgroundUpdateTaskName = "UpdateLastPublicActivity";
                foreach (var task in BackgroundTaskRegistration.AllTasks.Where(i => i.Value.Name == BackgroundUpdateTaskName))
                {
                    task.Value.Unregister(true);
                }
                Task.Run
                (
                    async() => await BackgroundExecutionManager.RequestAccessAsync()
                )
                .ContinueWith
                (
                    t =>
                {
                    var builder            = new BackgroundTaskBuilder();
                    builder.Name           = BackgroundUpdateTaskName;
                    builder.TaskEntryPoint = typeof(BackgroundUpdateLastPublicActivityTask).FullName;
                    builder.SetTrigger(new TimeTrigger(15, false));
                    builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
                    builder.Register();
                }
                );
            }
        }