Ejemplo n.º 1
0
        public async Task <IReadOnlyList <FSFile> > GetAll(FSTable table, string page)
        {
            var tableFolder = FindTableFolder(table, page);

            StorageFile[] tableFiles = tableFolder.GetFilesOrderedByName();
            return(await ReadFiles(table, tableFiles));
        }
Ejemplo n.º 2
0
        public async Task <IReadOnlyList <FSFile> > GetRange(FSTable table, uint startIndex, uint maxCount, string page)
        {
            var tableFolder = FindTableFolder(table, page);
            var tableFiles  = tableFolder.GetFilesOrderedByName((int)startIndex, (int)maxCount);

            return(await ReadFiles(table, tableFiles));
        }
Ejemplo n.º 3
0
        public async Task DeleteTableIfExists(FSTable table, string page)
        {
            StorageFolder tableFolder = FindTableFolder(table, page);

            if (tableFolder == null)
            {
                return;
            }
            tableFolder.DeleteIfExists();
            await Task.CompletedTask;
        }
Ejemplo n.º 4
0
        public async Task UpdateFile(FSTable table, FSFile file, string page)
        {
            if (table == null || file?.Id == null)
            {
                throw new ArgumentException();
            }
            var tableFolder = FindTableFolder(table, page);
            var storageFile = tableFolder.TryGetFile(file.Id);

            FileIO.WriteBytes(storageFile, file.Contents);
            await Task.CompletedTask;
        }
Ejemplo n.º 5
0
        public async Task <FSFile> FindFile(FSTable table, string id, string page)
        {
            if (table == null || id == null)
            {
                throw new ArgumentException();
            }
            var         tableFolder = FindTableFolder(table, page);
            StorageFile storageFile = tableFolder.TryGetFile(id);

            if (storageFile == null)
            {
                return(null);
            }
            byte[] buffer = FileIO.ReadBuffer(storageFile);
            return(new FSFile(buffer.ToArray(), id));
        }
Ejemplo n.º 6
0
        StorageFolder FindTableFolder(FSTable table, string page)
        {
            StorageFolder tableFolder = this.storeFolder.TryGetItemAsync(table.TableFolderName());

            if (tableFolder == null)
            {
                return(null);
            }
            if (!table.IsPaged || page == null)
            {
                return(tableFolder);
            }
            StorageFolder pageFolder = tableFolder.CreateFolderAsync(page, CreationCollisionOption.OpenIfExists);

            return(pageFolder);
        }
Ejemplo n.º 7
0
        public async Task DeleteFileIfExists(FSTable table, string id, string page)
        {
            if (table == null || id == null)
            {
                throw new ArgumentException();
            }
            var         tableFolder = FindTableFolder(table, page);
            StorageFile storageFile = tableFolder.TryGetFile(id);

            if (storageFile == null)
            {
                return;
            }
            storageFile.Delete();
            await Task.CompletedTask;
        }
Ejemplo n.º 8
0
        async Task <List <FSFile> > ReadFiles(FSTable table, IReadOnlyList <StorageFile> tableFiles)
        {
            var files = new List <FSFile>();

            if (!table.ReadListInReverseOrder)
            {
                for (var i = 0; i < tableFiles.Count; i++)
                {
                    var buffer = FileIO.ReadBuffer(tableFiles[i]);
                    files.Add(new FSFile(buffer.ToArray(), tableFiles[i].Name));
                }
            }
            else
            {
                for (var i = tableFiles.Count - 1; i >= 0; i--)
                {
                    var buffer = FileIO.ReadBuffer(tableFiles[i]);
                    files.Add(new FSFile(buffer.ToArray(), tableFiles[i].Name));
                }
            }
            return(files);
        }
Ejemplo n.º 9
0
        public async Task <string> InsertFile(FSTable table, string itemId, Func <string, object, object, byte[]> doSerialize, object serFun, object entity, string page = null, int currentAttmept = 1)
        {
            if (table == null || doSerialize == null)
            {
                throw new ArgumentException();
            }
            var tableFolder = FindTableFolder(table, page);

            if (table.IdMode == IdMode.UserGenerated)
            {
                StorageFile newFile = tableFolder.CreateFile(itemId, CreationCollisionOption.FailIfExists);
                FileIO.WriteBytes(newFile, doSerialize(newFile.Name, serFun, entity));
                return(newFile.Name);
            }

            string nextId = GetNextId(tableFolder);

            try
            {
                StorageFile newFile = tableFolder.CreateFile(nextId, CreationCollisionOption.FailIfExists);
                FileIO.WriteBytes(newFile, doSerialize(newFile.Name, serFun, entity));
                return(newFile.Name);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                Debug.WriteLine($"Insert Attempt {currentAttmept} failed.");
                uint dummy;
                FStoreTables.IdCache.TryRemove(tableFolder.Name, out dummy);
                if (currentAttmept > 10)
                {
                    throw;
                }
                return(await InsertFile(table, itemId, doSerialize, serFun, entity, page, currentAttmept + 1));
            }
        }
Ejemplo n.º 10
0
        public void CreateTable(FSTable table)
        {
            var store = this.storeFolder;

            store.CreateFolderAsync(table.TableFolderName(), CreationCollisionOption.FailIfExists);
        }
Ejemplo n.º 11
0
        public bool TableExists(FSTable table, string page)
        {
            var tableFolder = FindTableFolder(table, page);

            return(tableFolder != null);
        }
Ejemplo n.º 12
0
        public async Task <uint> CountFiles(FSTable table, string page)
        {
            var tableFolder = FindTableFolder(table, page);

            return(tableFolder.CountFiles());
        }