Beispiel #1
0
        private LongPollHistoryResponse GetLongPoolHistory()
        {
            if (!Ts.HasValue)
            {
                GetLongPoolServer(null);
            }
            MessagesGetLongPollHistoryParams rp = new MessagesGetLongPollHistoryParams();

            rp.Ts  = Ts.Value;
            rp.Pts = Pts;

            int c = 0;
            LongPollHistoryResponse history = null;
            string errorLog = "";

            while (c < 5 && history == null)
            {
                c++;
                try
                {
                    history = vkAcc.Messages.GetLongPollHistory(rp);
                }
                catch (TooManyRequestsException)
                {
                    Thread.Sleep(150);
                    c--;
                }
                catch (Exception ex)
                {
                    DataBaseCenter        dataBase  = DataBaseCenter.Create();
                    System.Data.DataTable dataTable = dataBase.GetDataTable("SELECT значение FROM Настройки WHERE название='vk'");
                    string[] str = dataTable.Rows[0].ItemArray[0].ToString().Split("|".ToCharArray());
                    ulong    appId;
                    ulong.TryParse(str[0], out appId);
                    vkAcc.Authorize(new ApiAuthParams
                    {
                        ApplicationId = appId,
                        Login         = str[1],
                        Password      = str[2],
                        AccessToken   = str[3],
                        Settings      = Settings.All
                    });
                    try { GetLongPoolServer(null); } catch { };
                }
            }

            if (history != null)
            {
                Pts = history.NewPts;
                foreach (var m in history.Messages)
                {
                    m.FromId = m.Type == VkNet.Enums.MessageType.Sended ? vkAcc.UserId : m.UserId;
                }
            }

            return(history);
        }
Beispiel #2
0
        /// <inheritdoc />
        public LongPollHistoryResponse GetLongPollHistory(MessagesGetLongPollHistoryParams @params)
        {
            VkErrors.ThrowIfNumberIsNegative(expr: () => @params.PreviewLength);
            VkErrors.ThrowIfNumberIsNegative(expr: () => @params.EventsLimit);
            VkErrors.ThrowIfNumberIsNegative(expr: () => @params.MsgsLimit);
            VkErrors.ThrowIfNumberIsNegative(expr: () => @params.MaxMsgId);

            return(_vk.Call(methodName: "messages.getLongPollHistory", parameters: @params));
        }
Beispiel #3
0
        private LongPollHistoryResponse GetLongPoolHistory()
        {
            if (!Ts.HasValue)
            {
                GetLongPoolServer(null);
            }
            MessagesGetLongPollHistoryParams rp = new MessagesGetLongPollHistoryParams();

            rp.Ts  = Ts.Value;
            rp.Pts = Pts;

            int c = 0;
            LongPollHistoryResponse history = null;
            string errorLog = "";

            while (c < 5 && history == null)
            {
                c++;
                try
                {
                    history = _account.Messages.GetLongPollHistory(rp);
                }
                catch (TooManyRequestsException)
                {
                    Thread.Sleep(150);
                    c--;
                }
                catch (Exception ex)
                {
                    errorLog += string.Format("{0} - {1}{2}", c, ex.Message, Environment.NewLine);
                }
            }

            if (history != null)
            {
                Pts = history.NewPts;
                foreach (var m in history.Messages)
                {
                    m.FromId = m.Type == VkNet.Enums.MessageType.Sended ? _account.UserId : m.UserId;
                }
            }
            else
            {
                throw new NotImplementedException(errorLog);
            }

            return(history);
        }
Beispiel #4
0
        static LongPollHistoryResponse GetLongPoolHistory()
        {
            if (!Ts.HasValue)
            {
                GetLongPoolServer(null);
            }
            MessagesGetLongPollHistoryParams rp = new MessagesGetLongPollHistoryParams();

            rp.Ts  = Ts.Value;
            rp.Pts = Pts;
            int i = 0;
            LongPollHistoryResponse history = null;
            string errorLog = "";

            while (i < 5 && history == null)
            {
                i++;
                try
                {
                    history = vkapi.Messages.GetLongPollHistory(rp);
                }
                catch (TooManyRequestsException)
                {
                    Thread.Sleep(150);
                    i--;
                }
                catch (Exception ex)
                {
                    errorLog += string.Format("{0} - {1}{2}", i, ex.Message, Environment.NewLine);
                }
            }

            if (history != null)
            {
                Pts = history.NewPts;
                foreach (var m in history.Messages)
                {
                    m.FromId = m.Type == MessageType.Sended ? vkapi.UserId : m.UserId;
                }
            }
            else
            {
                ColorMessage(errorLog, ConsoleColor.Red);
            }
            return(history);
        }
Beispiel #5
0
        private static LongPollHistoryResponse GetLongPoolHistory()
        {
            if (!ts.HasValue)
            {
                GetLongPoolServer(null);
            }
            var pollHistoryParams = new MessagesGetLongPollHistoryParams {
                Ts = ts.Value, Pts = pts
            };
            var i = 0;
            LongPollHistoryResponse history = null;
            var errorLog = "";

            while (i < 5 && history == null)
            {
                i++;
                try
                {
                    history = vkApi.Messages.GetLongPollHistory(pollHistoryParams);
                }
                catch (TooManyRequestsException)
                {
                    Thread.Sleep(150);
                    i--;
                }
                catch (Exception ex)
                {
                    errorLog += $"{i} - {ex.Message}{Environment.NewLine}";
                }
            }

            if (history == null)
            {
                return(history);
            }
            pts = history.NewPts;
            foreach (var message in history.Messages)
            {
                message.FromId = message.Type == MessageType.Sended ? vkApi.UserId : message.FromId;
            }
            return(history);
        }
Beispiel #6
0
 /// <inheritdoc />
 public Task <LongPollHistoryResponse> GetLongPollHistoryAsync(MessagesGetLongPollHistoryParams @params)
 {
     return(TypeHelper.TryInvokeMethodAsync(func: () => GetLongPollHistory(@params: @params)));
 }
Beispiel #7
0
		public LongPollHistoryResponse GetLongPollHistory(MessagesGetLongPollHistoryParams @params)
		{
			VkErrors.ThrowIfNumberIsNegative(() => @params.PreviewLength);
			VkErrors.ThrowIfNumberIsNegative(() => @params.EventsLimit);
			VkErrors.ThrowIfNumberIsNegative(() => @params.MsgsLimit);
			VkErrors.ThrowIfNumberIsNegative(() => @params.MaxMsgId);

			return _vk.Call("messages.getLongPollHistory", @params);
		}
Beispiel #8
0
 public LongPollHistoryResponse GetLongPollHistory(MessagesGetLongPollHistoryParams @params)
 {
     throw new NotImplementedException();
 }
Beispiel #9
0
 public Task <LongPollHistoryResponse> GetLongPollHistoryAsync(MessagesGetLongPollHistoryParams @params)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 /// <inheritdoc />
 public async Task <LongPollHistoryResponse> GetLongPollHistoryAsync(MessagesGetLongPollHistoryParams @params)
 {
     return(await TypeHelper.TryInvokeMethodAsync(() => _vk.Messages.GetLongPollHistory(@params)));
 }