123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using FastReport.Cloud.FastReport.Models.DataSource;
- using FastReport.Cloud.FastReport.Models;
- using System.Net;
- using System.Windows.Forms;
- using System;
- using FastReport.Design;
- using FastReport.Utils;
- using FastReport.Cloud.FastReport.ListViewCloud;
- namespace FastReport.Cloud.FastReport
- {
- internal static class FileManager
- {
- public static FileVM CreateFileCommand(string folderId, FileCreateVM file)
- {
- return ProviderManager.FilesProvider.Create(folderId,
- file);
- }
- public static FilesVM GetFolderAndFilesCommand(string folderId, SearchOptions options = null)
- {
- return ProviderManager.FilesProvider.GetFoldersAndFiles(folderId, options);
- }
- public static FileResponse DownloadFileCommand(string id)
- {
- return ProviderManager.FilesProvider.Download(id);
- }
- public static FileVM RenameCommand(FileVM folderOrFile, RenameVM newName)
- {
- return ProviderManager.FilesProvider.Rename(folderOrFile, newName);
- }
- public static void DeleteCommand(FileVM file)
- {
- ProviderManager.FilesProvider.Delete(file);
- }
- public static FileVM CreateFolderCommand(string currentFolderId, FolderCreateVM newFile)
- {
- return ProviderManager.FilesProvider.CreateFolder(currentFolderId, newFile);
- }
- public static bool ResaveCommand(Report report)
- {
- var cloudFileInfo = report.CloudFileInfo;
- var res = new MyRes("Forms,ListViewForm");
- bool isNotFound = false;
- FileVM toCheckReport = new FileVM();
- try
- {
- toCheckReport = GetFileCommand(cloudFileInfo.FileId);
- }
- catch (WebException)
- {
- isNotFound = true;
- }
- if (isNotFound)
- {
- if (MessageBox.Show(res.Get("ReportWasNotFound"), res.Get("ReportWasNotFoundCaption"),
- MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- // TODO: what if the folder was deleted too?
- var created = CreateFileCommand(cloudFileInfo.FolderId,
- new TemplateCreateVM()
- {
- Name = cloudFileInfo.FileName,
- Report = report
- });
- // update report.CloudFileInfo
- report.CloudFileInfo = new CloudFileInfo(created);
- return true;
- }
- else
- return false;
- }
- 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
- {
- if (MessageBox.Show(res.Get("ReportWasModified"), res.Get("ReportWasModifiedCaption"),
- MessageBoxButtons.YesNo) == DialogResult.No)
- return false;
- }
- ProviderManager.FilesProvider.Resave(cloudFileInfo.FileId, new TemplateCreateVM() { Report = report });
- // update report.CloudFileInfo EditedTime (otherwise if we resave report twice we'll get warning)
- toCheckReport = GetFileCommand(cloudFileInfo.FileId);
- report.CloudFileInfo = new CloudFileInfo(toCheckReport);
- return true;
- }
- public static FileVM GetFileCommand(string id)
- {
- return ProviderManager.FilesProvider.GetFile(id);
- }
- }
- internal static class DataSourceManager
- {
- public static DataSourceVM CreateDataSourceCommand(CreateDataSourceVM dataSource)
- {
- return ProviderManager.DataSourcesProvider.CreateDataSource(dataSource);
- }
- public static DataSourceVM GetDataSourceCommand(string id)
- {
- return ProviderManager.DataSourcesProvider.GetDataSource(id);
- }
- public static DataSourcesVM GetAvailableDataSourcesCommand(DataSourcesOptions options)
- {
- return ProviderManager.DataSourcesProvider.GetAvailableDataSources(options);
- }
- public static void FetchDataCommand(string id)
- {
- ProviderManager.DataSourcesProvider.FetchData(id);
- }
- public static void UpdateDataSourceSubscriptionCommand(string id, UpdateDataSourceSubcriptionVM model)
- {
- ProviderManager.DataSourcesProvider.UpdateSubscriptionDataSource(id, model);
- }
- public static void RenameDataSourceCommand(string id, RenameDataSourceVM model)
- {
- ProviderManager.DataSourcesProvider.RenameDataSource(id, model);
- }
- public static void UpdateConnectionStringCommand(string id, UpdateDataSourceConnectionStringVM model)
- {
- ProviderManager.DataSourcesProvider.UpdateConnectionString(id, model);
- }
- }
- }
|