Пример #1
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri("https://fastreport.cloud");
            httpClient.DefaultRequestHeaders.Authorization = new FastReportCloudApiKeyHeader(ApiKey);
            var subscriptions = new SubscriptionsClient(httpClient);

            var rpClientTemplates = new TemplatesClient(httpClient);
            var rpClientExports   = new ExportsClient(httpClient);
            var downloadClient    = new DownloadClient(httpClient);

            var subscription = (await subscriptions.GetSubscriptionsAsync(0, 10)).Subscriptions.First();

            var templateFolder = subscription.TemplatesFolder.FolderId;
            var exportFolder   = subscription.ExportsFolder.FolderId;

            TemplateCreateVM templateCreateVM = new TemplateCreateVM()
            {
                Name    = "box.frx",
                Content = TestData.BoxReport
            };

            TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM);

            ExportTemplateTaskVM export = new ExportTemplateTaskVM()
            {
                FileName = "box.pdf",
                FolderId = exportFolder,
                Format   = ExportTemplateTaskVMFormat.Pdf
            };
            ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM;

            string fileId   = exportedFile.Id;
            int    attempts = 3;

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

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



            using (var file = await downloadClient.GetExportAsync(fileId))
            {
                using (var pdf = File.Open("report.pdf", FileMode.Create))
                {
                    file.Stream.CopyTo(pdf);
                }
            }
        }
Пример #2
0
        public async Task DOCX(string filepath, long?userId)
        {
            var rpClientTemplates = new TemplatesClient(httpClient);
            var rpClientExports   = new ExportsClient(httpClient);
            var downloadClient    = new DownloadClient(httpClient);


            var templateFolder = subscription.TemplatesFolder.FolderId;
            var exportFolder   = subscription.ExportsFolder.FolderId;

            TemplateCreateVM templateCreateVM = new TemplateCreateVM()
            {
                Name    = "box.frx",
                Content = Convert.ToBase64String(File.ReadAllBytes(filepath))
            };

            TemplateVM uploadedFile = await rpClientTemplates.UploadFileAsync(templateFolder, templateCreateVM);

            ExportTemplateTaskVM export = new ExportTemplateTaskVM()
            {
                FileName = "box.docx",
                FolderId = exportFolder,
                Format   = ExportTemplateTaskVMFormat.Docx
            };
            ExportVM exportedFile = await rpClientTemplates.ExportAsync(uploadedFile.Id, export) as ExportVM;

            string fileId   = exportedFile.Id;
            int    attempts = 3;

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

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


            using (var file = await downloadClient.GetExportAsync(fileId))
            {
                using (var pdf = File.Open("report.docx", FileMode.Create))
                {
                    file.Stream.CopyTo(pdf);
                }
                using (var stream = File.Open("report.docx", FileMode.Open))
                {
                    await Program.tgBot.SendDocumentAsync(userId, new InputOnlineFile(stream, "report.docx"));
                }
            }
            //await Program.tgBot.SendDocumentAsync(userId, name);
        }