Пример #1
0
 /// <inheritdoc />
 public BotsLongPollHistoryResponse GetBotsLongPollHistory(BotsLongPollHistoryParams @params)
 {
     return(_vk.CallLongPoll(@params.Server, @params));
 }
Пример #2
0
        private Task GetMessages()
        {
            LongPollServerResponse      serverResponse = vkStuff.Api.Groups.GetLongPollServer((ulong)vkStuff.GroupId);
            BotsLongPollHistoryResponse historyResponse;
            BotsLongPollHistoryParams   botsLongPollHistoryParams = new BotsLongPollHistoryParams()
            {
                Server = serverResponse.Server,
                Ts     = serverResponse.Ts,
                Key    = serverResponse.Key,
                Wait   = 25
            };

            while (true)
            {
                try
                {
#if DEBUG
                    Console.WriteLine(DateTime.Now.ToString() + " Получаю сообщения");
                    Console.WriteLine("commandsQueue count = {0}", commandsQueue.Count);
                    Console.WriteLine("messagesQueue count = {0}", updatesQueue.Count);
                    Console.WriteLine("photosQueue count = {0}", photosQueue.Count);
#endif
                    historyResponse = vkStuff.Api.Groups.GetBotsLongPollHistory(botsLongPollHistoryParams);
                    if (historyResponse == null)
                    {
                        continue;
                    }
                    botsLongPollHistoryParams.Ts = historyResponse.Ts;
                    if (!historyResponse.Updates.Any())
                    {
                        continue;
                    }
                    for (int i = 0; i < historyResponse.Updates.Count(); i++)
                    {
                        updatesQueue.Enqueue(historyResponse.Updates.ElementAt(i));
                    }
                    historyResponse = null;
                }
                catch (LongPollException exception)
                {
                    if (exception is LongPollOutdateException outdateException)
                    {
                        botsLongPollHistoryParams.Ts = outdateException.Ts;
                    }
                    else
                    {
                        LongPollServerResponse server = vkStuff.Api.Groups.GetLongPollServer((ulong)vkStuff.GroupId);
                        botsLongPollHistoryParams.Ts     = server.Ts;
                        botsLongPollHistoryParams.Key    = server.Key;
                        botsLongPollHistoryParams.Server = server.Server;
                    }
                }
                catch
                {
                    LongPollServerResponse server = vkStuff.Api.Groups.GetLongPollServer((ulong)vkStuff.GroupId);
                    botsLongPollHistoryParams.Ts     = server.Ts;
                    botsLongPollHistoryParams.Key    = server.Key;
                    botsLongPollHistoryParams.Server = server.Server;
                }
            }
        }
Пример #3
0
 /// <inheritdoc />
 public Task <BotsLongPollHistoryResponse> GetBotsLongPollHistoryAsync(BotsLongPollHistoryParams @params)
 {
     return(TypeHelper.TryInvokeMethodAsync(func: () => GetBotsLongPollHistory(@params: @params)));
 }