Exemplo n.º 1
0
        public async Task DeleteFilesAsync(IEnumerable <Guid> fileIds)
        {
            var storageDirectory = _configuration.GetValue <string>("FileStoreDirectory");

            foreach (var fileId in fileIds)
            {
                var file          = _fileMetadataRepository.Get(fileId);
                var fileDirectory = Path.Combine(storageDirectory, fileId.ToString());

                if (Directory.Exists(fileDirectory))
                {
                    Directory.Delete(fileDirectory, true);
                }

                if (file == null)
                {
                    continue;
                }

                if (file.Store == FileStore.Azure)
                {
                    var blobReference = await _azureAccountManager.GetBlobReferenceAsync(file);

                    await blobReference.DeleteIfExistsAsync();
                }

                _fileMetadataRepository.Delete(file.Id);
            }
        }
Exemplo n.º 2
0
        private async Task Initialize(FileBlockInfo fileBlockInfo)
        {
            if (0 == Interlocked.Exchange(ref _initializing, 1))
            {
                try
                {
                    _fileMetadata.Id            = Guid.NewGuid();
                    _fileMetadata.FileName      = fileBlockInfo.FileName;
                    _fileMetadata.FileSize      = fileBlockInfo.FileSize;
                    _fileMetadata.Location      = _fileMetadata.Id.ToString();
                    _fileMetadata.CreateDateUtc = DateTime.UtcNow;
                    _fileMetadata.Store         = FileStore.Azure;

                    _blocksCount = fileBlockInfo.TotalBlocksCount;

                    _blockBlobReference = await _azureAccountManager.GetBlobReferenceAsync(_fileMetadata);
                }
                finally
                {
                    Interlocked.Exchange(ref _initialized, 1);
                }
            }
        }