UtilsController.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if DESIGNER
  2. using FastReport.Web.Services;
  3. using Microsoft.AspNetCore.Mvc;
  4. using System;
  5. using System.Net;
  6. using System.Threading.Tasks;
  7. using FastReport.Web.Infrastructure;
  8. using Microsoft.AspNetCore.Http;
  9. using System.Net.Mime;
  10. namespace FastReport.Web.Controllers
  11. {
  12. static partial class Controllers
  13. {
  14. [HttpGet("/designer.objects/mschart/template")]
  15. public static IResult GetMSChartTemplate(string name, IDesignerUtilsService designerUtilsService)
  16. {
  17. string response;
  18. try
  19. {
  20. response = designerUtilsService.GetMSChartTemplateXML(name);
  21. }
  22. catch (Exception ex)
  23. {
  24. return Results.NotFound();
  25. }
  26. return Results.Content(response, "application/xml");
  27. }
  28. [HttpGet("/designer.getComponentProperties")]
  29. public static IResult GetComponentProperties(string name, IDesignerUtilsService designerUtilsService)
  30. {
  31. var response = designerUtilsService.GetPropertiesJSON(name);
  32. return response.IsNullOrEmpty()
  33. ? Results.NotFound()
  34. : Results.Content(response, "application/json");
  35. }
  36. [HttpGet("/designer.getConfig")]
  37. public static IResult GetConfig(string reportId, IReportService reportService, IDesignerUtilsService designerUtilsService)
  38. {
  39. if (!reportService.TryFindWebReport(reportId, out var webReport))
  40. return Results.NotFound();
  41. var content = designerUtilsService.GetConfig(webReport);
  42. return Results.Content(content, "application/json");
  43. }
  44. [HttpGet("/designer.getFunctions")]
  45. public static IResult GetFunctions(string reportId,
  46. IReportService reportService,
  47. IDesignerUtilsService designerUtilsService)
  48. {
  49. if (!reportService.TryFindWebReport(reportId, out var webReport))
  50. return Results.NotFound();
  51. var buff = designerUtilsService.GetFunctions(webReport.Report);
  52. return Results.Content(buff, "application/xml");
  53. }
  54. [HttpPost("/designer.objects/preview")]
  55. public static async Task<IResult> GetDesignerObjectPreview(string reportId,
  56. IReportService reportService,
  57. IReportDesignerService reportDesignerService,
  58. IDesignerUtilsService designerUtilsService,
  59. HttpRequest request)
  60. {
  61. if (!reportService.TryFindWebReport(reportId, out var webReport))
  62. return Results.NotFound();
  63. try
  64. {
  65. var reportObj = await reportDesignerService.GetPOSTReportAsync(request.Body);
  66. var response = designerUtilsService.DesignerObjectPreview(webReport, reportObj);
  67. return Results.Content(response, MediaTypeNames.Text.Html);
  68. }
  69. catch (Exception ex)
  70. {
  71. var content = webReport.Debug ? ex.Message : "";
  72. return Results.BadRequest(content);
  73. }
  74. }
  75. }
  76. }
  77. #endif