Esempio n. 1
0
        /// <summary>
        /// 从储存反序列化所有数据
        /// </summary>
        /// <returns></returns>
        private async Task RestoreData()
        {
            try
            {
                SelectedCate = 0;

                AllToDos = await SerializerHelper.DeserializeFromJsonByFile <ObservableCollection <ToDo> >(SerializerFileNames.ToDoFileName);

                CurrentDisplayToDos = AllToDos;

                Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(AllToDos), MessengerTokens.UpdateTile);

                DeletedToDos = await SerializerHelper.DeserializeFromJsonByFile <ObservableCollection <ToDo> >(SerializerFileNames.DeletedFileName);

                DeletedToDos.ToList().ForEach(s =>
                {
                    if (s == null)
                    {
                        DeletedToDos.Remove(s);
                    }
                });

                StagedToDos = await SerializerHelper.DeserializeFromJsonByFile <ObservableCollection <ToDo> >(SerializerFileNames.StageFileName);

                App.HasSyncedListOnce = true;
            }
            catch (Exception ex)
            {
                var task = Logger.LogAsync(ex);
            }
        }
Esempio n. 2
0
        public async Task LoadAsync()
        {
            try
            {
                var tempFolder = GetCachedFileFolder();
                this.CachedFiles = await SerializerHelper.DeserializeFromJsonByFile <Dictionary <string, string> >("CachedFiles", tempFolder);

                if (this.CachedFiles == null)
                {
                    CachedFiles = new Dictionary <string, string>();
                }
            }
            catch (Exception)
            {
                CachedFiles = new Dictionary <string, string>();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 从本地缓存还原列表,如果不存在缓存,则还原默认列表
        /// </summary>
        /// <returns></returns>
        private async Task <ObservableCollection <ToDoCategory> > RestoreCacheButDefaultList()
        {
            var cacheList = await SerializerHelper.DeserializeFromJsonByFile
                            <ObservableCollection <ToDoCategory> >(SerializerFileNames.CategoryFileName);

            if (cacheList != null)
            {
                if (cacheList.Count >= 3)
                {
                    cacheList.ToList().ForEach(s => s.UpdateColor());
                    return(cacheList);
                }
            }
            var defaultList = GenerateList(AppSettings.DefaultCateJsonString);

            return(defaultList);
        }
Esempio n. 4
0
        private async Task RestoreMainListDataAsync()
        {
            var file = await CacheUtil.GetCachedFileFolder().TryGetFileAsync(CachedFileNames.MainListFileName);

            if (file != null)
            {
                var list = await SerializerHelper.DeserializeFromJsonByFile <IncrementalLoadingCollection <UnsplashImage> >(CachedFileNames.MainListFileName, CacheUtil.GetCachedFileFolder());

                if (list != null)
                {
                    this.MainDataVM = new ImageDataViewModel(this, UrlHelper.GetFeaturedImages);
                    list.ToList().ForEach(s => MainDataVM.DataList.Add(s));

                    for (int i = 0; i < MainDataVM.DataList.Count; i++)
                    {
                        var item = MainDataVM.DataList[i];
                        if (i % 2 == 0)
                        {
                            item.BackColor = new SolidColorBrush(ColorConverter.HexToColor("#FF2E2E2E").Value);
                        }
                        else
                        {
                            item.BackColor = new SolidColorBrush(ColorConverter.HexToColor("#FF383838").Value);
                        }
                        var task = item.RestoreAsync();
                    }
                    await UpdateLiveTileAsync();
                }
                else
                {
                    MainDataVM = new ImageDataViewModel(this, UrlHelper.GetFeaturedImages);
                }
            }
            else
            {
                MainDataVM = new ImageDataViewModel(this, UrlHelper.GetFeaturedImages);
            }
        }
Esempio n. 5
0
        private async Task RestoreMainListDataAsync()
        {
            var file = await CacheUtil.GetCachedFileFolder().TryGetFileAsync(CachedFileNames.MainListFileName);

            if (file != null)
            {
                var list = await SerializerHelper.DeserializeFromJsonByFile <IncrementalLoadingCollection <UnsplashImageBase> >(CachedFileNames.MainListFileName, CacheUtil.GetCachedFileFolder());

                if (list != null)
                {
                    this.MainDataVM = new ImageDataViewModel(this, UrlHelper.GetNewImages, true);
                    list.ToList().ForEach(s => MainDataVM.DataList.Add(s));

                    for (int i = 0; i < MainDataVM.DataList.Count; i++)
                    {
                        var item = MainDataVM.DataList[i];
                        if (i % 2 == 0)
                        {
                            item.BackColor = App.Current.Resources["ImageBackBrush1"] as SolidColorBrush;
                        }
                        else
                        {
                            item.BackColor = App.Current.Resources["ImageBackBrush2"] as SolidColorBrush;
                        }
                        var task = item.RestoreDataAsync();
                    }
                }
                else
                {
                    MainDataVM = new ImageDataViewModel(this, UrlHelper.GetNewImages, true);
                }
            }
            else
            {
                MainDataVM = new ImageDataViewModel(this, UrlHelper.GetNewImages, true);
            }
        }
Esempio n. 6
0
        private async Task RestoreCategoriyListAsync()
        {
            this.Categories = await SerializerHelper.DeserializeFromJsonByFile <ObservableCollection <UnsplashCategory> >(CachedFileNames.CateListFileName);

            SelectedIndex = 1;
        }