Пример #1
0
 private void DownloadUpdates()
 {
     try
     {
         var updates = _telegramMethods.GetUpdates(LastUpdateId + 1, null, null, AllowedUpdates).Result;
         if (updates.Count == 0)
         {
             return;
         }
         updates.ForEach(update =>
         {
             Update       = update;
             LastUpdateId = update.UpdateId;
             UpdatesArrivedEvent?.Invoke(this);
         });
     }
     catch (TelegramMethodsException ex)
     {
         var message = "An error occurred while receiving the update";
         UpdatesTracingStoppedEvent?.Invoke(this, new BotRequestErrorEventArgs(message, ex));
     }
     finally
     {
         DownloadBotRequestsSemaphore.Release();
     }
 }
Пример #2
0
        private void RequestMonitorTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //если образовалась очередь, выдать ошибку задержки ответа сервера
            if (!DownloadBotRequestsSemaphore.WaitOne(0))
            {
                var message = "Telegram server response timeout. Can't download content.";
                _requestMonitorTimer.Stop();
                UpdatesTracingStoppedEvent?.Invoke(this, new BotRequestErrorEventArgs(message));
                return;
            }

            DownloadUpdates();
        }
Пример #3
0
        /// <summary>
        /// Stops monitoring of new updates from Telegram server.
        /// </summary>
        /// <param name="triggerStoppedEvent"></param>
        /// <param name="message"></param>
        public void Stop(bool triggerStoppedEvent = false, string message = null)
        {
            _requestMonitorTimer.Stop();
            if (!triggerStoppedEvent)
            {
                return;
            }

            if (message == null)
            {
                message = "Monitoring of new updates was stopped manually";
            }
            UpdatesTracingStoppedEvent?.Invoke(this, new BotRequestErrorEventArgs(message));
        }