Exemplo n.º 1
0
        public ActionResult Index()
        {
            string              airportCode = Request.QueryString["airportCode"];
            DateTime            date        = DateTime.Parse(Request.QueryString["date"]);
            WeatherIncidentType?filterType  = GetWeatherIncidentTypeFromRequest(Request);

            double radius;

            if (!double.TryParse(Request.QueryString["radius"], out radius))
            {
                radius = 15;
            }

            var mainAirport = AirportList.GetAirport(airportCode);
            var airports    = new List <Airport> {
                mainAirport
            };

            airports.AddRange(AirportList.FindNearbyAirports(mainAirport.Geocode, radius));
            airports = airports.Distinct().ToList();

            var weatherUnderground = new WeatherUnderground();
            List <WeatherIncident> weatherUndergroundIncidents = new List <WeatherIncident>();

            foreach (var airport in airports)
            {
                weatherUndergroundIncidents.AddRange(weatherUnderground.GetEvents(airport.AirportCode, date, filterType));
            }
            return(Json(weatherUndergroundIncidents.Distinct(), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
 public WeatherVM()
 {
     Weather        = new WeatherUnderground();
     Cities         = new ObservableCollection <RESULT>();
     selectedResult = new RESULT();
     RefreshCommand = new RefreshCommand(this);
 }
        public static async Task <WeatherUnderground> GetWeatherInformationAsync(string link)
        {
            WeatherUnderground result = new WeatherUnderground();

            string url = string.Format(BASE_URL, API_KEY, link);

            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetAsync(url);

                string json = await response.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <WeatherUnderground>(json);
            }

            return(result);
        }
Exemplo n.º 4
0
        private async void buttonGo_Click(object sender, EventArgs e)
        {
            buttonGo.Enabled = false;
            try
            {
                ITimeRangeProvider timeRangeProvider = TimeRangeProviderFactory.GetProvider(
                    Properties.Settings.Default.StartTime,
                    Properties.Settings.Default.EndTime);

                var wu = new WeatherUnderground(textBoxLocation.Text, new UserInteraction(this.textBoxLog), this.browser, timeRangeProvider);
                List <WeatherInformation> weatherInformation = new List <WeatherInformation>();
                DateTime workingDate = dateTimePickerFrom.Value;
                DateTime endDate     = dateTimePickerTo.Value;

                int requestCount = (endDate - workingDate).Days + 1;

                this.progressBar1.Maximum = requestCount;

                while (workingDate <= endDate)
                {
                    var info = await wu.ReadWeatherInformation(workingDate);

                    if (info == null)
                    {
                        ProcessResult(weatherInformation);
                        return;
                    }
                    else
                    {
                        weatherInformation.Add(info);
                        workingDate = workingDate.AddDays(1);
                        this.progressBar1.Value++;
                    }
                }

                ProcessResult(weatherInformation);
            }
            finally
            {
                buttonGo.Enabled        = true;
                this.progressBar1.Value = 0;
            }
        }
Exemplo n.º 5
0
        //Todos los métodos async (asincronos) devuelven una tarea
        //Se marca async porque dentro está esperando (await) a otros métodos async ....
        //El mismo, al tener el modificador async, ya puede ser awaited también...


        // ## Ver --> https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ ## <--
        public static async Task <WeatherUnderground> GetWeatherInformationAsync(string link)
        {
            WeatherUnderground result = new WeatherUnderground();

            string url = string.Format(BASE_URL, API_KEY, link);

            using (HttpClient client = new HttpClient())
            {
                //Si no tuviese el await, devolvería un Task<TipoQuesea>...
                //Al ser await, ya devuelve el <TipoQueSea>
                var response = await client.GetAsync(url);

                string json = await response.Content.ReadAsStringAsync();

                result = JsonConvert.DeserializeObject <WeatherUnderground>(json);
            }

            return(result);
        }
Exemplo n.º 6
0
        public async Task <IServiceProvider> ConfigureServices()
        {
            Imgur ImgurConnect = new Imgur(WebConnect);
            await ImgurConnect.LoadConfig(new FileData("Config/ImgurConfig.json"));

            await ImgurConnect.SetupConnection();

            WeatherUnderground WeatherUndergroundConnect = new WeatherUnderground(WebConnect);
            await WeatherUndergroundConnect.LoadConfig(new FileData("Config/WeatherUndergroundConfig.json"));

            Cleverbot CleverbotConnect = new Cleverbot(WebConnect);
            await CleverbotConnect.LoadConfig(new FileData("Config/CleverbotConfig.json"));


            var sc = new ServiceCollection();

            sc.AddSingleton(Client);
            sc.AddSingleton(Console);
            sc.AddSingleton(ImgurConnect);
            sc.AddSingleton(WeatherUndergroundConnect);
            sc.AddSingleton(CleverbotConnect);
            sc.AddSingleton <CommandHandler>();
            sc.AddSingleton(new CommandService(new CommandServiceConfig {
                CaseSensitiveCommands = false, ThrowOnError = true
            }));
            sc.AddSingleton(new TestService("testing: ", Console));
            sc.AddSingleton <WeatherUndergroundService>();
            sc.AddSingleton <ImgurService>();
            sc.AddSingleton <CleverbotService>();
            sc.AddSingleton <ScheduleMaker>();
            sc.AddSingleton <TvModeService>();

            var sp = sc.BuildServiceProvider();

            sp.GetService <TestService>();
            sp.GetService <ImgurService>();
            sp.GetService <CleverbotService>();
            sp.GetService <TvModeService>();
            sp.GetService <WeatherUndergroundService>();
            return(sp);
        }
Exemplo n.º 7
0
 public WeatherUndergroundService(WeatherUnderground weatherUndergroundConnection, ServerUpdater <string> console, DiscordSocketClient client, ScheduleMaker scheduleMaker) : base(console, client, scheduleMaker)
 {
     WeatherUndergroundConnection = weatherUndergroundConnection;
     CommandName = "weather";
 }