Exemple #1
0
        /// <summary>
        ///     异步获取实例
        /// </summary>
        /// <returns></returns>
        public static async Task <FolderList> GetInstanceAsync()
        {
            var folderList = new FolderList();
            // 初始化list
            var query = folderList._databaseHelper.FolderDatabase.GetQuery();

            while (query.Read())
            {
                var folderModel = new FolderModel
                {
                    KeyNo       = query.GetInt32(0),
                    FolderPath  = query.GetString(1),
                    AccessToken = query.GetString(2)
                };
                // 查下这个文件夹还在不在
                var folder = await folderModel.GetFolder();

                if (folder != null)
                {
                    folderList.FolderModels.Add(folderModel);
                }
                else
                {
                    // 从图片数据库中删掉这个文件夹相关的图片
                    folderList._databaseHelper.ImageDatabase.Delete(folderModel.KeyNo);
                    // 从数据库里删掉这个文件夹
                    folderList._databaseHelper.FolderDatabase.Delete(folderModel.FolderPath);
                    // 从使用list里删掉这个文件夹
                    StorageApplicationPermissions.FutureAccessList.Remove(folderModel.AccessToken);
                }
            }
            return(folderList);
        }
Exemple #2
0
        /// <summary>
        ///     刷新list
        /// </summary>
        /// <returns></returns>
        public async Task RefreshAsync()
        {
            var folder = await _folderModel.GetFolder();

            // TODO 这里文件夹可能为空
            // 找到全部文件
            var files = await folder.GetFilesAsync();

            foreach (var file in files)
            {
                // 确认后缀名必须是图片
                if (file.FileType != ".jpg" && file.FileType != ".png" && file.FileType != ".jpeg")
                {
                    continue;
                }
                var accessToken = StorageApplicationPermissions.FutureAccessList.Add(file);
                var imageModel  = await ImageModel.GetInstanceAsync(_folderModel.KeyNo, file.Path, accessToken);

                Add(imageModel);
            }
        }