public List <ContentFulRowData> GetContentEntries(string typeID)
        {
            int skip = 0;
            int take = 50;
            var data = new List <Models.ContentFulRowData>();

            // var categories = await _apiClient.GetEntriesByType("category", QueryBuilder<Category>.New.Include(5).LocaleIs(HttpContext?.Session?.GetString(Startup.LOCALE_KEY) ?? CultureInfo.CurrentCulture.ToString()));
            var  type    = ContentTypes.First(p => p.TypeID.Equals(typeID));
            bool allData = false;

            while (!allData)
            {
                var queryBuilder = QueryBuilder <Entry <dynamic> > .New.ContentTypeIs(typeID);

                queryBuilder = queryBuilder.Skip(skip).Limit(take).Include(10).OrderBy("-sys.createdAt");
                var entries = _apiClient.GetEntriesCollection <Entry <dynamic> >(queryBuilder).Result;

                foreach (var entry in entries)
                {
                    data.Add(new ContentFulRowData(entry.SystemProperties.Id, entry.SystemProperties.Version ?? 1, typeID, entry));
                }

                if (entries.Items.Count() < take)
                {
                    allData = true;
                }
                else
                {
                    skip += take;
                }
            }
            return(data);
        }
Example #2
0
        private async void DisplayRequest(Request request)
        {
            var headers = request.Headers ?? new List <Header>();

            var accept = headers.GetValue(Header.Accept);

            if (!Accepts.Contains(accept))
            {
                accept = Accepts.First();
            }

            var contentType = headers.GetValue(Header.ContentType);

            if (!ContentTypes.Contains(contentType))
            {
                contentType = ContentTypes.First();
            }

            headers = headers
                      .Where(h =>
                             !h.Name.Equals(Header.Accept, StringComparison.OrdinalIgnoreCase) &&
                             !h.Name.Equals(Header.AcceptEncoding, StringComparison.OrdinalIgnoreCase) &&
                             !h.Name.Equals(Header.ContentType, StringComparison.OrdinalIgnoreCase))
                      .ToList();

            headers.Add(new Header(Header.Accept, accept));
            headers.Add(new Header(Header.AcceptEncoding, Header.AcceptEncodingValue));
            headers.Add(new Header(Header.ContentType, contentType));

            SelectedMethod      = request.Method;
            Url                 = request.Url;
            SelectedAccept      = accept;
            RequestBody         = new TextDocument(await Prettify(request.Body, contentType));
            SelectedContentType = contentType;
            Headers             = new BindableCollection <Header>(headers.OrderBy(h => h.Name));
            HeaderName          = null;
            HeaderValue         = null;

            var token = request.NamedAuthorizationState;

            if (token == null || token.AuthorizationState == null)
            {
                SelectedToken = _anonymousToken;
            }
            else
            {
                if (Tokens.All(t => t.Guid != token.Guid))
                {
                    Tokens.Add(token);
                }

                SelectedToken = token;
            }

            var response    = request.Response;
            var hasResponse = response != null;

            if (!hasResponse)
            {
                ResponseBody = null;
                return;
            }

            ResponseTime        = request.ResponseTime;
            ResponseBody        = new TextDocument(await Prettify(response.Body, response.ContentType));
            ResponseContentType = response.ContentType;
            HttpStatusCode      = response.HttpStatusCode;
            ResponseHeaders     = new BindableCollection <Header>(response.Headers.OrderBy(h => h.Name));
        }