Esempio n. 1
0
        public async Task <StatusEntityPair <EntryStatusEntity, EntryEntity> > QueryEntryAsync(int storageNo)
        {
            var path = Path.Combine(Definition.EntryDirectory, Definition.EntryFileFormatter(storageNo));

            if (!fileService.IsFileExists(path))
            {
                return(new StatusEntityPair <EntryStatusEntity, EntryEntity>(
                           new EntryStatusEntity {
                    StorageNo = storageNo
                },
                           Enumerable.Empty <EntryEntity>()));
            }

            using (var stream = await fileService.OpenReadAsync(path).ConfigureAwait(false))
            {
                // Status
                var buffer = new byte[EntryStatusEntity.Size];

                stream.Read(buffer, 0, buffer.Length);

                var status = new EntryStatusEntity();
                status.FromBytes(buffer);

                // Entity
                var count = (int)((stream.Length - EntryStatusEntity.Size) / EntryEntity.Size);
                var list  = new List <EntryEntity>(count);

                buffer = new byte[EntryEntity.Size];
                for (var i = 0; i < count; i++)
                {
                    stream.Position = (EntryEntity.Size * i) + EntryStatusEntity.Size;
                    stream.Read(buffer, 0, buffer.Length);

                    var entity = new EntryEntity {
                        DetailNo = i + 1
                    };
                    entity.FromBytes(buffer);
                    list.Add(entity);
                }

                return(new StatusEntityPair <EntryStatusEntity, EntryEntity>(status, list));
            }
        }
Esempio n. 2
0
        public async Task <EntryStatusEntity[]> QueryEntryStatusListAsync()
        {
            var list   = new List <EntryStatusEntity>();
            var buffer = new byte[EntryStatusEntity.Size];

            foreach (var file in await fileService.GetFilesAsync(Definition.EntryDirectory, "*"))
            {
                var path = Path.Combine(Definition.EntryDirectory, file);
                using (var stream = await fileService.OpenReadAsync(path).ConfigureAwait(false))
                {
                    stream.Read(buffer, 0, buffer.Length);

                    var entity = new EntryStatusEntity();
                    entity.FromBytes(buffer);

                    list.Add(entity);
                }
            }

            return(list.ToArray());
        }