public static async System.Threading.Tasks.Task RunAsync([QueueTrigger("eventqueue", Connection = "AzureWebJobsStorage")] CreateReportRequested request,
                                                                 [Table("downloads", Connection = "AzureWebJobsStorage")] IAsyncCollector <UserReportRecord> download,
                                                                 [Blob("user-reports", Connection = "AzureWebJobsStorage")] CloudBlobContainer container,
                                                                 ILogger log)
        {
            if (await container.CreateIfNotExistsAsync())
            {
                var permissions = await container.GetPermissionsAsync();

                permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                await container.SetPermissionsAsync(permissions);
            }

            var blob = container.GetBlockBlobReference($"{request.Id}.pdf");

            var pdfFile = PDFGenerator.GeneratePDF(request);

            await blob.UploadFromByteArrayAsync(pdfFile, 0, pdfFile.Length);

            var url = blob.Uri.AbsoluteUri;

            await download.AddAsync(new UserReportRecord
            {
                PartitionKey = "UserReport",
                RowKey       = request.Id.ToString(),
                Name         = $"{request.FirstName} {request.LastName}",
                Url          = url
            });
        }
Exemplo n.º 2
0
        public static void Run(
            [QueueTrigger("eventqueue", Connection = "AzureWebJobsStorage")] CreateReportRequested request,
            [Table("downloads", Connection = "AzureWebJobsStorage")] out UserReportRecord download,
            [Blob("user-reports", Connection = "AzureWebJobsStorage")] CloudBlobContainer container,
            TraceWriter log)
        {
            if (container.CreateIfNotExists())
            {
                var permissions = container.GetPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                container.SetPermissions(permissions);
            }

            var blob = container.GetBlockBlobReference($"{request.Id}.pdf");

            var pdfFile = PDFGenerator.GeneratePDF(request);

            blob.UploadFromByteArray(pdfFile, 0, pdfFile.Length);

            var url = blob.Uri.AbsoluteUri;

            download = new UserReportRecord
            {
                PartitionKey = "UserReport",
                RowKey       = request.Id.ToString(),
                Name         = $"{request.FirstName} {request.LastName}",
                Url          = url
            };
        }