/// <summary> /// 获取Splash图片 /// </summary> /// <returns></returns> private async Task <IRandomAccessStream> GetSplashImageAsync() { try { var lastCacheSplashFileName = Global.AppConfig.LastCacheSplashFileName; //缓存的Splash文件名称 bool isSplashExpired = false; //Splash是否已过期 if (Global.AppConfig.CacheSplashExpire.HasValue) { if (Global.AppConfig.CacheSplashExpire < DateTime.Now) { isSplashExpired = true; Global.AppConfig.CacheSplashExpire = null; //清空过期时间 Global.SaveAppConfig(); } } IRandomAccessStream splashStream = null; if (isSplashExpired || string.IsNullOrWhiteSpace(lastCacheSplashFileName) || !(await LocalCacheUtility.ExistsCacheFile(lastCacheSplashFileName))) //没有缓存Splash,或者缓存已过期,或者缓存图片获取失败 { LocalCacheUtility.DeleteCacheFile(lastCacheSplashFileName).NoWarning(); } else { splashStream = await LocalCacheUtility.GetCacheAsync(lastCacheSplashFileName); } return(splashStream); } catch (Exception ex) { Debug.WriteLine(ex); return(null); } }
/// <summary> /// 获取当前活动 /// </summary> /// <param name="tryTimes"></param> /// <returns></returns> private async Task GetCurrentActivities(int tryTimes = 2) { if (LastGetActivityTime > DateTime.Now.AddMinutes(-5)) //三分钟以内不重复获取 { return; } var advertisementResult = await OfoApi.GetAdvertisementsAsync(await PositionUtility.GetUnFixBasicPositionAsync()); if (await CheckOfoApiResult(advertisementResult)) { LastGetActivityTime = DateTime.Now; //缓存起始屏幕splash var cacheSplashTask = Task.Run(async() => { try { if (advertisementResult?.Data?.splash?.Count > 0) { var splashInfo = advertisementResult.Data.splash[0]; if (!splashInfo.ImgName.Equals(Global.AppConfig.LastCacheSplashFileName)) //缓存的不是当前Splash { if (await LocalCacheUtility.CacheHttpFileAsync(splashInfo.ImgName, splashInfo.ImgUrl)) { Global.AppConfig.LastCacheSplashFileName = splashInfo.ImgName; Global.AppConfig.CacheSplashExpire = VariousUtility.TimeStampToDateTime(splashInfo.expire * 10000L); Global.SaveAppConfig(); } } } } catch (Exception ex) { Debug.WriteLine(ex); } }); var activity = advertisementResult.Data.activity?.Count > 0 ? advertisementResult.Data.activity[0] : null; if (activity != null) { if (Global.AppConfig.LastShowActivityId == activity.id && Global.AppConfig.LastShowActivityTime > DateTime.Now.AddHours(-3)) //今天已经显示过当前活动,则不再显示 { return; } else //显示活动 { ActivityPopupContentView activityPopupContentView = new ActivityPopupContentView(); ActivityPopupContentViewModel popupContentViewModel = new ActivityPopupContentViewModel() { Activity = activity, }; await ShowContentNotifyAsync(activityPopupContentView, popupContentViewModel); } } } else { if (tryTimes-- > 0) { await GetCurrentActivities(tryTimes); } } }
public SettingContentViewModel() { LoginOutCommand = new RelayCommand(async(state) => { var dialogResult = await MessageDialogUtility.ShowMessageAsync("您确认要退出登录吗?", "退出登录"); if (dialogResult == MessageDialogResult.OK) { Global.ClearUserStatus(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (Window.Current?.Content is Frame rootFrame) { rootFrame.BackStack.Clear(); } }); await TryNavigateAsync(typeof(NoLoginView)); } }); ClearCacheCommand = new RelayCommand(async(state) => { var dialogResult = await MessageDialogUtility.ShowMessageAsync("您确认要清除所有缓存吗?", "缓存清理"); if (dialogResult == MessageDialogResult.OK) { Global.ClearCacheSetting(); await LocalCacheUtility.ClearLocalCacheFile(); await MessageDialogUtility.ShowMessageAsync("缓存清理完成", "缓存清理", MessageDialogType.OK); var cacheSize = await LocalCacheUtility.GetLocalCacheSizeAsync(true); CacheSize = VariousUtility.ByteSizeToString(cacheSize); } }); AboutSoftWareLicenseCommand = new RelayCommand((state) => { var args = new ContentPageArgs() { Name = "软件授权", ContentElement = new SoftWareLicenseContentView(), }; ContentNavigation(args); }); AboutUsCommand = new RelayCommand((state) => { var args = new ContentPageArgs() { Name = "关于我们", ContentElement = new AboutUsContentView(), }; ContentNavigation(args); }); AboutSoftWareCommand = new RelayCommand((state) => { var args = new ContentPageArgs() { Name = "免责声明", ContentElement = new AboutSoftWareContentView(), }; ContentNavigation(args); }); }
protected override async Task InitializationAsync() { var cacheSize = await LocalCacheUtility.GetLocalCacheSizeAsync(true); CacheSize = VariousUtility.ByteSizeToString(cacheSize); }