public void Dispose()
        {
            IEnumerable <TestObject> documents = new List <TestObject>()
            {
                new TestObject {
                    Id = "1"
                },
                new TestObject {
                    Id = "2"
                },
                new TestObject {
                    Id = "-123819"
                },
                new TestObject {
                    Id = "10"
                },
                new TestObject {
                    Id = "abc"
                },
                new TestObject {
                    Id = "3"
                }
            };

            foreach (TestObject document in documents)
            {
                _storageProvider.DeleteAsync(document);
            }
        }
        public async Task DisposeAsync()
        {
            IDocumentClient client = new DocumentClient(new Uri(getCosmosURI()), "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");

            IEnumerable <PartitionedTestObject> documents = new List <PartitionedTestObject>()
            {
                new PartitionedTestObject {
                    Id = "1", Partition = "partition"
                },
                new PartitionedTestObject {
                    Id = "2", Partition = "partition"
                },
                new PartitionedTestObject {
                    Id = "-123819", Partition = "partition"
                },
                new PartitionedTestObject {
                    Id = "10", Partition = "partition"
                },
                new PartitionedTestObject {
                    Id = "abc", Partition = "partition"
                },
                new PartitionedTestObject {
                    Id = "3", Partition = "partition"
                }
            };

            foreach (PartitionedTestObject document in documents)
            {
                await _storageProvider.DeleteAsync(document);
            }
            await Task.Delay(6000);
        }
示例#3
0
        public async Task DeleteAsync(BatchInput <long> input)
        {
            foreach (var id in input.Ids)
            {
                var picture = await _pictureManager.GetByIdAsync(id);

                //删除云存储资源文件
                await _storageProvider.DeleteAsync(picture.Key);

                await _pictureManager.DeleteAsync(picture);
            }
        }
        public async Task DeleteAsync(Guid attachmentId)
        {
            var attachment = await dbContext.FindAsync <Entities.Attachment>(attachmentId);

            if (attachment != null)
            {
                dbContext.Attachments.Remove(attachment);
                await dbContext.SaveChangesAsync();

                await storageProvider.DeleteAsync(attachment.Path);
            }
        }
示例#5
0
        public override async Task <EntityResponse <PhotoDTO> > CreateAsync(PhotoDTO dto)
        {
            return((EntityResponse <PhotoDTO>) await TransactionAsync(async context =>
            {
                var photo = Mapper.Map <Photo>(dto);
                try
                {
                    photo.ImageUrl = (await _storageProvider.SaveFileAndGetUriAsync(ContainerStore.PHOTO_CONTAINER, dto.ImageFile.FileName, dto.ImageFile).ConfigureAwait(false)).ToString();
                    photo.FileName = dto.ImageFile.FileName;

                    await context.Photos.AddAsync(photo).ConfigureAwait(false);
                    await context.SaveChangesAsync().ConfigureAwait(false);

                    return new EntityResponse <PhotoDTO>(Mapper.Map <PhotoDTO>(photo));
                }
                catch
                {
                    await _storageProvider.DeleteAsync(ContainerStore.PHOTO_CONTAINER, photo.FileName).ConfigureAwait(false);
                    throw;
                }
            }).ConfigureAwait(false));
        }
示例#6
0
        public async Task <IActionResult> DeleteAsync([FromRoute] int id)
        {
            var file = await _repositoryManager
                       .FileRepository.GetByFileIdAsync(id);

            if (file == null)
            {
                return(NotFound());
            }

            _repositoryManager.FileRepository.Delete(file);

            var result = await _storageProvider.DeleteAsync(file.Path);

            await _repositoryManager.SaveAsync();

            return(Ok(result));
        }
示例#7
0
        public async Task WriteAsync(string key, Stream data, bool replace = true)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentException($"key should not be null or empty string", nameof(key));
            }
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data), "Cannot write null data");
            }

            try
            {
                if (!_storageProvider.IsThreadSafe)
                {
                    await _semaphore.WaitAsync(key);
                }

                if (await _storageProvider.ExistsAsync(key).ConfigureAwait(false))
                {
                    if (replace)
                    {
                        await _storageProvider.DeleteAsync(key).ConfigureAwait(false);
                    }
                    else
                    {
                        throw new IOException("File already exists");
                    }
                }

                await _storageProvider.CreateAsync(key, data).ConfigureAwait(false);
            }
            finally
            {
                if (!_storageProvider.IsThreadSafe)
                {
                    _semaphore.Release(key);
                }
            }
        }
示例#8
0
 public async Task <bool> DeleteShowAsync(ShowObject _object)
 {
     return(await _showStore.DeleteAsync(_object));
 }
示例#9
0
 public async Task <bool> DeleteNewsAsync(NewsObject _object)
 {
     return(await _newsStore.DeleteAsync(_object));
 }
示例#10
0
 public async Task <bool> DeleteImageAsync(ImageObject _object)
 {
     return(await _imageStore.DeleteAsync(_object));
 }
示例#11
0
 public Task CleanupAsync(IChallengeContext[] challengeContexts, CancellationToken cancellationToken)
 {
     return(Task.WhenAll(challengeContexts.Select(c => _storageProvider.DeleteAsync(_pathPrefix + c.Token, cancellationToken))));
 }
示例#12
0
 public async Task RemoveAsync(int key)
 {
     await _storageProvider.DeleteAsync(key);
 }
示例#13
0
        public override async Task <EntityResponse <BlogDTO> > CreateAsync(BlogDTO dto)
        {
            return((EntityResponse <BlogDTO>) await TransactionAsync(async context =>
            {
                ICollection <BlogPhoto> blogPhotos = new List <BlogPhoto>();
                ICollection <Photo> photos = new List <Photo>();
                var blog = Mapper.Map <Blog>(dto);
                try
                {
                    // add the new blog to the context.
                    await context.Blogs.AddAsync(blog).ConfigureAwait(false);
                    await context.SaveChangesAsync().ConfigureAwait(false);

                    // process each photo linked to the new blog.
                    foreach (var photoDTO in dto.Photos)
                    {
                        // check if the photo already exists.
                        var photo = await context.Photos.FindAsync(photoDTO.Id).ConfigureAwait(false);

                        // else if a new photo is used, process and add a new photo to the context.
                        if (photo == null && photoDTO.ImageFile != null)
                        {
                            photo = Mapper.Map <Photo>(photoDTO);
                            photo.ImageUrl = (await _storageProvider.SaveFileAndGetUriAsync(ContainerStore.PHOTO_CONTAINER, photoDTO.ImageFile.FileName, photoDTO.ImageFile).ConfigureAwait(false)).ToString();
                            photo.FileName = photoDTO.ImageFile.FileName;
                            photos.Add(photo);
                            await context.Photos.AddAsync(photo).ConfigureAwait(false);
                            await context.SaveChangesAsync().ConfigureAwait(false);
                        }
                        if (photo == null)
                        {
                            continue;
                        }

                        // stack the new many-to-many link until all photos are processed.
                        blogPhotos.Add(new BlogPhoto
                        {
                            BlogId = blog.Id,
                            PhotoId = photo.Id
                        });
                    }

                    // add all linked many-to-many relations between blog and photos.
                    await context.Set <BlogPhoto>().AddRangeAsync(blogPhotos).ConfigureAwait(false);
                    await context.SaveChangesAsync().ConfigureAwait(false);

                    // return the resulting blog entity.
                    return new EntityResponse <BlogDTO>(Mapper.Map <BlogDTO>(blog));
                }
                catch
                {
                    // if something in the process goes wrong, we undo the entire process.
                    // first we remove all succesful photo uploads.
                    foreach (var photo in photos)
                    {
                        await _storageProvider.DeleteAsync(ContainerStore.PHOTO_CONTAINER, photo.FileName).ConfigureAwait(false);
                    }

                    // then we re-throw the exception in order to let the context transaction rollback all database mutations.
                    throw;
                }
            }).ConfigureAwait(false));
        }
        public void TestStorageProvider()
        {
            // TestAddStorageFile

            // Act
            Task <StorageFile> addResult = _storageProvider.AddFileAsync(_userId, _filePath, "application/octet-stream");

            addResult.Wait();

            // Assert
            Assert.IsFalse(addResult.IsFaulted);
            Assert.AreNotEqual(addResult.Result.FileId, new Guid());
            Assert.AreEqual(addResult.Result.Users.Count, 0);
            Assert.AreEqual(addResult.Result.Groups.Count, 0);

            _fileId = addResult.Result.FileId;

            // TestExistsStorageFile

            // Act
            var existAfterAddResult = _storageProvider.ExistsFileAsync(_filePath);

            existAfterAddResult.Wait();

            // Assert
            Assert.IsFalse(existAfterAddResult.IsFaulted);
            Assert.IsTrue(existAfterAddResult.Result);

            // TestGetStorageFile

            // Act
            Task <StorageFile> getAfterAddResult = _storageProvider.GetByIdAsync(_fileId);

            getAfterAddResult.Wait();

            // Assert
            Assert.IsFalse(getAfterAddResult.IsFaulted);
            Assert.IsNotNull(getAfterAddResult.Result);
            Assert.AreNotEqual(getAfterAddResult.Result.FileId, new Guid());
            Assert.AreEqual(getAfterAddResult.Result.OwnerUserId, _userId);
            Assert.AreEqual(getAfterAddResult.Result.Users.Count, 0);
            Assert.AreEqual(getAfterAddResult.Result.Groups.Count, 0);

            // TestUpdateStorageFile

            // Arrange
            var storageFile = new StorageFile(_fileId, string.Empty, _userId)
            {
                Users = new List <string> {
                    "vasya"
                }
            };

            // Act
            var updateResult = _storageProvider.UpdateAsync(storageFile);

            updateResult.Wait();

            // Assert
            Assert.IsFalse(updateResult.IsFaulted);

            // TestGetStorageFileAfterUpdate

            // Act
            Task <StorageFile> getAfterUpdateResult = _storageProvider.GetByIdAsync(_fileId);

            getAfterUpdateResult.Wait();

            // Assert
            Assert.IsFalse(getAfterUpdateResult.IsFaulted);
            Assert.AreNotEqual(getAfterUpdateResult.Result.FileId, new Guid());
            Assert.IsTrue(getAfterUpdateResult.Result.Users.Contains("vasya"));

            // TestDeleteStorageFile

            // Arrange
            storageFile = new StorageFile(_fileId, string.Empty, _userId);

            // Act
            var deleteResult = _storageProvider.DeleteAsync(storageFile.FileId, true);

            deleteResult.Wait();

            // Assert
            Assert.IsFalse(deleteResult.IsFaulted);

            // TestExistsStorageFileAfterDelete

            // Act
            var existsAfterDeleteResult = _storageProvider.ExistsFileAsync(_filePath);

            existsAfterDeleteResult.Wait();

            // Assert
            Assert.IsFalse(existsAfterDeleteResult.IsFaulted);
            Assert.IsFalse(existsAfterDeleteResult.Result);

            // TestGetStorageFileAfterDelete

            // Act
            Task <StorageFile> getAfterDeleteResult = _storageProvider.GetByIdAsync(_fileId);

            getAfterDeleteResult.Wait();

            // Assert
            Assert.IsFalse(getAfterDeleteResult.IsFaulted);
            Assert.IsNull(getAfterDeleteResult.Result);
        }