/// <summary> /// Builds the uri for purpose of probing any remaining entries satisfying the request of service context /// use the last entry's token in the feed as the marker of skiptoken; /// and reduce the $top count if top was in context request URI. /// </summary> /// <param name="context">The service context object</param> /// <returns>Uri object if a meaningful prober can be constructed; null otherwise </returns> private static Uri ConstructProbeUri(ServiceContext context) { Uri result = null; JObject response = JsonParserHelper.GetResponseObject(context); if (response != null) { JArray entries = JsonParserHelper.GetEntries(response); if (entries != null) { JObject lastEntry = JsonParserHelper.GetLastEntry(entries); if (lastEntry != null) { string lastToken = JsonParserHelper.GetTokenOfEntry(lastEntry); string lastTokenOfValues = ResourcePathHelper.GetValuesOfKey(lastToken); var uri = context.Destination; ResourcePathHelper pathHelper = new ResourcePathHelper(uri); // replace top value with the reduced value, if $top was in context request string topValue = pathHelper.GetQueryValue("$top"); if (!string.IsNullOrEmpty(topValue)) { pathHelper.RemoveQueryOption("$top"); int entriesGot = entries.Count; int entriesToGet; if (Int32.TryParse(topValue, out entriesToGet) && entriesToGet > entriesGot) { int entriesLeft = entriesToGet - entriesGot; pathHelper.AddQueryOption("$top", entriesLeft.ToString(CultureInfo.InvariantCulture)); } } // set up new skiptoken query pathHelper.RemoveQueryOption("$skiptoken"); pathHelper.AddQueryOption("$skiptoken", lastTokenOfValues); result = new Uri(pathHelper.Product); } } } return result; }
/// <summary> /// Builds the uri for purpose of probing the empty feed based on the base uri string. /// </summary> /// <param name="context">The service context object</param> /// <returns>Uri object if a meaningful prober can be constructed; null otherwise </returns> private static Uri ConstructProbeUri(ServiceContext context) { int safetyTopping = 20; Uri result = null; // find out how many entries in the base feed Uri uriFeedCount = new Uri(context.DestinationBasePath + "/$count"); var resp = WebHelper.Get(uriFeedCount, Constants.AcceptHeaderAtom, RuleEngineSetting.Instance().DefaultMaximumPayloadSize, context.RequestHeaders); if (resp.StatusCode.HasValue && resp.StatusCode.Value == System.Net.HttpStatusCode.OK && !string.IsNullOrEmpty(resp.ResponsePayload)) { string payload = resp.ResponsePayload.Trim(); int count = 0; if (Int32.TryParse(payload, out count) && count >= 0) { int countToSkip = count + safetyTopping; Uri uriBaseFeed = new Uri(context.DestinationBasePath); ResourcePathHelper pathHelper = new ResourcePathHelper(uriBaseFeed); pathHelper.AddQueryOption("$skip", countToSkip.ToString(CultureInfo.InvariantCulture)); result = new Uri(pathHelper.Product); } } return result; }