public static async Task <IActionResult> GetAllStationsForecast(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stations/all/forecast")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"Get station forecast for all stations");

            LuasApi api = new LuasApi();

            var stations             = api.GetAllStations();
            var stationAbbreviations = stations.Select(s => s.Abbreviation);

            try
            {
                var allForecasts =
                    await Task.WhenAll(
                        stationAbbreviations.Select(
                            abbreviation => api.GetForecastAsync(abbreviation)))
                    .ConfigureAwait(false);

                var allForecastsDictionary = allForecasts.Select(forecast => new { forecast.Station.Abbreviation, forecast });

                return(new OkObjectResult(allForecastsDictionary));
            }
            catch (StationNotFoundException ex)
            {
                log.LogWarning($"StationNotFoundException for '{ex.StationThatWasNotFound}'. Exception: {ex}");
                return(new NotFoundObjectResult($"Unable to find forecast for: '{ex.StationThatWasNotFound}'"));
            }
            catch (Exception ex)
            {
                log.LogError($"Exception thrown in GetStationForecast. Exception: {ex}");
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public static async Task <IActionResult> GetStationForecast(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stations/{stationAbbreviation}/forecast")] HttpRequest req,
            string stationAbbreviation,
            ILogger log)
        {
            log.LogInformation($"Get station forecast for {stationAbbreviation}");

            LuasApi api = new LuasApi();

            try
            {
                var forecast = await api.GetForecastAsync(stationAbbreviation).ConfigureAwait(false);

                return(new OkObjectResult(forecast));
            }
            catch (StationNotFoundException ex)
            {
                log.LogWarning($"StationNotFoundException for '{stationAbbreviation}'. Exception: {ex}");
                return(new NotFoundObjectResult($"Unable to find forecast for: '{stationAbbreviation}'"));
            }
            catch (Exception ex)
            {
                log.LogError($"Exception thrown in GetStationForecast. Exception: {ex}");
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
        public static async Task <IActionResult> GetStation(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stations/{stationAbbreviation}")] HttpRequest req,
            string stationAbbreviation,
            ILogger log)
        {
            log.LogInformation($"Get station for '{stationAbbreviation}'");

            LuasApi api = new LuasApi();

            try
            {
                Station station = api.GetStation(stationAbbreviation);
                return(new OkObjectResult(station));
            }
            catch (StationNotFoundException ex)
            {
                log.LogWarning($"StationNotFoundException for '{stationAbbreviation}'. Exception: {ex}");
                return(new NotFoundObjectResult($"Unable to find station for: '{stationAbbreviation}'"));
            }
            catch (Exception ex)
            {
                log.LogError($"Unexpected code path '{stationAbbreviation}'. Exception: {ex}");
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 4
0
        static void Main()
        {
            LuasApi api = new LuasApi();
            var     s   = api.GetStation("ABB");

            //Console.WriteLine(JsonConvert.SerializeObject(api.GetAllStations()));
            //Console.WriteLine();

            Console.WriteLine(JsonConvert.SerializeObject(api.GetForecast(s)));
        }
Esempio n. 5
0
        public void Start()
        {
            Api = new LuasApi();

            string[] stations = { "DEP", "TPT", "SDK", "MYS", "GDK", "CON", "BUS", "ABB", "JER", "FOU", "SMI", "MUS", "HEU", "JAM", "FAT", "RIA", "SUI", "GOL", "DRI", "BLA", "BLU", "KYL", "RED", "KIN", "BEL", "COO", "HOS", "TAL", "FET", "CVN", "CIT", "FOR", "SAG", "BRO", "CAB", "PHI", "GRA", "BRD", "DOM", "PAR", "MAR", "TRY", "OUP", "OGP", "WES", "DAW", "STS", "HAR", "CHA", "RAN", "BEE", "COW", "MIL", "WIN", "DUN", "BAL", "KIL", "STI", "SAN", "CPK", "GLE", "GAL", "LEO", "BAW", "RCC", "CCK", "BRE", "LAU", "CHE", "BRI" };

            Test(Forecast, "Sync", stations);
            Thread.Sleep(15000);
            Test(ForecastAsync, "Async", stations);
        }
        public static async Task <IActionResult> GetAllStations(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "stations")] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Get all stations");

            LuasApi api = new LuasApi();

            return(new OkObjectResult(api.GetAllStations()));
        }