private static RegionGenerationByFuelTypeResult GetGenerationByFuelTypeData(Uri uri, RequestGenerationByFuelTypeParams request) { using (var client = new HttpClient()) { client.BaseAddress = uri; client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.PostAsJsonAsync("", request).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsAsync<RegionGenerationByFuelTypeResult>().Result; return result; } throw new Exception(String.Format("Failed to contact web api {0} with error code {1} ({2})", uri, response.StatusCode, response.Content)); } }
private static RequestGenerationByFuelTypeParams ConstructRequest(DateTimeOffset? newestAemoInterval, Dictionary<string, DateTimeOffset?> newestApviSolarIntervalByRegion, int resolution) { // The APVI web API expects its parameter region ids to be postfixed with 1 but does not return them postfixed with 1. var request5Min = new RequestGenerationByFuelTypeParams { NewestAemoInterval = newestAemoInterval, NewestSolarIntervals = newestApviSolarIntervalByRegion .ToLookup(r => r.Value) .Where(g => g.Key.HasValue) .Select(g => new IntervalRegions { NewestInterval = g.Key.Value, RegionIds = g.Select(r => r + "1").ToArray() }) .ToArray(), Resolution = resolution }; return request5Min; }