public ServerManager() { if (Properties.Settings.Default.CallUpgrade) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.CallUpgrade = false; Properties.Settings.Default.Save(); } InitializeComponent(); mainPropertyGrid.PropertySort = PropertySort.Categorized; sourceHelper = new TreeViewEditorHelper() { sortColumnAlphaOrderToolStripMenuItem = sortColumnAlphaOrderToolStripMenuItem, sortColumnSQLOrderToolStripMenuItem = sortColumnSQLOrderToolStripMenuItem, addFromToolStripMenuItem = addFromToolStripMenuItem, addToolStripMenuItem = addToolStripMenuItem, removeToolStripMenuItem = removeToolStripMenuItem, copyToolStripMenuItem = copyToolStripMenuItem, removeRootToolStripMenuItem = removeRootToolStripMenuItem, treeContextMenuStrip = treeContextMenuStrip, mainTreeView = mainTreeView }; toolStripHelper = new ToolStripEditorHelper() { MainToolStrip = mainToolStrip, MainPropertyGrid = mainPropertyGrid, EntityHandler = this, MainTreeView = mainTreeView }; toolsHelper = new ToolsHelper() { EntityHandler = this }; toolsHelper.InitHelpers(toolsToolStripMenuItem, false); HelperEditor.HandlerInterface = this; configureMenuItem.Click += configureClick; configurationToolStripMenuItem.DropDownItems.Add(configureMenuItem); configurationToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator()); publishWebMenuItem.Click += configureClick; configurationToolStripMenuItem.DropDownItems.Add(publishWebMenuItem); configurationToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator()); securityMenuItem.Click += securityClick; configurationToolStripMenuItem.DropDownItems.Add(securityMenuItem); ShowIcon = true; Icon = Properties.Resources.serverManager; //Repository management, should be part of the installation _repository = Repository.Create(); if (_repository == null) { _repository = new Repository(); MessageBox.Show("No repository has been defined or found for this installation. Reports will not be rendered. Please modify the .configuration file to set a RepositoryPath containing at least a Views subfolder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //handle program args string[] args = Environment.GetCommandLineArgs(); bool open = (args.Length >= 2 && args[1].ToLower() == "/o"); string fileToOpen = null; if (args.Length >= 3 && File.Exists(args[2])) fileToOpen = args[2]; //and last used file if (!open && File.Exists(Properties.Settings.Default.LastUsedFile)) { open = true; fileToOpen = Properties.Settings.Default.LastUsedFile; } if (open && HasValidRepositoryDirectory(fileToOpen)) { openFile(fileToOpen); } else { IsModified = false; init(); } }
public static Report GetScheduledReport(TaskFolder taskFolder, string reportPath, string reportGUID, string scheduleGUID, Repository repository) { Report report = null; if (File.Exists(reportPath)) report = Report.LoadFromFile(reportPath, repository); if (!File.Exists(reportPath) || (report != null && report.GUID != reportGUID)) { //Report has been moved or renamed: search report from its GUID in the report folder report = repository.FindReport(repository.ReportsFolder, reportGUID); if (report == null) { //Remove the schedules of the report foreach (Task oldTask in taskFolder.GetTasks().Where(i => i.Definition.RegistrationInfo.Source.EndsWith(scheduleGUID))) { taskFolder.DeleteTask(oldTask.Name); } } } return report; }
void SynchronizeSchedules(ExecutionLogInterface log, string folder, Repository repository, ref int count, ref int errorCount, StringBuilder errorSummary, bool useCurrentUser) { log.Log("Checking folder '{0}'", folder); foreach (string reportPath in Directory.GetFiles(folder, "*." + Repository.SealReportFileExtension)) { try { if (log.IsJobCancelled()) return; count++; Report report = Report.LoadFromFile(reportPath, repository); report.SchedulesWithCurrentUser = useCurrentUser; if (report.Schedules.Count > 0) { log.Log("Synchronizing schedules for report '{0}'", reportPath); foreach (ReportSchedule schedule in report.Schedules) { if (log.IsJobCancelled()) return; log.Log("Checking schedule '{0}'", schedule.Name); try { Task task = schedule.FindTask(); if (task != null) schedule.SynchronizeTask(); else { log.Log("Creating task for '{0}'", schedule.Name); schedule.SynchronizeTask(); } } catch (Exception ex) { errorCount++; log.LogRaw("ERROR\r\n"); log.Log(ex.Message); errorSummary.AppendFormat("\r\nReport '{0}' Schedule '{1}': {2}\r\n", reportPath, schedule.Name, ex.Message); } } } } catch (Exception ex) { errorCount++; log.LogRaw("ERROR\r\n"); log.Log(ex.Message); errorSummary.AppendFormat("\r\nReport '{0}': {1}\r\n", reportPath, ex.Message); } } foreach (string subFolder in Directory.GetDirectories(folder)) { if (log.IsJobCancelled()) return; SynchronizeSchedules(log, subFolder, repository, ref count, ref errorCount, errorSummary, useCurrentUser); } log.LogRaw("\r\n"); }
void exportReportsTranslations(ExecutionLogInterface log, string folder, Repository repository, StringBuilder translations, string separator, string extraSeparators, int len) { foreach (string reportPath in Directory.GetFiles(folder, "*." + Repository.SealReportFileExtension)) { try { if (log.IsJobCancelled()) return; Report report = Report.LoadFromFile(reportPath, repository); translations.AppendFormat("ReportDisplayName{0}{1}{0}{2}{3}\r\n", separator, Helper.QuoteDouble(reportPath.Substring(len)), Helper.QuoteDouble(report.ExecutionName), extraSeparators); foreach (var view in report.Views) { exportViewsTranslations(log, view, repository, translations, reportPath, separator, extraSeparators, len); } foreach (var output in report.Outputs) { translations.AppendFormat("ReportOutputName{0}{1}{0}{2}{3}\r\n", separator, Helper.QuoteDouble(reportPath.Substring(len)), Helper.QuoteDouble(output.Name), extraSeparators); } } catch (Exception ex) { log.LogRaw("ERROR loading report {0}\r\n", reportPath); log.Log(ex.Message); } } foreach (string subFolder in Directory.GetDirectories(folder)) { if (log.IsJobCancelled()) return; exportReportsTranslations(log, subFolder, repository, translations, separator, extraSeparators, len); } }
public void AddDefaultConnection(Repository repository) { if (Connections.Count == 0) { //Add default connection MetaConnection connection = MetaConnection.Create(this); connection.ConnectionString = repository.Configuration.DefaultConnectionString; Connections.Add(connection); ConnectionGUID = connection.GUID; } }
//Same as create but we shared or clone properties for performance reasons... public Repository CreateFast() { //check if some files have changed, in this case -> full reload if (MustReload()) return Repository.Create(); //Fast load Repository result = null; string path = FindRepository(); if (Directory.Exists(path)) { result = new Repository(); //Just clone the sources as connections and enums can be updated result._sources = (List<MetaSource>)Helper.Clone(Sources); foreach (var source in result.Sources) source.InitReferences(result); //Others collections should remain static/unchanged an can be shared... result._translations = Translations; result._viewTemplates = ViewTemplates;// (List<ReportViewTemplate>)Helper.Clone(ViewTemplates);-> Note that Parameters of ViewTemplates are not cloned correctely result._themes = Themes; result._devices = Devices; result._configuration = Configuration; result._path = path; //plus defaults... result._cultureInfo = CultureInfo; } return result; }
public static Report LoadFromFile(string path, Repository repository) { Report result = null; try { StreamReader sr = new StreamReader(path); XmlSerializer serializer = new XmlSerializer(typeof(Report)); result = (Report)serializer.Deserialize(sr); result.FilePath = path; result.Repository = repository; sr.Close(); result.LastModification = File.GetLastWriteTime(path); result.LoadErrors = ""; foreach (ReportSource source in result.Sources) { source.Report = result; source.LoadRepositoryMetaSources(repository); } result.InitReferences(); //Refresh enums foreach (ReportSource source in result.Sources) source.RefreshEnumsOnDbConnection(); } catch (Exception ex) { throw new Exception(string.Format("Unable to read the file '{0}'.\r\n{1}", path, ex.Message)); } return result; }
private void ReportDesigner_Load(object sender, EventArgs e) { KeyPreview = true; //Set event handler for sub-property grids... EntityCollectionEditor.MyPropertyValueChanged += mainPropertyGrid_PropertyValueChanged; //handle program args string[] args = Environment.GetCommandLineArgs(); bool open = (args.Length >= 2 && args[1].ToLower() == "/o"); string reportToOpen = null; if (args.Length >= 3 && File.Exists(args[2])) reportToOpen = args[2]; //MRU = most recent used reports if (Properties.Settings.Default.MRU == null) Properties.Settings.Default.MRU = new System.Collections.Specialized.StringCollection(); if (!open && Properties.Settings.Default.MRU.Count > 0 && File.Exists(Properties.Settings.Default.MRU[0])) { open = true; reportToOpen = Properties.Settings.Default.MRU[0]; } showScriptErrorsToolStripMenuItem.Checked = Properties.Settings.Default.ShowScriptErrors; if (!Helper.IsMachineAdministrator()) Properties.Settings.Default.SchedulesWithCurrentUser = true; schedulesWithCurrentUserToolStripMenuItem.Checked = Properties.Settings.Default.SchedulesWithCurrentUser; if (open) { if (!string.IsNullOrEmpty(reportToOpen)) openReport(reportToOpen); else newToolStripMenuItem_Click(null, null); } else { _repository = Repository.Create(); IsModified = false; init(); } if (_repository == null) { _repository = new Repository(); MessageBox.Show("No repository has been defined or found for this installation. Reports will not be rendered. Please modify the .config file to set a RepositoryPath containing at least a Views subfolder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static Report Create(Repository repository) { Report result = new Report() { GUID = Guid.NewGuid().ToString() }; result.FilePath = "NewReport." + Repository.SealReportFileExtension; result.Repository = repository; foreach (MetaSource source in repository.Sources) { ReportSource reportSource = result.AddSource(source); } if (result.Sources.Count == 0) result.AddSource(null); foreach (ReportSource source in result.Sources) { source.LoadRepositoryMetaSources(repository); //Remove the connection added if (source.Connections.Count > 1) source.Connections.RemoveAll(i => i.IsEditable); //And master table added for NoSQL if (source.IsNoSQL && source.MetaData.Tables.Count > 1) source.MetaData.Tables.RemoveAll(i => i.IsEditable); } //and a first model if (result.Models.Count == 0) result.AddModel(); //Add default views ReportView defaultView = result.AddModelHTMLView(); result.ViewGUID = defaultView.GUID; result.AddModelCSVView(); return result; }
public void LoadRepositoryMetaSources(Repository repository) { foreach (var connection in Connections) { connection.IsEditable = true; } foreach (var table in MetaData.Tables) { table.IsEditable = true; } foreach (var join in MetaData.Joins) { join.IsEditable = true; } foreach (var itemEnum in MetaData.Enums) { itemEnum.IsEditable = true; } if (!string.IsNullOrEmpty(MetaSourceGUID)) { MetaSource source = repository.Sources.FirstOrDefault(i => i.GUID == MetaSourceGUID); if (source != null) { IsDefault = source.IsDefault; IsNoSQL = source.IsNoSQL; NumericFormat = source.NumericFormat; TasksScript = source.TasksScript; DateTimeFormat = source.DateTimeFormat; _metaSourceName = source.Name; foreach (var item in source.Connections) { item.IsEditable = false; Connections.Add(item); } foreach (var item in source.MetaData.Tables) { item.IsEditable = false; MetaData.Tables.Add(item); } foreach (var item in source.MetaData.Joins) { item.IsEditable = false; MetaData.Joins.Add(item); } foreach (var item in source.MetaData.Enums) { item.IsEditable = false; MetaData.Enums.Add(item); } PreSQL = source.PreSQL; PostSQL = source.PostSQL; IgnorePrePostError = source.IgnorePrePostError; } else { Report.LoadErrors += string.Format("Unable to find repository source for '{0}' (GUID {1}). Check the data source files in the repository folder.\r\n", Name, MetaSourceGUID); } } if (Connections.Count == 0) { Connections.Add(MetaConnection.Create(this)); ConnectionGUID = Connections[0].GUID; } }
static public ReportSource Create(Repository repository, bool createConnection) { ReportSource result = new ReportSource() { GUID = Guid.NewGuid().ToString(), Name = "Data Source", Repository = repository }; //Add master table MetaTable master = MetaTable.Create(); master.DynamicColumns = true; master.IsEditable = true; master.Alias = MetaData.MasterTableName; master.Source = result; result.MetaData.Tables.Add(master); if (createConnection) result.AddDefaultConnection(repository); return result; }
public static string RefreshEnums(string path, Repository repository) { string result = ""; return result; }
static public MetaSource LoadFromFile(string path, Repository repository) { MetaSource result = null; try { StreamReader sr = new StreamReader(path); XmlSerializer serializer = new XmlSerializer(typeof(MetaSource)); result = (MetaSource)serializer.Deserialize(sr); sr.Close(); result.Name = Path.GetFileNameWithoutExtension(path); result.FilePath = path; result.LastModification = File.GetLastWriteTime(path); result.InitReferences(repository); } catch (Exception ex) { throw new Exception(string.Format("Unable to read the file '{0}'.\r\n{1}", path, ex.Message)); } return result; }
static public MetaSource Create(Repository repository) { MetaSource result = new MetaSource() { GUID = Guid.NewGuid().ToString(), Name = "Data Source", Repository = repository }; result.AddDefaultConnection(repository); return result; }
private void openReport(string path) { //refresh repository _repository = Repository.Create(); _report = Report.LoadFromFile(path, _repository); if (_report != null) { addMRU(path); IsModified = false; init(); selectAfterLoad(); if (!string.IsNullOrEmpty(_report.LoadErrors)) { MessageBox.Show(string.Format("Error loading the report:\r\n{0}", _report.LoadErrors), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (!string.IsNullOrEmpty(_report.UpgradeWarnings)) { MessageBox.Show(_report.UpgradeWarnings, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close(); toolsHelper.Report = _report; _report.SchedulesWithCurrentUser = Properties.Settings.Default.SchedulesWithCurrentUser; }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; if (!checkModified()) return; if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close(); if (_repository == null || _repository.MustReload()) _repository = Repository.Create(); _report = Report.Create(_repository); IsModified = true; mainTreeView.SelectedNode = null; init(); selectAfterLoad(); toolsHelper.Report = _report; _report.SchedulesWithCurrentUser = Properties.Settings.Default.SchedulesWithCurrentUser; } finally { Cursor.Current = Cursors.Default; } }
public void ViewReport(Report report, Repository repository, bool render, string viewGUID, string outputGUID, string originalFilePath) { Show(); Text = Path.GetFileNameWithoutExtension(originalFilePath) + " - " + Repository.SealRootProductName + " Report Viewer"; BringToFront(); Report previousReport = _report; _report = report; _report.ExecutionContext = ReportExecutionContext.DesignerReport; if (string.IsNullOrEmpty(_report.DisplayName)) _report.DisplayName = Path.GetFileNameWithoutExtension(originalFilePath); _report.CurrentViewGUID = _report.ViewGUID; //execute to output if (!string.IsNullOrEmpty(outputGUID)) { _report.OutputToExecute = _report.Outputs.FirstOrDefault(i => i.GUID == outputGUID); _report.ExecutionContext = ReportExecutionContext.DesignerOutput; if (_report.OutputToExecute != null) _report.CurrentViewGUID = _report.OutputToExecute.ViewGUID; } //execute with custom view if (!string.IsNullOrEmpty(viewGUID)) _report.CurrentViewGUID = viewGUID; if (previousReport != null && render) { //force execution var parameter = _report.ExecutionView.Parameters.FirstOrDefault(i => i.Name == "force_execution"); if (parameter != null) parameter.BoolValue = true; //set previous data tables and restrictions foreach (var model in _report.Models) { ReportModel previousModel = previousReport.Models.FirstOrDefault(i => i.GUID == model.GUID); if (previousModel != null) { model.ResultTable = previousModel.ResultTable; model.Restrictions = previousModel.Restrictions; model.RestrictionText = previousModel.RestrictionText; model.Sql = previousModel.Sql; } } _report.RenderOnly = true; } _execution = new ReportExecution() { Report = _report }; _report.InitForExecution(); _execution.RenderHTMLDisplayForViewer(); _url = "file:///" + _report.HTMLDisplayFilePath; webBrowser.Navigate(_url); }
public static Report Create(Repository repository) { Report result = new Report() { GUID = Guid.NewGuid().ToString() }; result.FilePath = "NewReport." + Repository.SealReportFileExtension; result.Repository = repository; foreach (MetaSource source in repository.Sources) { ReportSource reportSource = result.AddSource(source); } if (result.Sources.Count == 0) result.AddSource(null); foreach (ReportSource source in result.Sources) { source.LoadRepositoryMetaSources(repository); //Remove the connection added if (source.Connections.Count > 1) source.Connections.RemoveAll(i => i.IsEditable); //And master table added for NoSQL if (source.IsNoSQL && source.MetaData.Tables.Count > 1) source.MetaData.Tables.RemoveAll(i => i.IsEditable); } //and a first model if (result.Models.Count == 0) result.AddModel(); //Add default views ReportView defaultView = result.AddModelHTMLView(); if (defaultView == null) throw new Exception(string.Format("Unable to find any view in your repository. Check that your repository folder '{0}' contains all the default sub-folders and files...", repository.RepositoryPath)); result.ViewGUID = defaultView.GUID; result.AddModelCSVView(); return result; }
void checkExecutions(ExecutionLogInterface log, string folder, Repository repository, ref int count, ref int errorCount, StringBuilder errorSummary) { log.Log("Checking folder '{0}'", folder); foreach (string reportPath in Directory.GetFiles(folder, "*." + Repository.SealReportFileExtension)) { try { if (log.IsJobCancelled()) return; log.Log("Checking report '{0}'", reportPath); count++; Report report = Report.LoadFromFile(reportPath, repository); report.CheckingExecution = true; if (report.Tasks.Count > 0) log.Log("Warning: Report Task executions are skipped."); foreach (ReportView view in report.Views) { if (log.IsJobCancelled()) return; log.Log("Running report with view '{0}'", view.Name); try { report.CurrentViewGUID = view.GUID; ReportExecution reportExecution = new ReportExecution() { Report = report }; reportExecution.Execute(); int cnt = 120; while (--cnt > 0 && report.IsExecuting && !log.IsJobCancelled()) { Thread.Sleep(1000); } if (report.IsExecuting) { if (cnt == 0) log.Log("Warning: Report is running for more than 2 minutes. Cancelling the execution..."); report.CancelExecution(); } if (!string.IsNullOrEmpty(report.ExecutionErrors)) throw new Exception(report.ExecutionErrors); if (!string.IsNullOrEmpty(report.ExecutionView.Error)) throw new Exception(report.ExecutionView.Error); report.RenderOnly = true; } catch (Exception ex) { errorCount++; log.LogRaw("ERROR\r\n"); log.Log(ex.Message); errorSummary.AppendFormat("\r\nReport '{0}' View '{1}': {2}\r\n", reportPath, view.Name, ex.Message); } } } catch (Exception ex) { errorCount++; log.LogRaw("ERROR\r\n"); log.Log(ex.Message); errorSummary.AppendFormat("\r\nReport '{0}': {1}\r\n", reportPath, ex.Message); } } log.LogRaw("\r\n"); foreach (string subFolder in Directory.GetDirectories(folder)) { if (log.IsJobCancelled()) return; checkExecutions(log, subFolder, repository, ref count, ref errorCount, errorSummary); } }
public static Repository Create() { Repository result = null; string path = FindRepository(); if (Directory.Exists(path)) { result = new Repository(); result.Init(path); } if (result == null) throw new Exception(string.Format("Unable to find or create a Repository from '{0}'. Please check your configuration file", Properties.Settings.Default.RepositoryPath)); return result; }
string initTranslationFile(StringBuilder translations, string separator, Repository repository) { translations.AppendFormat("Context{0}Instance{0}Reference", separator); //Add header string extraSeparators = ""; if (repository.Translations.Count > 0) { foreach (var lang in repository.Translations[0].Translations) { translations.AppendFormat("{0}{1}", separator, lang.Key); extraSeparators += separator; } } else { translations.AppendFormat("{0}en{0}fr", separator); extraSeparators += separator + separator; } translations.AppendLine(); return extraSeparators; }
void exportViewsTranslations(ExecutionLogInterface log, ReportView view, Repository repository, StringBuilder translations, string reportPath, string separator, string extraSeparators, int len) { translations.AppendFormat("ReportViewName{0}{1}{0}{2}{3}\r\n", separator, Helper.QuoteDouble(reportPath.Substring(len)), Helper.QuoteDouble(view.Name), extraSeparators); foreach (var child in view.Views) { exportViewsTranslations(log, child, repository, translations, reportPath, separator, extraSeparators, len); } }
public void InitReferences(Repository repository) { Repository = repository; //init references in objects foreach (var connection in Connections) { connection.Source = this; } foreach (var table in MetaData.Tables) { table.Source = this; foreach (var column in table.Columns) { column.Source = this; } } foreach (var join in MetaData.Joins) { join.Source = this; } foreach (var item in MetaData.Enums) { item.Source = this; } }