Beispiel #1
0
        public async Task RenewAsync(string userId, ReminderRegistration registration)
        {
            var reminder = await context.Reminders.Where(v => v.UserId == userId && v.Id == registration.Id).SingleAsync();

            reminder.Expires = registration.Expires;
            await context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task AddAsync(string userId, ReminderRequest request, ReminderRegistration registration)
        {
            var user = await context.Users.Where(v => v.Id == userId).SingleOrDefaultAsync();

            var storedReminder = new StoredReminder()
            {
                ClientState     = request.ClientState,
                Expires         = registration.Expires,
                Id              = registration.Id,
                Minutes         = request.Minutes,
                NotificationUri = request.NotificationUri
            };

            if (null == user)
            {
                user = new User()
                {
                    Id        = userId,
                    Reminders = new List <StoredReminder>()
                    {
                        storedReminder
                    }
                };
                await context.Users.AddAsync(user);
            }
            else
            {
                if (null == user.Reminders)
                {
                    user.Reminders = new List <StoredReminder>();
                }
                user.Reminders.Add(storedReminder);
            }
            await context.SaveChangesAsync();
        }
        public async Task <UserInformation> MaintainAsync(string userId)
        {
            var sm = maintainanceSemaphores.GetOrAdd(userId, (key) => new SemaphoreSlim(1));

            try
            {
                await sm.WaitAsync();

                var user = await userRepository.GetAsync(userId);

                if (null == user)
                {
                    return(null);
                }
                bool reminderInactive = null == user.ReminderId || !await calendarService.Users[userId].Reminders[user.ReminderId].IsAliveAsync();
                if (reminderInactive)
                {
                    ReminderRegistration registration = null;
                    try
                    {
                        registration = await calendarService.Users[userId].Reminders.RegisterAsync(new ReminderRequest()
                        {
                            Minutes         = (uint)FocusConstants.FocusScanTime.TotalMinutes,
                            ClientState     = userId,
                            NotificationUri = options.ReminderCallbackUri
                        });
                        await digitLogger.LogForUser(userId, "Registered reminder");
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Could not register reminder");
                        await digitLogger.LogErrorForUser(userId, "Could not register reminder");
                    }
                    if (null != registration)
                    {
                        reminderInactive = false;
                        user.ReminderId  = registration.Id;
                        await userRepository.StoreReminderIdAsync(userId, user.ReminderId);
                        await InstallButlerForReminderRenewal(registration);
                    }
                }
                var userInformation = new UserInformation()
                {
                    PushChannelRegistered  = await PushChannelRegistered(userId),
                    CalendarReminderActive = !reminderInactive
                };

                return(userInformation);
            }
            finally
            {
                sm.Release();
            }
        }
Beispiel #4
0
        public async Task <ReminderRegistration> RenewAsync(string userId, string id)
        {
            var registration = new ReminderRegistration()
            {
                Expires = DateTime.Now.AddMinutes(ExpirationMinutes),
                Id      = id
            };
            await reminderRepository.RenewAsync(userId, registration);

            return(registration);
        }
 private async Task InstallButlerForReminderRenewal(ReminderRegistration registration)
 {
     await butler.InstallAsync(new WebhookRequest()
     {
         When = registration.Expires.AddMinutes(-4),
         Data = new RenewReminderRequest()
         {
             ReminderId = registration.Id
         },
         Url = options.ReminderMaintainanceCallbackUri
     });
 }
Beispiel #6
0
        public async Task <ReminderRegistration> RegisterAsync(string userId, ReminderRequest request)
        {
            var registration = new ReminderRegistration()
            {
                Expires = DateTime.Now.AddMinutes(ExpirationMinutes),
                Id      = Guid.NewGuid().ToString()
            };
            await reminderRepository.AddAsync(userId, request, registration);

            await calendarService.InstallNotifications(userId);

            await MaintainReminderAsync(registration.Id);

            return(registration);
        }