コード例 #1
0
        public async Task UpdateTrends(bool forceUpdate = false)
        {
            if (UpdatingTrends)
            {
                return;
            }

            if (!forceUpdate && _trendsLastUpdate + TimeSpan.FromMinutes(15) > DateTime.Now && _trendsLastWoeId ==
                SettingSupport.GetTrendsWoeId(SettingService.Setting.TrendsRegion))
            {
                return;
            }

            UpdatingTrends = true;

            TrendsPlace = SettingSupport.GetTrendsPlaceString(SettingService.Setting.TrendsRegion);

            Trends.Clear();
            try
            {
                var trends = await Tokens.Trends.PlaceAsync(
                    id => SettingSupport.GetTrendsWoeId(SettingService.Setting.TrendsRegion));

                if (trends.Count == 0)
                {
                    UpdatingTrends = false;
                    return;
                }

                Trends.Clear();
                foreach (var trend in trends)
                {
                    Trends.Add(trend);
                }

                _trendsLastUpdate = DateTime.Now.ToLocalTime();
                _trendsLastWoeId  = SettingSupport.GetTrendsWoeId(SettingService.Setting.TrendsRegion);
            }
            catch
            {
                UpdatingTrends = false;
                return;
            }

            UpdatingTrends = false;
        }