public async Task TemplatesClient_List_With_Filter() { var connection = new Mock <IConnection>(); connection.Setup(c => c.Get <IList <Template> >(ApiUrls.TemplatesList(), It.IsAny <IDictionary <string, string> >())) .ReturnsAsync(() => { var json = System.IO.File.ReadAllText("./Fixtures/Templates_ListTemplates.json"); return(JsonConvert.DeserializeObject <IList <Template> >(json)); }); var templateClient = new TemplatesClient(connection.Object); var result = await templateClient.List(new TemplateFilter() { Id = "1234", Label = "Windows 10", OS = "Windows 10 (Server 2019) - Licensed", Region = "", Name = "paperspace/tk9izniv", DTCreated = new System.DateTime(), UserId = "12345", TeamId = "12354" }); Assert.AreEqual(14, result.Count); }
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); } } }
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); }
public async Task TemplatesClient_List_HappyPath() { var connection = new Mock <IConnection>(); connection.Setup(c => c.Get <IList <Template> >(ApiUrls.TemplatesList(), null)) .ReturnsAsync(() => { var json = System.IO.File.ReadAllText("./Fixtures/Templates_ListTemplates.json"); return(JsonConvert.DeserializeObject <IList <Template> >(json)); }); var templateClient = new TemplatesClient(connection.Object); var result = await templateClient.List(); Assert.AreEqual(14, result.Count); }
public async Task MachinesClient_Create_HappyPath() { var connection = new Mock <IConnection>(); connection.Setup(c => c.Post <Machine>(ApiUrls.MachinesCreate(), null, It.IsAny <CreateMachineRequest>(), null, null)) .ReturnsAsync(() => { var json = System.IO.File.ReadAllText("./Fixtures/Machines_CreateMachine.json"); return(JsonConvert.DeserializeObject <Machine>(json)); }); connection.Setup(c => c.Get <IList <Template> >(ApiUrls.TemplatesList(), null)) .ReturnsAsync(() => { var json = System.IO.File.ReadAllText("./Fixtures/Templates_ListTemplates.json"); return(JsonConvert.DeserializeObject <IList <Template> >(json)); }); var templateClient = new TemplatesClient(connection.Object); var templates = await templateClient.List(); var template = templates.FirstOrDefault(t => t.OS == "Windows 10 (Server 2016) - Licensed"); var machinesClient = new MachinesClient(connection.Object); var result = await machinesClient.Create(new CreateMachineRequest() { Region = Region.EastCoast_NY2, MachineType = MachineType.Air, Size = 50, BillingType = BillingType.Hourly, MachineName = "My Machine 1", TemplateId = template.Id, }); Assert.AreEqual(result.Id, "pslwpsvsx"); }
public TemplatesController(ICommandBus commandBus, TemplatesClient templatesClient) : base(commandBus) { this.templatesClient = templatesClient; }