Пример #1
0
        public async Task <FileContentResult> GetPDFRecommendations()
        {
            var subscription = (await subscriptionsClient.GetSubscriptionsAsync(0, 1)).Subscriptions.First();

            var template = await SendTemplateToCloud(subscription.TemplatesFolder.FolderId);

            ExportTemplateTaskVM eTaskVM = new()
            {
                FileName = "songs.pdf",
                Format   = ExportTemplateTaskVMFormat.Pdf,
                FolderId = subscription.ExportsFolder.FolderId
            };
            var exportedFile = await templatesClient.ExportAsync(template.Id, eTaskVM);

            int attempts = 5;

            string fileId = exportedFile.Id;

            while (exportedFile.Status != ExportVMStatus.Success && attempts >= 0)
            {
                await Task.Delay(1000);

                exportedFile = exportsClient.GetFile(fileId);
                attempts--;
            }


            var fileStream = await downloadClient.GetExportAsync(fileId);

            using (MemoryStream ms = new MemoryStream())
            {
                fileStream.Stream.CopyTo(ms);
                return(new FileContentResult(ms.ToArray(), "application/octet-stream")
                {
                    FileDownloadName = "report.pdf"
                });
            }
        }
Пример #2
0
        public async Task <IActionResult> PrepareReport(IFormCollection forms)
        {
            var subscription = (await subscriptionsClient.GetSubscriptionsAsync(0, 1)).Subscriptions.First();
            var template     = await SendTemplateToCloud(subscription.TemplatesFolder.FolderId);

            var name = forms["ReportName"][0];
            var nums = forms["BarcodeNums"][0];

            Dictionary <string, object> parameters = new();

            parameters.Add("report_name", name);
            parameters.Add("barcode_nums", nums);



            ExportTemplateTaskVM eTaskVM = new()
            {
                FileName         = "songs.pdf",
                Format           = ExportTemplateTaskVMFormat.Pdf,
                ReportParameters = parameters,
                FolderId         = subscription.ExportsFolder.FolderId
            };
            var exportedFile = await templatesClient.ExportAsync(template.Id, eTaskVM);

            int attempts = 5;

            string fileId = exportedFile.Id;

            while (exportedFile.Status != ExportVMStatus.Success && attempts >= 0)
            {
                await Task.Delay(1000);

                exportedFile = exportsClient.GetFile(fileId);
                attempts--;
            }


            var fileStream = await downloadClient.GetExportAsync(fileId);

            using (MemoryStream ms = new MemoryStream())
            {
                fileStream.Stream.CopyTo(ms);
                return(new FileContentResult(ms.ToArray(), "application/octet-stream")
                {
                    FileDownloadName = "report.pdf"
                });
            }
        }