private async void OnActiveTabChangedAsync() { if (IsActive) { try { var statistics = await _cnsusService.GetStatistics(); TraditionSum = statistics.Where(s => s.Type == "Tradition").FirstOrDefault().EndPointSum; RestaurantSum = statistics.Where(s => s.Type == "Restaurant").FirstOrDefault().EndPointSum; var cacheTraditionSetting = await _cacheManager.Get <TraditionSetting>(GlobalSettings.traditionSetting_key); var cacheRestaurantSetting = await _cacheManager.Get <RestaurantSetting>(GlobalSettings.restaurantSetting_key); var cacheSalesProductSetting = await _cacheManager.Get <SalesProductSetting>(GlobalSettings.salesProductSetting_key); if (cacheTraditionSetting == null) { cacheTraditionSetting = await _settingService.GetTraditionSetting(); await _cacheManager.Set <TraditionSetting>(GlobalSettings.traditionSetting_key, cacheTraditionSetting); } if (cacheRestaurantSetting == null) { cacheRestaurantSetting = await _settingService.GetRestaurantSetting(); await _cacheManager.Set <RestaurantSetting>(GlobalSettings.restaurantSetting_key, cacheRestaurantSetting); } if (cacheTraditionSetting == null) { cacheSalesProductSetting = await _settingService.GetSalesProductSetting(); await _cacheManager.Set <SalesProductSetting>(GlobalSettings.salesProductSetting_key, cacheSalesProductSetting); } GlobalSettings.TraditionSetting = cacheTraditionSetting; GlobalSettings.RestaurantSetting = cacheRestaurantSetting; GlobalSettings.SalesProductSetting = cacheSalesProductSetting; } catch (Exception) { _dialogService.LongAlert("系统初始错误!"); } } }
public async Task Initialize(object navigationData) { CurrentDate = GlobalSettings.EventDate; IsBusy = true; try { var weather = _weatherService.GetDemoWeatherInfoAsync(); var events = _eventsService.GetEvents(); var suggestions = _ridesService.GetSuggestions(); var tasks = new List <Task> { weather, events, suggestions }; while (tasks.Count > 0) { var finishedTask = await Task.WhenAny(tasks); tasks.Remove(finishedTask); if (finishedTask.Status == TaskStatus.RanToCompletion) { if (finishedTask == weather) { var weatherResults = await weather; if (weatherResults is WeatherInfo) { var weatherInfo = weatherResults as WeatherInfo; Location = weatherInfo.LocationName; Temp = Math.Round(weatherInfo.Temp).ToString(); } } else if (finishedTask == events) { var eventsResults = await events; Events = new ObservableCollection <Event>(eventsResults); } else if (finishedTask == suggestions) { var suggestionsResults = await suggestions; Suggestions = new ObservableCollection <Suggestion>(suggestionsResults); } } } var traditions = new List <Tradition>(); var restaurants = new List <Restaurant>(); //销量 //traditions = await _censusService.GetTraditions(10, 0); //restaurants = await _censusService.GetRestaurants(10, 0); try { var traditionsModel = await _cacheManager.Get <List <Tradition> >(GlobalSettings.traditions_key); if (traditionsModel != null) { traditions = traditionsModel; } else { traditions = await _censusService.GetTraditions(10, 0); await _cacheManager.Set <List <Tradition> >(GlobalSettings.traditions_key, traditions); } // var restaurantsModel = await _cacheManager.Get <List <Restaurant> >(GlobalSettings.restaurants_key); if (restaurantsModel != null) { restaurants = restaurantsModel; } else { restaurants = await _censusService.GetRestaurants(10, 0); await _cacheManager.Set <List <Restaurant> >(GlobalSettings.restaurants_key, restaurants); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } var ridesResult = new List <Stats>(); foreach (var t in traditions) { if (t != null) { ridesResult.Add(new Stats { Title = t.BaseInfo.EndPointStorsName, Label1 = string.Format("{0}月销量", DateTime.Now.AddMonths(-1).Month), Label2 = string.Format("{0}月销量", DateTime.Now.Month), Value1 = "0", Value2 = "0" }); } } foreach (var t in restaurants) { if (t != null) { ridesResult.Add(new Stats { Title = t.BaseInfo.EndPointStorsName, Label1 = string.Format("{0}月", DateTime.Now.AddMonths(-1).Month), Label2 = string.Format("{0}月", DateTime.Now.Month), Value1 = "0", Value2 = "0" }); } } Statistics = new ObservableCollection <Stats>(ridesResult); //合计 TotalSum = 0; var statistics = await _censusService.GetStatistics(); statistics.ForEach(s => { TotalSum += s.EndPointSum; }); } catch (Exception ex) when(ex is WebException || ex is HttpRequestException) { //await _dialogService.ShowAlertAsync("Communication error", "Error", "Ok"); } catch (Exception ex) { Debug.WriteLine($"Error loading data in: {ex}"); } IsBusy = false; }