コード例 #1
0
        public async Task <EntryMedia> MarkUploadedSuccess(EntryMedia articleEntryMedia, string uploadUri)
        {
            if (articleEntryMedia == null)
            {
                throw new ArgumentNullException(nameof(articleEntryMedia));
            }
            if (string.IsNullOrWhiteSpace(uploadUri))
            {
                throw new ArgumentNullException(nameof(uploadUri));
            }

            _context.Attach(articleEntryMedia);

            articleEntryMedia.BlobUrl   = StringUtilities.ToBase64(uploadUri);
            articleEntryMedia.Persisted = _clock.Now;

            await _context.SaveChanges();

            return(articleEntryMedia);
        }
コード例 #2
0
        public async Task <string> UploadEntryMedia(ArticleEntryMediaRequest entryMediaRequest,
                                                    EntryMedia articleEntryMedia)
        {
            if (entryMediaRequest == null)
            {
                throw new ArgumentNullException(nameof(entryMediaRequest));
            }
            if (articleEntryMedia == null)
            {
                throw new ArgumentNullException(nameof(articleEntryMedia));
            }
            if (entryMediaRequest.MediaContent == null)
            {
                throw new Exception($"{nameof(entryMediaRequest.MediaContent)} cannot be null");
            }

            var uploadUri = await _blobStore.PersistArticleEntryMedia(articleEntryMedia.Id,
                                                                      articleEntryMedia.EntryContentId,
                                                                      entryMediaRequest.MediaContent,
                                                                      entryMediaRequest.ContentType);

            return(uploadUri);
        }
コード例 #3
0
        public async Task <IActionResult> FindEntryMedia(Guid entryId,
                                                         [FromHeader(Name = "If-Match")] string ifMatch,
                                                         [FromHeader(Name = "Content-Disposition")] string contentDisposition)
        {
            if (string.IsNullOrWhiteSpace(ifMatch))
            {
                return(NotFound());
            }

            ifMatch = ifMatch.Replace("\"", string.Empty);
            string     fileName = HeaderUtilityHelper.TryGetContentDispositionFileName(contentDisposition);
            EntryMedia result   = string.IsNullOrWhiteSpace(fileName)
                ? await _mediaSearchStrategy.Find(entryId, ifMatch)
                : await _mediaSearchStrategy.Find(entryId, ifMatch, fileName);


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

            return(NoContent());
        }
コード例 #4
0
 private Task <EntryMedia> StoreBlobUriAndMarkUploadSuccess(EntryMedia articleEntryMedia, string uploadUri)
 {
     return(_createEntryMediaCoordinator.MarkUploadedSuccess(articleEntryMedia, uploadUri));
 }
コード例 #5
0
        private async Task <EntryMedia> UploadMediaContent(ArticleEntryMediaRequest entryMediaRequest, EntryMedia articleEntryMedia)
        {
            var uploadUri = await _uploadCoordinator.UploadEntryMedia(entryMediaRequest, articleEntryMedia);

            if (string.IsNullOrWhiteSpace(uploadUri))
            {
                return(articleEntryMedia);
            }

            return(await StoreBlobUriAndMarkUploadSuccess(articleEntryMedia, uploadUri));
        }
コード例 #6
0
        public async Task FindsMediaEntryByHashAndFileNameIfExists(Article[] allArticles, Guid entryContentId, string testMd5HashToFind, string fileNameToFind, EntryMedia expected = null)
        {
            var contextFixture = new MockBlogApiDbContextFixture();

            contextFixture.WithQuery(allArticles);

            var context = contextFixture.Build();
            var entryMediaSearchStrategy = new EntryMediaSearchStrategyFixture
            {
                Context = context
            }.Build();

            var result = await entryMediaSearchStrategy.Find(entryContentId, testMd5HashToFind, fileNameToFind);

            contextFixture.Mock.Verify(ctx => ctx.Query <Article>());

            if (expected == null)
            {
                Assert.Null(result);
                return;
            }

            Assert.Equal(expected, result);
        }