Exemple #1
0
        private static async Task <SantaResponse> Låge2(ParticipateResponse participateResponse, HttpClient httpClient)
        {
            string documentId = participateResponse.Id.ToString();

            Console.WriteLine("Creating search client...");

            SearchClient client = new SearchClient(participateResponse.Credentials.Username, participateResponse.Credentials.Password, cloudId);

            Console.WriteLine("Fetching document...");

            SantaInformation santaInfo = client.GetDocument(index, documentId);

            Console.WriteLine("Converting to meters...");

            IEnumerable <SantaMovement> alignedSantaMovements = santaInfo.ConvertAllMovementsToMeters();

            Console.WriteLine($"Moving santa...starting from: {santaInfo.CanePosition.ToString()}");

            GeoPoint santaEndlocation = SantaMover.Move(santaInfo.CanePosition, alignedSantaMovements);

            Console.WriteLine($"lat:{santaEndlocation.lat.ToString(CultureInfo.GetCultureInfo("en-US"))}, lon: {santaEndlocation.lon.ToString(CultureInfo.GetCultureInfo("en-US"))}");

            HttpResponseMessage apiResponse = await httpClient.PostAsJsonAsync("/api/santarescue", new { id = participateResponse.Id, position = santaEndlocation });

            if (!apiResponse.IsSuccessStatusCode)
            {
                throw new ChristmasException($"{apiResponse.StatusCode}: {(await apiResponse.Content.ReadAsStringAsync())}");
            }

            Console.WriteLine(await apiResponse.Content.ReadAsStringAsync());

            return(await apiResponse.Content.ReadAsAsync <SantaResponse>());
        }
        public SantaInformation GetDocument(string index, string documentId)
        {
            var request = new GetRequest(index, documentId);

            try
            {
                GetResponse <SantaInformation> result = _client.Get <SantaInformation>(request);
                if (result.IsValid)
                {
                    return(result.Source);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }

            return(SantaInformation.Empty());
        }