Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (LatestUpdate != 0UL)
            {
                hash ^= LatestUpdate.GetHashCode();
            }
            if (User1 != 0UL)
            {
                hash ^= User1.GetHashCode();
            }
            if (User2 != 0UL)
            {
                hash ^= User2.GetHashCode();
            }
            hash ^= messages_.GetHashCode();
            return(hash);
        }
Exemplo n.º 2
0
        /// <summary>
        /// After the background worker is done, prompt to update if there is one
        /// </summary>
        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }

            this.update = (LatestUpdate)e.Result;

            if (this.update == null)
            {
                return;
            }

            if (this.update.IsNewerThan(this.programInfo.ApplicationAssembly.GetName().Version))
            {
                // Add dialog here to check if you want to download
                this.acceptUpdateForm = new AcceptUpdateForm(this.programInfo, this.update);
            }
        }
Exemplo n.º 3
0
        public async Task UpdateWeatherAsync()
        {
            var woEidList = await _dbContext.Locations.Select(l => Tuple.Create(l.LocationId, l.WoeId)).ToListAsync();

            var client = _httpClientFactory.CreateClient();

            foreach (Tuple <long, long> tuple in woEidList)
            {
                var result = await client.GetStringAsync("https://www.metaweather.com/api/location/" + tuple.Item2);

                var weatherUpdateDto = JsonConvert.DeserializeObject <WeatherUpdateResultDto>(result);

                foreach (var consolidatedWeather in weatherUpdateDto.consolidated_weather)
                {
                    WeatherUpdate weatherUpdate = new WeatherUpdate()
                    {
                        LocationId           = tuple.Item1,
                        ApplicableDate       = consolidatedWeather.applicable_date,
                        WeatherStateName     = consolidatedWeather.weather_state_name,
                        WeatherStateAbbr     = consolidatedWeather.weather_state_abbr,
                        WindSpeed            = consolidatedWeather.wind_speed,
                        WindDirection        = consolidatedWeather.wind_direction,
                        WindDirectionCompass = consolidatedWeather.wind_direction_compass,
                        MinTemp        = consolidatedWeather.min_temp,
                        MaxTemp        = consolidatedWeather.max_temp,
                        CurrentTemp    = consolidatedWeather.the_temp,
                        AirPressure    = consolidatedWeather.air_pressure,
                        Humidity       = consolidatedWeather.humidity,
                        Visibility     = consolidatedWeather.visibility,
                        Predictability = consolidatedWeather.predictability
                    };

                    _dbContext.WeatherUpdates.Add(weatherUpdate);
                }

                LatestUpdate latestWeatherToBeUpdated = await _dbContext.LatestUpdates.FirstOrDefaultAsync(lu => lu.LocationId == tuple.Item1);

                consolidated_weather latestUpdate = weatherUpdateDto.consolidated_weather.OrderBy(cw => cw.applicable_date).FirstOrDefault();
                if (latestUpdate != null)
                {
                    if (latestWeatherToBeUpdated != null)
                    {
                        _dbContext.Entry(latestWeatherToBeUpdated).State = EntityState.Modified;
                    }
                    else
                    {
                        latestWeatherToBeUpdated            = new LatestUpdate();
                        latestWeatherToBeUpdated.LocationId = tuple.Item1;
                        _dbContext.LatestUpdates.Add(latestWeatherToBeUpdated);
                    }

                    latestWeatherToBeUpdated.ApplicableDate       = latestUpdate.applicable_date;
                    latestWeatherToBeUpdated.WeatherStateName     = latestUpdate.weather_state_name;
                    latestWeatherToBeUpdated.WeatherStateAbbr     = latestUpdate.weather_state_abbr;
                    latestWeatherToBeUpdated.WindSpeed            = latestUpdate.wind_speed;
                    latestWeatherToBeUpdated.WindDirection        = latestUpdate.wind_direction;
                    latestWeatherToBeUpdated.WindDirectionCompass = latestUpdate.wind_direction_compass;
                    latestWeatherToBeUpdated.MinTemp        = latestUpdate.min_temp;
                    latestWeatherToBeUpdated.MaxTemp        = latestUpdate.max_temp;
                    latestWeatherToBeUpdated.CurrentTemp    = latestUpdate.the_temp;
                    latestWeatherToBeUpdated.AirPressure    = latestUpdate.air_pressure;
                    latestWeatherToBeUpdated.Humidity       = latestUpdate.humidity;
                    latestWeatherToBeUpdated.Visibility     = latestUpdate.visibility;
                    latestWeatherToBeUpdated.Predictability = latestUpdate.predictability;
                }
            }

            await _dbContext.SaveChangesAsync();
        }