示例#1
0
        public void InitializePushNotificationWatchTimer(int updatePeriod)
        {
            if (UpdatesHandler == null)
            {
                throw new InvalidOperationException($"{nameof(ServiceFactory)} property must be initialized first.");
            }
            if (UpdatesHandler == null)
            {
                throw new InvalidOperationException($"{nameof(MessageHandler)} property must be initialized first.");
            }

            if (_gmailDbContextWorker == null)
            {
                _gmailDbContextWorker = new GmailDbContextWorker();
            }
            //start timer which would be update push notification watch for users which expiration time approaches the end
            PushNotificationWatchTimer = new Timer(state =>
            {
                var userSettings = _gmailDbContextWorker.GetAllUsersSettings();
                userSettings.ForEach(us =>
                {
                    var difference = DateTime.UtcNow.Difference(us.Expiration);
                    if (difference.TotalHours >= 2)
                    {
                        return;
                    }
                    var service = ServiceFactory?.ServiceCollection.FirstOrDefault(s => s.From == us.UserId);
                    if (service == null)
                    {
                        return;
                    }
                    MessageHandler?.HandleStartWatchCommand(service);
                });
            }, null, updatePeriod, updatePeriod);
        }
示例#2
0
 public void InitializeMessageHandler()
 {
     if (string.IsNullOrEmpty(BotSettings.Token))
     {
         throw new InvalidOperationException($"{nameof(BotSettings.Token)} property must be specified");
     }
     if (UpdatesHandler == null)
     {
         throw new InvalidOperationException($"{nameof(UpdatesHandler)} property must be initialized first.");
     }
     MessageHandler = new MessageHandler();
 }
示例#3
0
 //restart push notification watches for all gmail control bot users
 public void InitializePushNotificationWatchesAsync(int delay)
 {
     if (UpdatesHandler == null)
     {
         throw new InvalidOperationException($"{nameof(ServiceFactory)} property must be initialized first.");
     }
     if (UpdatesHandler == null)
     {
         throw new InvalidOperationException($"{nameof(MessageHandler)} property must be initialized first.");
     }
     Task.Run(() =>
     {
         Task.Delay(delay).Wait();
         ServiceFactory?.ServiceCollection.ForEach(async s =>
         {
             await MessageHandler.HandleStartWatchCommandAsync(s)
             ;
             //probably i need to do a delay here to avoid response ddos to my server
         });
     });
 }