public static JurisdictionCollection GetJurisdictions() { JurisdictionCollection collection = new JurisdictionCollection(); JurisdictionList list = GetJurisdictionList(); int total = list.Data.Count; for (var i = 0; i < total; i++) { var data = list.Data[i]; string jurisdictionURL = JurisdictionsBaseURL + "/" + data.Id; int percent = (int)Math.Round(i * ((decimal)100 / total)); // ConsoleEx.WriteProgress("Getting Jurisdictions", "Jurisdictions", data.Title, percent); string jurisdictionJson = InvokeWebRequest(jurisdictionURL); var jurisdiction = JurisdictionsSerializer.Deserialize(jurisdictionJson); collection.Add(jurisdiction); } Console.WriteLine(); return(collection); }
private static JurisdictionList GetJurisdictionList() { string jsonList = InvokeWebRequest(JurisdictionsBaseURL); JurisdictionList list = JurisdictionListSerializer.Deserialize(jsonList); return(list); }
protected override void ProcessRecord() { WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Api-Key", ApiKey); HttpWebRequest request = HttpWebRequest.CreateHttp(RequestUri); request.CachePolicy = RestApi.CachePolicy; request.Headers = headers; Stopwatch stopWatch = Stopwatch.StartNew(); var responseAsync = GetWebResponseAsync(request); while (!responseAsync.IsCompleted) { WriteProgress(ProgressRecordFactory.Progress($"Waiting for response from {RequestUri}...", $"Time Elapsed: {stopWatch.Elapsed.Seconds}")); } HttpWebResponse response = (HttpWebResponse)responseAsync.Result; if (response.IsFromCache) { WriteWarning("Respose was received from the cash!"); } using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { string text = reader.ReadToEnd(); JObject obj = JObject.Parse(text); if (ReturnJObject) { WriteObject(obj); } else { JurisdictionList list = JsonModelSerializer.DeserializeList(obj.ToString()); PagingUtilities.Page(this, list.Data.ToArray()); } } }