Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public async Task <GetPostQueryResult> ExecuteAsync(GetPostDbResult postData, PostSecurityResult access, AccessSignatureExpiryInformation expiry)
        {
            postData.AssertNotNull("postData");
            expiry.AssertNotNull("expiry");

            var post = await this.ProcessPost(postData.Post, access);

            var files = new List <GetPostQueryResult.File>();

            foreach (var file in postData.Files)
            {
                var completeFile = await this.ProcessFile(post, file, access, expiry);

                files.Add(completeFile);
            }

            return(new GetPostQueryResult(post, files));
        }