static async Task Main(string[] args) { CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("https://vertica-xmas2019.azurewebsites.net"); //låge 1 ParticipateResponse participateResponse = await Låge1(httpClient); //låge 2 SantaResponse data = await Låge2(participateResponse, httpClient); //låge 3 ReindeerResponse result = await Låge3(participateResponse, data, httpClient); //låge 4 await Låge4(participateResponse, result.ToyDistributionXmlUrl, httpClient); Console.ReadLine(); } }
private static async Task <ReindeerResponse> Låge3(ParticipateResponse participateResponse, SantaResponse data, HttpClient httpClient) { CosmosConnector cosmosConnector = new CosmosConnector(_documentdbEndpointUri, _authKey, _databaseId, _collectionId); List <ReindeerLocation> positions = new List <ReindeerLocation>(); foreach (Zone zone in data.Zones) { Zone normalized = zone.NormalizeRadius(); Console.WriteLine($"Normalized - {normalized.ToString()}"); ReindeerPosition locatedReindeer = await cosmosConnector.GetDocumentByZoneAsync(normalized); positions.Add(new ReindeerLocation() { Name = locatedReindeer.Name, Position = new GeoPoint(locatedReindeer.Location.Position.Latitude, locatedReindeer.Location.Position.Longitude) }); Console.WriteLine("-----------------------------------------------------------"); } HttpResponseMessage apiReindeerResponse = await httpClient.PostAsJsonAsync("/api/reindeerrescue", new { id = participateResponse.Id, locations = positions }); if (!apiReindeerResponse.IsSuccessStatusCode) { throw new ChristmasException($"{apiReindeerResponse.StatusCode}: {(await apiReindeerResponse.Content.ReadAsStringAsync())}"); } Console.WriteLine("##############################################################################"); ReindeerResponse result = await apiReindeerResponse.Content.ReadAsAsync <ReindeerResponse>(); Console.WriteLine($"Result: {result}"); return(result); }