private void InitializeQuery(PaginatedRequestParams queryParams, PaginatedRequestParams requestParams)
 {
     queryParams.Path       = requestParams.Path;
     queryParams.HttpMethod = requestParams.HttpMethod;
     queryParams.Body       = requestParams.Body;
     queryParams.Headers    = requestParams.Headers;
 }
 protected bool Equals(PaginatedRequestParams other)
 {
     return(Start.Equals(other.Start) &&
            End.Equals(other.End) &&
            Limit == other.Limit &&
            Direction == other.Direction &&
            ExtraParameters.SequenceEqual(other.ExtraParameters));
 }
Exemple #3
0
 internal PaginatedResult(AblyResponse response, int limit, Func <PaginatedRequestParams, Task <PaginatedResult <T> > > executeDataQueryFunc)
 {
     Response             = response;
     Limit                = limit;
     ExecuteDataQueryFunc = executeDataQueryFunc;
     if (response.Headers != null)
     {
         CurrentQueryParams = PaginatedRequestParams.GetLinkQuery(response.Headers, DataRequestLinkType.Current);
         NextQueryParams    = PaginatedRequestParams.GetLinkQuery(response.Headers, DataRequestLinkType.Next);
         FirstQueryParams   = PaginatedRequestParams.GetLinkQuery(response.Headers, DataRequestLinkType.First);
     }
 }
        internal static PaginatedRequestParams Parse(string querystring)
        {
            var query = new PaginatedRequestParams {
                QueryString = querystring
            };
            var queryParameters = HttpUtility.ParseQueryString(querystring);

            foreach (var key in queryParameters.AllKeys)
            {
                switch (key.ToLower())
                {
                case "start":
                    query.Start = ToDateTime(queryParameters[key]);
                    break;

                case "end":
                    query.End = ToDateTime(queryParameters[key]);
                    break;

                case "direction":
                    if (Enum.TryParse(queryParameters[key], true, out QueryDirection direction))
                    {
                        query.Direction = direction;
                    }

                    break;

                case "limit":
                    if (int.TryParse(queryParameters[key], out var limit))
                    {
                        query.Limit = limit;
                    }

                    break;

                default:
                    query.ExtraParameters.Add(key, queryParameters[key]);
                    break;
                }
            }

            return(query);
        }
        internal HttpPaginatedResponse(AblyResponse response, int limit, PaginatedRequestParams requestParams, Func <PaginatedRequestParams, Task <HttpPaginatedResponse> > executeDataQueryFunc)
            : base(response, limit, null)
        {
            ExecuteDataQueryFunc = executeDataQueryFunc;
            StatusCode           = Response.StatusCode;
            Headers = response.Headers;

            if (Response.Headers.TryGetValues(AblyErrorCodeHeader, out var errorCodeHeaderValues))
            {
                string errCodeStr = errorCodeHeaderValues.FirstOrDefault();
                if (int.TryParse(errCodeStr, out var errCode))
                {
                    ErrorCode = errCode;
                }
            }

            if (Response.Headers.TryGetValues(AblyErrorCodeHeader, out var errorMessageHeaderValues))
            {
                ErrorMessage = errorMessageHeaderValues.FirstOrDefault();
            }

            ExecuteDataQueryFunc = executeDataQueryFunc;

            if (response.TextResponse.IsNotEmpty())
            {
                var data = JToken.Parse(response.TextResponse);
                if (data is JArray arr)
                {
                    foreach (var token in arr)
                    {
                        Items.Add(token);
                    }
                }
                else
                {
                    Items.Add(data);
                }
            }

            InitializeQuery(CurrentQueryParams, requestParams);
            InitializeQuery(NextQueryParams, requestParams);
        }