Beispiel #1
0
        public async Task <IActionResult> GetWaitTime(AirportCode model)

        {
            var clientResult = await _airportClient.GetAirport(model.Code);

            return(View(clientResult));
        }
        public async Task <IActionResult> TSASpecs(Departure model)
        {
            AirportCode newModel = new AirportCode();

            newModel.Code = model.iata;
            return(View(newModel));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the airport specified by the given airport code.
        /// </summary>
        /// <returns>
        /// The airport specified by the given airport code.
        /// </returns>
        /// <param name="code">
        /// The airport code of the desired airport.
        /// </param>
        /// <param name="type">
        /// The type of airport code given.
        /// </param>
        public static Airport GetAirport(string code, AirportCode type)
        {
            List <Airport> results;

            switch (type)
            {
            case AirportCode.FAA:
                results = sqlitedb.Query <Airport> ("select * from Airport where FAA = ?", code);
                break;

            case AirportCode.IATA:
                results = sqlitedb.Query <Airport> ("select * from Airport where IATA = ?", code);
                break;

            case AirportCode.ICAO:
                results = sqlitedb.Query <Airport> ("select * from Airport where ICAO = ?", code);
                break;

            case AirportCode.Any:
                results = sqlitedb.Query <Airport> ("select * from Airport where FAA = ? or IATA = ? or ICAO = ?", code, code, code);
                break;

            default:
                return(null);
            }

            return(results.Count > 0 ? results[0] : null);
        }
Beispiel #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            AirportCode airportCode = db.AirportCodes.Find(id);

            db.AirportCodes.Remove(airportCode);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "Id,Name,Country,Code")] AirportCode airportCode)
 {
     if (ModelState.IsValid)
     {
         db.Entry(airportCode).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(airportCode));
 }
Beispiel #6
0
        private async Task <Location> GetLocationCachedAsync(AirportCode airportCode)
        {
            var ctx = new Context($"{nameof(GetLocationCachedAsync)}:{airportCode.Code}");

            var getAirportTask = CachePolicy is null
                ? GetAirportAsync(airportCode)
                : CachePolicy.ExecuteAsync(ctx => GetAirportAsync(airportCode), ctx);

            return(ParseLocation(await getAirportTask));
        }
Beispiel #7
0
        public ActionResult Create([Bind(Include = "AirportCodeID,IATACode,AirportName,City,Country")] AirportCode airportCode)
        {
            if (ModelState.IsValid)
            {
                db.AirportCodes.Add(airportCode);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(airportCode));
        }
Beispiel #8
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = AirportCode.GetHashCode();
         result = (result * 397) ^ City.GetHashCode();
         result = (result * 397) ^ State.GetHashCode();
         result = (result * 397) ^ Geocode.GetHashCode();
         return(result);
     }
 }
Beispiel #9
0
        public ActionResult Create(AirportCode airportCode)
        {
            if (ModelState.IsValid)
            {
                db.AirportCodes.Add(airportCode);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(airportCode));
        }
Beispiel #10
0
        // GET: AirportCodes/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AirportCode airportCode = db.AirportCodes.Find(id);

            db.AirportCodes.Remove(airportCode);
            db.SaveChanges();
            return(RedirectToAction("Index", "AirportCodes"));
        }
Beispiel #11
0
        // GET: AirportCodes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AirportCode airportCode = db.AirportCodes.Find(id);

            if (airportCode == null)
            {
                return(HttpNotFound());
            }
            return(View(airportCode));
        }
Beispiel #12
0
        public async Task <IActionResult> TravelTime(AirportCode model)
        {
            TravelTimeViewModel travel = new TravelTimeViewModel();

            travel.Location = model.Location;
            travel.ArriveBy = model.ArriveBy;
            string time = Request.Form["time"];

            model.Code = Request.Form["airport"];
            var tsaWaitTime = await _airportClient.GetAirport(model.Code);

            travel.Code        = model.Code;
            travel.TSAWaitTime = tsaWaitTime.rightnow / 60;
            string hourMin = time.Substring(0, 5);

            time        = DateTime.Parse(hourMin).ToString("h:mm tt");
            model.Time  = Convert.ToDateTime(time);
            travel.Time = model.Time.ToString("h:mm tt");
            DirectionsRequest request = new DirectionsRequest();

            request.Key         = "AIzaSyAD_-v70Gc1IQ2mfHkKTjCYBINKMlQ4I8I";
            request.Origin      = new Location(model.Location);
            request.Destination = new Location(model.Code);
            var response = GoogleApi.GoogleMaps.Directions.Query(request);

            double duration = response.Routes.First().Legs.First().Duration.Value / 3600D;

            travel.TotalTravelTime = duration + travel.TSAWaitTime;

            TimeSpan tt = TimeSpan.FromHours((duration));

            travel.DriveTime = tt.Hours.ToString("00") + " hours" + " and" + tt.Minutes.ToString(" 00") + " minutes";

            if (model.ArriveBy)
            {
                DateTime arriveByTime = model.Time;
                DateTime updatedTime  = arriveByTime.AddHours(-(travel.TotalTravelTime));
                travel.LeaveTime = updatedTime.ToString("h:mm tt");
            }
            else
            {
                DateTime arriveByTime = model.Time;
                DateTime updatedTime  = arriveByTime.AddHours((travel.TotalTravelTime));
                travel.LeaveTime = updatedTime.ToString("h:mm tt");
            }

            ;
            return(View(travel));
        }
Beispiel #13
0
        public Guid Reserve(string airportCode, string vendor, DateTime from, DateTime until)
        {
            Vendor        = vendor;
            Airport       = new AirportCode(airportCode).Code;
            From          = from;
            From          = until;
            ReservationId = Guid.NewGuid();

            AddDomainEvent(new CarRentalBooked()
            {
                Id = Id, ReservationId = ReservationId
            });

            return(ReservationId);
        }
Beispiel #14
0
        /// <summary>Returns the distance (in meters) between airports</summary>
        /// <exception cref="AirportCodeException">If the airport code is unknown or unsupported</exception>
        public async Task <Distance> GetDistanceAsync(AirportCode from, AirportCode to)
        {
            if (from == to)
            {
                return(Distance.Zero);
            }

            var(fromLoc, toLoc) = await
                                  (
                AirportLocator.GetLocationAsync(from),
                AirportLocator.GetLocationAsync(to)
                                  )
                                  .WhenAll();

            return(fromLoc - toLoc);
        }
        private async Task <ActionResult <AirportDistance> > GetDistanceAsync(string from, string to, DistanceUnit unit)
        {
            try
            {
                var fromAirportCode = new AirportCode(from);
                var toAirportCode   = new AirportCode(to);
                var distance        = await DistanceCalculator.GetDistanceAsync(fromAirportCode, toAirportCode);

                return(new AirportDistance(fromAirportCode, toAirportCode, distance.Convert(unit)));
            }
            catch (AirportCodeException e)
            {
                Logger.Error(e, "Error while calculating airport distance {From} - {To}", from, to);
                return(BadRequest(new { message = e.Message }));
            }
        }
Beispiel #16
0
 /// <summary>
 /// Converts the value of the current WeatherEvent instance
 /// to its equivalent string representation.
 /// </summary>
 /// <returns>A string representation of a WeatherEvent.</returns>
 public override string ToString()
 {
     return(EventID.ToString() + ToStringSeparator +
            Type.ToString() + ToStringSeparator +
            Severity.ToString() + ToStringSeparator +
            StartTime.ToString() + ToStringSeparator +
            EndTime.ToString() + ToStringSeparator +
            TimeZone.ToString() + ToStringSeparator +
            AirportCode.ToString() + ToStringSeparator +
            LocationLatitude.ToString() + ToStringSeparator +
            LocationLongitude.ToString() + ToStringSeparator +
            City.ToString() + ToStringSeparator +
            County.ToString() + ToStringSeparator +
            State.ToString() + ToStringSeparator +
            ZipCode.ToString());
 }
Beispiel #17
0
        public async Task Location_of_some_airports_can_be_determined(string code, Location expectedLocation)
        {
            // Arrange

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri("https://places-dev.cteleport.com")
            };

            IAirportLocator locator     = new PlacesService(httpClient, new PolicyRegistry());
            var             airportCode = new AirportCode(code);

            // Act

            var location = await locator.GetLocationAsync(airportCode);

            // Assert
            Assert.Equal(expectedLocation, location);
        }
        private async Task GetMetar()
        {
            if (!HasNetworkAccess())
            {
                DisplayError(Localization.Error_Occured, Localization.Check_Connection);
                return;
            }

            if (string.IsNullOrEmpty(AirportCode) || IsBusy)
            {
                return;
            }
            if (!AirportCode.ToUpper().StartsWith(Constants.IdentifierChar))
            {
                AirportCode = AirportCode.Insert(0, Constants.IdentifierChar);
            }

            IsBusy = true;
            await AirportService.GetAirportMetar(AirportCode.ToUpper(), new System.Threading.CancellationToken()).ConfigureAwait(false);
        }
Beispiel #19
0
        private async Task <JsonDocument> GetAirportAsync(AirportCode airportCode)
        {
            using var response = await HttpClient.GetAsync($"/airports/{airportCode.Code}");

            if (response.IsSuccessStatusCode)
            {
                return(await response.GetJson());
            }
            else
            {
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new AirportCodeException(airportCode.Code);
                }
                else
                {
                    throw new ApplicationException(
                              $"Error response from \"places\" service: {response.StatusCode}");
                }
            }
        }
Beispiel #20
0
        public async Task <IActionResult> Index(AirportCode model)
        {
            var airportCode = model.code;

            var message  = new HttpRequestMessage();            // instantiate HttpRequestMessage object. Will eventually hold all parts of our GET request
            var message2 = new HttpRequestMessage();
            var message3 = new HttpRequestMessage();


            message.Method  = HttpMethod.Get;
            message2.Method = HttpMethod.Get;
            message3.Method = HttpMethod.Get;


            message.RequestUri  = new Uri($"{BASE_URL}metar/{airportCode}?token=Ee2dwfrB1XRnuxsGjByGWD9C3YIuZajZMRgfhluZzL0");
            message2.RequestUri = new Uri($"{BASE_URL}station/{airportCode}?token=Ee2dwfrB1XRnuxsGjByGWD9C3YIuZajZMRgfhluZzL0");
            message3.RequestUri = new Uri($"{BASE_URL}metar/{airportCode}?token=Ee2dwfrB1XRnuxsGjByGWD9C3YIuZajZMRgfhluZzL0");


            var client  = _clientFactory.CreateClient();        // Using injected clientFactory, create new local object
            var client2 = _clientFactory.CreateClient();
            var client3 = _clientFactory.CreateClient();


            var response = await client.SendAsync(message);     // Async sending of GET request with response stored in local object

            var response2 = await client2.SendAsync(message2);

            var response3 = await client3.SendAsync(message3);


            if (response.IsSuccessStatusCode)                                           // If 200-Range Response
            {
                using var responseStream = await response.Content.ReadAsStreamAsync();  // 'using' statement to preserve/garbage-collect resources. Read stream of JSON response into local object

                METARs = await JsonSerializer.DeserializeAsync <METAR>(responseStream); // Deserialize response stream into our METARs property of type METAR.
            }                                                                           // ..If this were more than 1 property on the response, use IEnumerable & for-loop through on the View
            else
            {
                METARs = null;                                                                  // Set Property to null if failed call
            }

            if (response2.IsSuccessStatusCode)
            {
                using var responseStream2 = await response2.Content.ReadAsStreamAsync();

                Name = await JsonSerializer.DeserializeAsync <AirportName>(responseStream2);
            }
            else
            {
                Name = null;
            }
            if (response3.IsSuccessStatusCode)
            {
                using var responseStream3 = await response3.Content.ReadAsStreamAsync();

                Sanitized = await JsonSerializer.DeserializeAsync <FullReport>(responseStream3);
            }

            ViewBag.metarRes    = METARs.flight_rules;
            ViewBag.airportName = Name.name;
            ViewBag.sanitized   = $"METAR: {Sanitized.sanitized}";



            return(View());
            // Return the view passing in the field parsed from response
        }
Beispiel #21
0
 /// <inheritdoc/>
 Task <Location> IAirportLocator.GetLocationAsync(AirportCode airportCode)
 => GetLocationCachedAsync(airportCode);
Beispiel #22
0
        /// <summary>
        /// Gets the airport specified by the given airport code.
        /// </summary>
        /// <returns>
        /// The airport specified by the given airport code.
        /// </returns>
        /// <param name="code">
        /// The airport code of the desired airport.
        /// </param>
        /// <param name="type">
        /// The type of airport code given.
        /// </param>
        public static Airport GetAirport(string code, AirportCode type)
        {
            List<Airport> results;

            switch (type) {
            case AirportCode.FAA:
                results = sqlitedb.Query<Airport> ("select * from Airport where FAA = ?", code);
                break;
            case AirportCode.IATA:
                results = sqlitedb.Query<Airport> ("select * from Airport where IATA = ?", code);
                break;
            case AirportCode.ICAO:
                results = sqlitedb.Query<Airport> ("select * from Airport where ICAO = ?", code);
                break;
            case AirportCode.Any:
                results = sqlitedb.Query<Airport> ("select * from Airport where FAA = ? or IATA = ? or ICAO = ?", code, code, code);
                break;
            default:
                return null;
            }

            return results.Count > 0 ? results[0] : null;
        }
Beispiel #23
0
 /// <summary>Constructor</summary>
 public AirportDistance(AirportCode from, AirportCode to, Distance distance)
 {
     From     = from;
     To       = to;
     Distance = distance;
 }
Beispiel #24
0
 public Airport(string airportCode)
 {
     AirportCode = new AirportCode(airportCode);
 }