public JEnumerable <JObject> GetDetailedTrackingRecords(JObject masterObject) { string jsonResult = string.Empty; JEnumerable <JObject> detailObjects; using (HttpClient detailClient = new HttpClient()) { detailClient.BaseAddress = new Uri(trackingDataRequest.baseUri); detailClient.DefaultRequestHeaders.Accept.Clear(); detailClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AppConstants.TokenHeaderName, accessToken); detailClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(AppConstants.ContentTypeJson)); detailClient.DefaultRequestHeaders.Add(AppConstants.Upn, trackingDataRequest.upn); try { string detailRelativeUri = string.Format("api/Track/Detail?MasterID={0}&PageNumber=1", masterObject.Property("ID").Value.ToString()); TraceProvider.WriteLine("Executing test suit run id {0}, Getting detailed tracking data from BizTrack api {1}{2}", testSuiteRunId, detailClient.BaseAddress, detailRelativeUri); var response = detailClient.GetAsync(detailRelativeUri).Result; if (response.IsSuccessStatusCode) { jsonResult = response.Content.ReadAsStringAsync().Result; } } catch (Exception ex) { TraceProvider.WriteLine("Executing test suit run id {0}, Error while retrieving detail tracking data from BizTrack API {1}", testSuiteRunId, ex.Message); } } detailObjects = JsonHelper.AllChildren(JObject.Parse(jsonResult)) .First(c => c.Type == JTokenType.Array && c.Path.Contains(AppConstants.DetailsLiteral)) .Children <JObject>(); TraceProvider.WriteLine("Executing test suit run id {0}, detail tracking data retrieved from BizTrack API. Count is {1}", testSuiteRunId, detailObjects.Count <JObject>()); return(detailObjects); }
public JEnumerable <JObject> GetMasterTrackingRecords() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(trackingDataRequest.baseUri); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AppConstants.TokenHeaderName, accessToken); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(AppConstants.ContentTypeJson)); client.DefaultRequestHeaders.Add("upn", trackingDataRequest.upn); string jsonResult = string.Empty; JEnumerable <JObject> masterObjects; try { TraceProvider.WriteLine("Executing test suit run id {0}, Getting master tracking data from BizTrack api {1}{2}", testSuiteRunId, client.BaseAddress, trackingDataRequest.relativeUriMaster); var response = client.PostAsJsonAsync(trackingDataRequest.relativeUriMaster, trackingDataRequest.masterFilter).Result; if (response.IsSuccessStatusCode) { jsonResult = response.Content.ReadAsStringAsync().Result; } masterObjects = JsonHelper.AllChildren(JObject.Parse(jsonResult)) .First(c => c.Type == JTokenType.Array && c.Path.Contains(AppConstants.MastersLiteral)) .Children <JObject>(); TraceProvider.WriteLine("Executing test suit run id {0}, master tracking data retrieved from BizTrack api. Number of Master records {1}", testSuiteRunId, masterObjects.Count <JObject>()); } catch (Exception ex) { TraceProvider.WriteLine("Executing test suit run id {0}, Error while getting master tracking data. Error message {1}", testSuiteRunId, ex.Message); } return(masterObjects); }