private async Task <GetPostQueryResult.File> ProcessFile(GetPostQueryResult.FullPost post, GetPostDbResult.PostFileDbResult file, PostSecurityResult access, AccessSignatureExpiryInformation expiry) { var fileInformation = await this.fileInformationAggregator.GetFileInformationAsync(post.ChannelId, file.FileId, file.Purpose); RenderSize renderSize = null; if (file.RenderWidth.HasValue && file.RenderHeight.HasValue) { renderSize = new RenderSize(file.RenderWidth.Value, file.RenderHeight.Value); } var fileSourceInformation = new FileSourceInformation( file.FileName, file.FileExtension, this.mimeTypeMap.GetMimeType(file.FileExtension), file.FileSize, renderSize); BlobSharedAccessInformation accessInformation = null; if (access == PostSecurityResult.Denied) { if (file.Purpose == FilePurposes.PostImage) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid() + "/" + FileManagement.Shared.Constants.PostPreviewImageThumbnailName, expiry.Private); } } else if (access == PostSecurityResult.FreePost) { if (file.Purpose == FilePurposes.PostImage) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid() + "/" + FileManagement.Shared.Constants.PostFeedImageThumbnailName, expiry.Private); } else if (file.Purpose == FilePurposes.PostFile) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid(), expiry.Private); } } var completeFile = new GetPostQueryResult.File(fileInformation, fileSourceInformation, accessInformation); return(completeFile); }
private async Task PerformTest( PostSecurityResult access, Comment expectedContent, BlobSharedAccessInformation expectedFileSharedAccessInformation, BlobSharedAccessInformation expectedImageSharedAccessInformation) { var result = await this.target.ExecuteAsync(PostData, access, Expiry); Assert.AreEqual( new GetPostQueryResult( new GetPostQueryResult.FullPost( CreatorId, Creator, PostId, BlogId, Blog, ChannelId, Channel, expectedContent, PreviewWordCount, WordCount, ImageCount, FileCount, VideoCount, LiveDate, LikesCount, CommentsCount, true, access == PostSecurityResult.Denied, access == PostSecurityResult.FreePost), new List <GetPostQueryResult.File> { new GetPostQueryResult.File( new FileInformation(FileId1, ContainerName1), new FileSourceInformation(FileName1, FileExtension1, ContentType1, FileSize1, new RenderSize(FileWidth1, FileHeight1)), expectedFileSharedAccessInformation), new GetPostQueryResult.File( new FileInformation(FileId2, ContainerName2), new FileSourceInformation(FileName2, FileExtension2, ContentType2, FileSize2, new RenderSize(FileWidth2, FileHeight2)), expectedImageSharedAccessInformation), }), result); }
public async Task WhenAnUploadRequestIsPosted_ItShouldInitiateTheFileUploadAndGenerateAWritableBlobUri() { this.guidCreator.Setup(v => v.CreateSqlSequential()).Returns(GeneratedSqlGuid); const string FilePath = @"C:\test\myfile.jpeg"; const string Purpose = "profile-picture"; this.requesterContext.Setup(_ => _.GetRequesterAsync()).ReturnsAsync(Requester); this.initiateFileUpload.Setup(v => v.HandleAsync(new InitiateFileUploadCommand(Requester, ChannelId, FileId, FilePath, Purpose))) .Returns(Task.FromResult(0)); var accessInformation = new BlobSharedAccessInformation("containerName", "blobName", "uri", "sig", DateTime.UtcNow); this.generateWritableBlobUri.Setup(v => v.HandleAsync(new GenerateWritableBlobUriQuery(Requester, ChannelId, FileId, Purpose))) .ReturnsAsync(accessInformation); var response = await this.target.PostUploadRequestAsync(new UploadRequest(ChannelId.Value.EncodeGuid(), FilePath, Purpose)); Assert.AreEqual(new GrantedUpload(FileId, accessInformation), response); }
public async Task <GetPreviewNewsfeedQueryResult> HandleAsync(GetNewsfeedQuery query) { query.AssertNotNull("query"); var requestingUserId = await this.requesterSecurity.TryAuthenticateAsync(query.Requester); var now = this.timestampCreator.Now(); var postsResult = await this.getPreviewNewsfeedDbStatement.ExecuteAsync( requestingUserId, query.CreatorId, query.ChannelIds, now, query.Origin ?? now, query.SearchForwards, query.StartIndex, query.Count); var posts = postsResult.Posts; var expiry = this.getAccessSignatureExpiryInformation.Execute(now); var results = new List <GetPreviewNewsfeedQueryResult.PreviewPost>(); foreach (var post in posts) { FileInformation profileImage = null; if (post.ProfileImageFileId != null) { profileImage = await this.fileInformationAggregator.GetFileInformationAsync( null, post.ProfileImageFileId, FilePurposes.ProfileImage); } FileInformation image = null; BlobSharedAccessInformation imageAccessInformation = null; if (post.ImageId != null) { image = await this.fileInformationAggregator.GetFileInformationAsync( post.ChannelId, post.ImageId, FilePurposes.PostImage); var imageType = post.IsFreePost ? FileManagement.Shared.Constants.PostFeedImageThumbnailName : FileManagement.Shared.Constants.PostPreviewImageThumbnailName; imageAccessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( image.ContainerName, image.FileId.Value.EncodeGuid() + "/" + imageType, expiry.Public); } RenderSize imageRenderSize = null; if (post.ImageRenderWidth.HasValue && post.ImageRenderHeight.HasValue) { imageRenderSize = new RenderSize(post.ImageRenderWidth.Value, post.ImageRenderHeight.Value); } var completePost = new GetPreviewNewsfeedQueryResult.PreviewPost( post.CreatorId, new GetPreviewNewsfeedQueryResult.PreviewPostCreator(new Username(post.Username), profileImage), post.PostId, post.BlogId, new GetPreviewNewsfeedQueryResult.PreviewPostBlog(new BlogName(post.BlogName), null, null), post.ChannelId, new GetPreviewNewsfeedQueryResult.PreviewPostChannel(new ChannelName(post.ChannelName)), post.PreviewText, image, image == null ? null : new FileSourceInformation(post.ImageName, post.ImageExtension, this.mimeTypeMap.GetMimeType(post.ImageExtension), post.ImageSize ?? 0, imageRenderSize), imageAccessInformation, post.PreviewWordCount, post.WordCount, post.ImageCount, post.FileCount, post.VideoCount, post.LiveDate, post.LikesCount, post.CommentsCount, post.HasLikedPost, post.IsFreePost); results.Add(completePost); } return(new GetPreviewNewsfeedQueryResult(results)); }