Esempio n. 1
0
        public SearchResultResponse.Response Search(DateTime from, DateTime to, string fromCode, string toCode)
        {
            // Handler to decompress Gzip
            HttpClientHandler handler = new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };


            using (var client = new HttpClient(handler))
            {
                client.DefaultRequestHeaders.Add("apikey", apiKey);
                var response = client.GetAsync(server + "v2/search?fly_from=" + fromCode + "&fly_to=" + toCode + "&date_from=05%2F12%2F2019&date_to=10%2F12%2F2019&return_from=20%2F12%2F2019&return_to=25%2F12%2F2019&nights_in_dst_from=2&nights_in_dst_to=14&max_fly_duration=20&flight_type=round&adults=1&max_stopovers=2&vehicle_type=aircraft&one_for_city=1").Result;

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = response.Content;

                    // by calling .Result you are synchronously reading the result
                    string responseString = responseContent.ReadAsStringAsync().Result;
                    SearchResultResponse.Response responseData = JsonConvert.DeserializeObject <SearchResultResponse.Response>(responseString);


                    return(responseData);
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 2
0
        public ActionResult <SearchResult> Search(string upperRight, string bottomLeft, string fromLocation, string interestType)
        {
            var charsToRemove = new string[] { "(", ")", " " };

            foreach (var c in charsToRemove)
            {
                upperRight = upperRight.Replace(c, string.Empty);
                bottomLeft = bottomLeft.Replace(c, string.Empty);
            }
            //string fff = upperRight.Split(",")[0];
            //decimal ddddd = Convert.ToDecimal(fff);
            decimal        upperRightLon = Convert.ToDecimal(upperRight.Split(",")[1], CultureInfo.InvariantCulture);
            decimal        upperRightLat = Convert.ToDecimal(upperRight.Split(",")[0], CultureInfo.InvariantCulture);
            decimal        bottomLeftLon = Convert.ToDecimal(bottomLeft.Split(",")[1], CultureInfo.InvariantCulture);
            decimal        bottomLeftLat = Convert.ToDecimal(bottomLeft.Split(",")[0], CultureInfo.InvariantCulture);
            List <Airport> airports      = GetAirports();

            airports = FilterVisibleAirports(airports, upperRightLon, upperRightLat, bottomLeftLon, bottomLeftLat);


            // Get Snow coeficients
            switch (interestType)
            {
            case "snow":
                GetSnowCoeficients(airports.Take(simulationAmount).ToList());
                break;

            case "air-quality":

                break;

            case "water-quality":
                GetWaterCoeficients(airports.Take(simulationAmount).ToList());
                break;

            default:
                break;
            }

            Siesta.Kiwi.Kiwi kiwi = new Siesta.Kiwi.Kiwi();

            SearchResult result = new SearchResult();

            foreach (var item in airports.Take(simulationAmount))
            {
                if (interestType == "snow")
                {
                    if (item.SnowCoeficient < 0.05m)
                    {
                        continue;
                    }
                }
                if (interestType == "water-quality")
                {
                    if (item.WaterCoeficient < 0.05m)
                    {
                        continue;
                    }
                }
                SearchResultResponse.Response kiwiResult = kiwi.Search(DateTime.Now, DateTime.Now.AddDays(3), fromLocation, item.code);
                if (kiwiResult != null)
                {
                    foreach (var flightData in kiwiResult.data.Take(1))
                    {
                        SearchResult.Flight flight = new SearchResult.Flight();
                        flight.cityFrom        = flightData.cityFrom;
                        flight.cityTo          = flightData.cityTo;
                        flight.deep_link       = flightData.deep_link;
                        flight.distance        = flightData.distance;
                        flight.flyFrom         = flightData.flyFrom;
                        flight.flyTo           = flightData.flyTo;
                        flight.local_arrival   = flightData.local_arrival;
                        flight.local_departure = flightData.local_departure;
                        flight.price           = flightData.price;
                        result.flights.Add(flight);
                    }
                }
            }

            return(result);
        }