public UpdateSecondaryTileTask() { userService = UserService.GetInstance(); weatherService = WeatherService.GetInstance(); userRespose = new GetUserRespose(); userCityRespose = new GetUserCityRespose(); weatherRespose = new GetWeatherRespose(); weatherTypeRespose = new GetWeatherTypeRespose(); }
public MyCityPage() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += this.NavigationHelper_LoadState; this.navigationHelper.SaveState += this.NavigationHelper_SaveState; userService = UserService.GetInstance(); weatherService = WeatherService.GetInstance(); userRespose = new GetUserRespose(); userCityRespose = new GetUserCityRespose(); weatherTypeRespose = new GetWeatherTypeRespose(); weatherRespose = new GetWeatherRespose(); myCityPage = new ViewModel.MyCityPage(); myCityPageModelList = new List<ViewModel.MyCityPageModel>(); }
public PivotPage() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += this.NavigationHelper_LoadState; this.navigationHelper.SaveState += this.NavigationHelper_SaveState; this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required; userService = UserService.GetInstance(); weatherService = WeatherService.GetInstance(); settingService = SettingService.GetInstance(); userRespose = new GetUserRespose(); userCityRespose = new GetUserCityRespose(); weatherRespose = new GetWeatherRespose(); weatherTypeRespose = new GetWeatherTypeRespose(); settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose(); }
public MainPage() { this.navigationHelper = new NavigationHelper(this); this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required; userService = UserService.GetInstance(); weatherService = WeatherService.GetInstance(); settingService = SettingService.GetInstance(); colorService = ColorService.GetInstance(); userRespose = new GetUserRespose(); userCityRespose = new GetUserCityRespose(); weatherRespose = new GetWeatherRespose(); weatherTypeRespose = new GetWeatherTypeRespose(); settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose(); colorResponse = new GetColorRespose(); homePageModel = new HomePageModel(); this.InitializeComponent(); Loaded += MainPage_Loaded; }
/// <summary> /// 更新磁贴 /// </summary> /// <param name="weatherRespose"></param> /// <param name="getWeatherTypeRespose"></param> /// <param name="getUserRespose"></param> private void UpdateTile(GetWeatherRespose weatherRespose) { string tileXmlString = @"<tile>" + "<visual version='2'>" + "<binding template='TileWide310x150PeekImage02' fallback='TileWidePeekImage02'>" + "<image id='1' src='ms-appx:///" + weatherTypeRespose.WeatherTypes.Find(x => x.Code == weatherRespose.result.FirstOrDefault().now.cond.code).TileWidePic + "'/>" + "<text id='1'>" + weatherRespose.result.FirstOrDefault().basic.city + "</text>" + "<text id='2'>" + weatherRespose.result.FirstOrDefault().daily_forecast.FirstOrDefault().tmp.min + "°~" + weatherRespose.result.FirstOrDefault().daily_forecast.FirstOrDefault().tmp.max + "° " + weatherRespose.result.FirstOrDefault().now.cond.txt + "</text>" + "<text id='3'>" + weatherRespose.result.FirstOrDefault().now.wind.dir + " " + weatherRespose.result.FirstOrDefault().now.wind.sc + " 级</text>" + "<text id='4'>湿度: " + weatherRespose.result.FirstOrDefault().now.hum + "%</text>" + "<text id='5'>能见度: " + weatherRespose.result.FirstOrDefault().now.vis + "km</text>" + "</binding>" + "<binding template='TileSquare150x150PeekImageAndText01' fallback='TileSquarePeekImageAndText01'>" + "<image id='1' src='ms-appx:///" + weatherTypeRespose.WeatherTypes.Find(x => x.Code == weatherRespose.result.FirstOrDefault().now.cond.code).TileSquarePic + "'/>" + "<text id='1'>" + weatherRespose.result.FirstOrDefault().basic.city + "</text>" + "<text id='2'>" + weatherRespose.result.FirstOrDefault().now.tmp + "°</text>" + "<text id='3'>" + weatherRespose.result.FirstOrDefault().now.cond.txt + "</text>" + "<text id='4'>" + weatherRespose.result.FirstOrDefault().now.wind.dir + " " + weatherRespose.result.FirstOrDefault().now.wind.sc + "级</text>" + "</binding>" + "</visual>" + "</tile>"; TileHelper.UpdateTileNotificationsByXml(tileXmlString); }
private void UpdateSecondaryTile(string tileId, GetWeatherRespose weatherRespose) { if (weatherRespose.result != null) { if (SecondaryTileHelper.IsExists(tileId)) { string tileXmlString = @"<tile>" + "<visual version='2'>" + "<binding template='TileWide310x150BlockAndText01' fallback='TileWideBlockAndText01'>" + "<text id='1'>" + weatherRespose.result.sk.temp + "°</text>" + "<text id='2'>" + weatherRespose.result.today.city + "</text>" + "<text id='3'>" + weatherRespose.result.today.temperature + "</text>" + "<text id='4'>" + weatherRespose.result.today.weather + "</text>" + "<text id='5'>" + weatherRespose.result.sk.wind_direction + " " + weatherRespose.result.sk.wind_strength + "</text>" + "<text id='6'>" + weatherRespose.result.today.week + "</text>" + "</binding>" + "<binding template='TileSquare150x150PeekImageAndText01' fallback='TileSquarePeekImageAndText01'>" + "<image id='1' src='ms-appx:///" + weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa).TileSquarePic + "'/>" + "<text id='1'>" + weatherRespose.result.sk.temp + "°</text>" + "<text id='2'>" + weatherRespose.result.today.temperature + "</text>" + "<text id='3'>" + weatherRespose.result.today.weather + "</text>" + "<text id='4'>" + weatherRespose.result.sk.wind_direction + " " + weatherRespose.result.sk.wind_strength + "</text>" + "</binding>" + "</visual>" + "</tile>"; SecondaryTileHelper.UpdateSecondaryTileNotificationsByXml(tileId, tileXmlString); } } }
/// <summary> /// 通过本地获取 /// </summary> /// <param name="item"></param> /// <returns></returns> public async Task<MyCityPageModel> GetWeatherByClient(Model.UserCity item) { weatherRespose = await weatherService.GetWeatherByClientAsync(item.CityId.ToString()).ConfigureAwait(false); MyCityPageModel model = new MyCityPageModel(); model.CityId = item.CityId; model.CityName = item.CityName; model.Temp = weatherRespose == null ? null : weatherRespose.result.today.temperature; model.TodayPic = weatherRespose == null ? null : weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa).TodayPic; return model; }
/// <summary> /// 通过网络获取 /// </summary> /// <param name="item"></param> /// <returns></returns> public async Task<MyCityPageModel> GetWeatherByNet(Model.UserCity item) { //不存在当天的天气数据,就从网络获取数据 IGetWeatherRequest request = GetWeatherRequestFactory.CreateGetWeatherRequest(GetWeatherMode.City, item.CityName); weatherRespose = await weatherService.GetWeatherAsync(request); await DeleteFile(item.CityId); await weatherService.SaveWeather<GetWeatherRespose>(weatherRespose, item.CityId.ToString()); MyCityPageModel model = new MyCityPageModel() { CityId = item.CityId, CityName = item.CityName, Temp = weatherRespose == null ? null : weatherRespose.result.today.temperature, TodayPic = weatherRespose == null ? null : weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa).TodayPic }; return model; }
private async Task<GetWeatherRespose> GetWeatherAsync(int isRefresh, Model.UserCity userCity, IGetWeatherRequest weatherRequest) { GetWeatherRespose weatherRespose = new GetWeatherRespose(); try { if (isRefresh == 1) { weatherRespose = await weatherService.GetWeatherAsync(weatherRequest); await weatherService.SaveWeather(weatherRespose, userCity.CityId.ToString()); } else { string filePath = StringHelper.GetTodayFilePath(userCity.CityId); if (!await FileHelper.IsExistFileAsync(filePath)) { //不存在当天的天气数据,就从网络获取数据 weatherRespose = await weatherService.GetWeatherAsync(weatherRequest); await DeleteFile(userCity.CityId); await weatherService.SaveWeather(weatherRespose, userCity.CityId.ToString()); } else { weatherRespose = await weatherService.GetWeatherByClientAsync(userCity.CityId.ToString()); } } return weatherRespose; } catch (Exception) { return weatherRespose; } }
/// <summary> /// 获取天气数据 /// </summary> /// <param name="cityId"></param> private async Task GetWeather(string cityId, int isRefresh) { Model.UserCity userCity = string.IsNullOrEmpty(cityId) ? userCityRespose.UserCities.FirstOrDefault(x => x.IsDefault == 1) : userCityRespose.UserCities.FirstOrDefault(x => x.CityId == cityId); IGetWeatherRequest weatherRequest = GetWeatherRequestFactory.CreateGetWeatherRequest(GetWeatherMode.CityId, userCity.CityId); //有网络 if (NetHelper.IsNetworkAvailable()) { if (userRespose.UserConfig.IsWifiUpdate == 0) { weatherRespose = await GetWeatherAsync(isRefresh, userCity, weatherRequest); } else { if (NetHelper.IsWifiConnection()) { weatherRespose = await GetWeatherAsync(isRefresh, userCity, weatherRequest); } else { weatherRespose.result = null; NotifyUser("Wifi未启动"); } } } else { weatherRespose = await weatherService.GetWeatherByClientAsync(userCity.CityId.ToString()); NotifyUser("请开启网络,以更新最新天气数据"); } if (weatherRespose != null) { var respose = weatherRespose.result.FirstOrDefault(); var aqi = respose.aqi; var now = respose.now; var basic = respose.basic; var daily_forecast = respose.daily_forecast; var hourly_forecast = respose.hourly_forecast; if (aqi != null) { homePageModel.Aqi = "空气质量: " + aqi.city.qlty; } homePageModel.City = basic.city; homePageModel.Daytmp = daily_forecast.FirstOrDefault().tmp.min + "° / " + daily_forecast.FirstOrDefault().tmp.max + "°"; homePageModel.Hum = "湿度: " + now.hum + " %"; homePageModel.Pres = now.pres + " hPa"; homePageModel.Tmp = now.tmp + "°"; homePageModel.Txt = now.cond.txt; homePageModel.Update = basic.update.loc + " 发布"; homePageModel.Vis = "能见度: " + now.vis + " km"; homePageModel.Wind = now.wind.dir + " " + now.wind.sc + " 级"; homePageModel.WeatherType = weatherTypeRespose.WeatherTypes.FirstOrDefault(x => x.Code == now.cond.code); List<ViewModel.DailyItem> dailyList = new List<ViewModel.DailyItem>(); foreach (var item in daily_forecast) { DailyItem daily = new DailyItem() { Date = GetDateStr(item.date), Image = weatherTypeRespose.WeatherTypes.FirstOrDefault(x => x.Code == item.cond.code_d).TileWidePic, Tmp = item.tmp.min + "° / " + item.tmp.max + "°", Txt = item.cond.txt_d }; dailyList.Add(daily); } homePageModel.DailyList = dailyList; List<ViewModel.HourlyItem> hourlyList = new List<ViewModel.HourlyItem>(); foreach (var item in hourly_forecast) { HourlyItem hourly = new HourlyItem() { Date = DateTime.Parse(item.date).ToString("HH:mm"), Hum = item.hum + " %", Tmp = item.tmp + "°", Wind = item.wind.dir + " " + item.wind.sc }; hourlyList.Add(hourly); } homePageModel.HourlyList = hourlyList; LayoutRoot.DataContext = null; LayoutRoot.DataContext = homePageModel; } else { NotifyUser("天气数据获取失败"); } }
/// <summary> /// 获取天气数据 /// </summary> /// <param name="cityId"></param> private async Task GetWeather(string cityId, int isRefresh) { popupProgressBar.IsOpen = true; //progressBar.Visibility = Visibility.Visible; Model.UserCity userCity = string.IsNullOrEmpty(cityId) ? userCityRespose.UserCities.FirstOrDefault(x => x.IsDefault == 1) : userCityRespose.UserCities.FirstOrDefault(x => x.CityId == int.Parse(cityId)); IGetWeatherRequest weatherRequest = GetWeatherRequestFactory.CreateGetWeatherRequest(GetWeatherMode.City, userCity.CityName); //有网络 if (NetHelper.IsNetworkAvailable()) { if (userRespose.UserConfig.IsWifiUpdate == 0) { weatherRespose = await GetWeatherAsync(isRefresh, userCity, weatherRequest); } else { if (NetHelper.IsWifiConnection()) { weatherRespose = await GetWeatherAsync(isRefresh, userCity, weatherRequest); } else { weatherRespose.result = null; NotifyUser("Wifi未启动"); } } } else { weatherRespose = await weatherService.GetWeatherByClientAsync(userCity.CityId.ToString()); NotifyUser("请开启网络,以更新最新天气数据"); } if (weatherRespose != null) { ViewModel.HomePageModel homePageModel = new ViewModel.HomePageModel(); homePageModel.WeatherType = weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa); weatherRespose.result.sk.temp = weatherRespose.result.sk.temp + "°"; weatherRespose.result.sk.time = weatherRespose.result.sk.time + "发布"; homePageModel.Sk = weatherRespose.result.sk; homePageModel.Today = weatherRespose.result.today; var fiture = weatherRespose.result.future.Find(x => x.date == DateTime.Now.ToString("yyyyMMdd")); if (fiture == null) { return; } int i; if (int.TryParse(fiture.weather_id.fa, out i)) { homePageModel.Futures = weatherRespose.result.future.ForEach(x => x.weather_id.fa = weatherTypeRespose.WeatherTypes.Find(w => w.Wid == x.weather_id.fa).TomorrowPic).ToList(); } else { homePageModel.Futures = weatherRespose.result.future; } LayoutRoot.DataContext = homePageModel; UpdateTileFacade(); UpdateSecondaryTileFacade(); } else { NotifyUser("请开启网络,以更新最新天气数据"); } popupProgressBar.IsOpen = false; //progressBar.Visibility = Visibility.Collapsed; }