Ejemplo n.º 1
0
        public bool MoveNext()
        {
            // initial load
            if (_itemRange == null)
            {
                var initialData = _fetch(null);
                _itemRange = initialData.ItemRange;
                _page      = initialData.Data.GetEnumerator();
                return(_page.MoveNext());
            }
            if (_page.MoveNext())
            {
                return(true);
            }
            if (_itemRange.IsComplete)
            {
                return(false);
            }
            // page load
            var nextPage = _fetch(_itemRange.Increment());

            _itemRange = nextPage.ItemRange;
            _page      = nextPage.Data.GetEnumerator();
            return(_page.MoveNext());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiResponse&lt;T&gt;" /> class.
        /// </summary>
        /// <param name="statusCode">HTTP status code.</param>
        /// <param name="headers">HTTP headers.</param>
        /// <param name="data">Data (parsed HTTP body)</param>
        public ApiResponse(int statusCode, IDictionary <string, string> headers, T data)
        {
            this.StatusCode = statusCode;
            this.Headers    = headers;
            this.Data       = data;
            ItemRange itemRange;

            ItemRange.TryParse(headers, out itemRange);
            ItemRange = itemRange;
        }
Ejemplo n.º 3
0
        public static bool TryParse(IDictionary <string, string> headers, out ItemRange range)
        {
            range = null;
            if (headers == null || !headers.ContainsKey(HeaderName))
            {
                return(false);
            }
            var match = ItemRangeHeaderRegex.Value.Match(headers[HeaderName]);

            if (!match.Success)
            {
                return(false);
            }
            int start, end, total;

            range = new ItemRange {
                IsAllResults = match.Groups["all"].Success,
                Start        = int.TryParse(match.Groups["start"].Value, out start) ? start : -1,
                End          = int.TryParse(match.Groups["end"].Value, out end) ? end : -1,
                Total        = int.TryParse(match.Groups["total"].Value, out total) ? total : -1,
            };
            return(true);
        }
Ejemplo n.º 4
0
 public PagedResultCollection(IEnumerable <T> enumerable, ItemRange itemRange)
 {
     _enumerable = enumerable;
     Count       = itemRange.Total;
     _itemRange  = itemRange;
 }
Ejemplo n.º 5
0
 public void Reset()
 {
     _itemRange = null;
     _page      = null;
 }