FRCloudCommandManagers.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using FastReport.Cloud.FastReport.Models.DataSource;
  2. using FastReport.Cloud.FastReport.Models;
  3. using System.Net;
  4. using System.Windows.Forms;
  5. using System;
  6. using FastReport.Design;
  7. using FastReport.Utils;
  8. using FastReport.Cloud.FastReport.ListViewCloud;
  9. namespace FastReport.Cloud.FastReport
  10. {
  11. internal static class FileManager
  12. {
  13. public static FileVM CreateFileCommand(string folderId, FileCreateVM file)
  14. {
  15. return ProviderManager.FilesProvider.Create(folderId,
  16. file);
  17. }
  18. public static FilesVM GetFolderAndFilesCommand(string folderId, SearchOptions options = null)
  19. {
  20. return ProviderManager.FilesProvider.GetFoldersAndFiles(folderId, options);
  21. }
  22. public static FileResponse DownloadFileCommand(string id)
  23. {
  24. return ProviderManager.FilesProvider.Download(id);
  25. }
  26. public static FileVM RenameCommand(FileVM folderOrFile, RenameVM newName)
  27. {
  28. return ProviderManager.FilesProvider.Rename(folderOrFile, newName);
  29. }
  30. public static void DeleteCommand(FileVM file)
  31. {
  32. ProviderManager.FilesProvider.Delete(file);
  33. }
  34. public static FileVM CreateFolderCommand(string currentFolderId, FolderCreateVM newFile)
  35. {
  36. return ProviderManager.FilesProvider.CreateFolder(currentFolderId, newFile);
  37. }
  38. public static bool ResaveCommand(Report report)
  39. {
  40. var cloudFileInfo = report.CloudFileInfo;
  41. var res = new MyRes("Forms,ListViewForm");
  42. bool isNotFound = false;
  43. FileVM toCheckReport = new FileVM();
  44. try
  45. {
  46. toCheckReport = GetFileCommand(cloudFileInfo.FileId);
  47. }
  48. catch (WebException)
  49. {
  50. isNotFound = true;
  51. }
  52. if (isNotFound)
  53. {
  54. if (MessageBox.Show(res.Get("ReportWasNotFound"), res.Get("ReportWasNotFoundCaption"),
  55. MessageBoxButtons.YesNo) == DialogResult.Yes)
  56. {
  57. // TODO: what if the folder was deleted too?
  58. var created = CreateFileCommand(cloudFileInfo.FolderId,
  59. new TemplateCreateVM()
  60. {
  61. Name = cloudFileInfo.FileName,
  62. Report = report
  63. });
  64. // update report.CloudFileInfo
  65. report.CloudFileInfo = new CloudFileInfo(created);
  66. return true;
  67. }
  68. else
  69. return false;
  70. }
  71. if (DateTime.Compare(toCheckReport.EditedTime, cloudFileInfo.EditedTime + TimeSpan.FromSeconds(1)) > 0) // delta must be at least 1 sec because otherwise date time is not compared correctly
  72. {
  73. if (MessageBox.Show(res.Get("ReportWasModified"), res.Get("ReportWasModifiedCaption"),
  74. MessageBoxButtons.YesNo) == DialogResult.No)
  75. return false;
  76. }
  77. ProviderManager.FilesProvider.Resave(cloudFileInfo.FileId, new TemplateCreateVM() { Report = report });
  78. // update report.CloudFileInfo EditedTime (otherwise if we resave report twice we'll get warning)
  79. toCheckReport = GetFileCommand(cloudFileInfo.FileId);
  80. report.CloudFileInfo = new CloudFileInfo(toCheckReport);
  81. return true;
  82. }
  83. public static FileVM GetFileCommand(string id)
  84. {
  85. return ProviderManager.FilesProvider.GetFile(id);
  86. }
  87. }
  88. internal static class DataSourceManager
  89. {
  90. public static DataSourceVM CreateDataSourceCommand(CreateDataSourceVM dataSource)
  91. {
  92. return ProviderManager.DataSourcesProvider.CreateDataSource(dataSource);
  93. }
  94. public static DataSourceVM GetDataSourceCommand(string id)
  95. {
  96. return ProviderManager.DataSourcesProvider.GetDataSource(id);
  97. }
  98. public static DataSourcesVM GetAvailableDataSourcesCommand(DataSourcesOptions options)
  99. {
  100. return ProviderManager.DataSourcesProvider.GetAvailableDataSources(options);
  101. }
  102. public static void FetchDataCommand(string id)
  103. {
  104. ProviderManager.DataSourcesProvider.FetchData(id);
  105. }
  106. public static void UpdateDataSourceSubscriptionCommand(string id, UpdateDataSourceSubcriptionVM model)
  107. {
  108. ProviderManager.DataSourcesProvider.UpdateSubscriptionDataSource(id, model);
  109. }
  110. public static void RenameDataSourceCommand(string id, RenameDataSourceVM model)
  111. {
  112. ProviderManager.DataSourcesProvider.RenameDataSource(id, model);
  113. }
  114. public static void UpdateConnectionStringCommand(string id, UpdateDataSourceConnectionStringVM model)
  115. {
  116. ProviderManager.DataSourcesProvider.UpdateConnectionString(id, model);
  117. }
  118. }
  119. }