예제 #1
0
        /// <summary>
        /// Create a basic MetaSource
        /// </summary>
        static public MetaSource Create(Repository repository)
        {
            MetaSource result = new MetaSource()
            {
                GUID = Guid.NewGuid().ToString(), Name = "Data Source", Repository = repository
            };

            result.AddDefaultConnection(repository);
            return(result);
        }
예제 #2
0
        public bool CanSelectSource(MetaSource item)
        {
            var sourceName = item.Name;

            if (item is ReportSource)
            {
                sourceName = ((ReportSource)item).MetaSourceName;
            }
            return(!ForbiddenSources.Exists(i =>
                                            (string.IsNullOrEmpty(i.Name) || i.Name == sourceName)
                                            ));
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <summary>
        /// Load the MetaSource from a file
        /// </summary>
        static public MetaSource LoadFromFile(string path)
        {
            MetaSource result = null;

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(MetaSource));
                using (XmlReader xr = XmlReader.Create(path))
                {
                    result = (MetaSource)serializer.Deserialize(xr);
                }
                result.Name             = Path.GetFileNameWithoutExtension(path);
                result.FilePath         = path;
                result.LastModification = File.GetLastWriteTime(path);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Unable to read the file '{0}'.\r\n{1}", path, ex.Message));
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Init the repository from a given path
        /// </summary>
        public void Init(string path)
        {
            RepositoryPath = path;
            RepositoryServer.ViewsFolder          = ViewsFolder;
            RepositoryServer.TableTemplatesFolder = TableTemplatesFolder;

            CheckFolders();
            //Data sources
            if (Sources.Count == 0)
            {
                foreach (var file in Directory.GetFiles(SourcesFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        var source = MetaSource.LoadFromFile(file);
                        Sources.Add(source);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                foreach (var source in Sources)
                {
                    source.InitReferences(this);
                }
            }

            if (Devices.Count == 0)
            {
                //Devices, add a default folder device, then the other devices
                Devices.Add(OutputFolderDevice.Create());
                foreach (var file in Directory.GetFiles(DevicesEmailFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        Devices.Add(OutputEmailDevice.LoadFromFile(file, true));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
                foreach (var file in Directory.GetFiles(DevicesFileServerFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        Devices.Add(OutputFileServerDevice.LoadFromFile(file, true));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }

            if (!_assembliesLoaded)
            {
                //Load extra assemblies defined in Repository
                var assemblies = Directory.GetFiles(AssembliesFolder, "*.dll");
                foreach (var assembly in assemblies)
                {
                    try
                    {
                        Assembly.LoadFrom(assembly);
                    }
                    catch (Exception Exception)
                    {
                        Debug.WriteLine(Exception.Message);
                    }
                }

                //Add this assembly resolve necessary when executing Razor scripts
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);

                _assembliesLoaded = true;
            }
        }
예제 #6
0
        private void openFile(string path)
        {
            bool openOK = true;
            if (Path.GetDirectoryName(path).ToLower() == _repository.SourcesFolder.ToLower())
            {
                _source = MetaSource.LoadFromFile(path, _repository);
                _device = null;
            }
            else if (Path.GetDirectoryName(path).ToLower() == _repository.DevicesEmailFolder.ToLower())
            {
                _source = null;
                _device = OutputEmailDevice.LoadFromFile(path, false);
            }
            else
            {
                openOK = false;
                MessageBox.Show("The configuration file must be in a repository folder.\r\nA sub-folder of " + _repository.RepositoryPath, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (openOK)
            {
                Properties.Settings.Default.LastUsedFile = path;
            }
            IsModified = false;
            init();
        }
예제 #7
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!checkModified()) return;

            _source = null;
            _device = null;

            object entityToSelect = null;

            if (sender == dataSourceToolStripMenuItem || sender == noSQLdataSourceToolStripMenuItem)
            {
                _source = MetaSource.Create(_repository);
                _source.IsNoSQL = sender == noSQLdataSourceToolStripMenuItem;
                if (_source.IsNoSQL)
                {
                    //Add master table
                    MetaTable master = MetaTable.Create();
                    master.DynamicColumns = true;
                    master.IsEditable = true;
                    master.Alias = MetaData.MasterTableName;
                    master.Source = _source;
                    _source.MetaData.Tables.Add(master);
                    entityToSelect = master;
                }
                else
                {
                    entityToSelect = _source.Connection;
                }
            }
            else if (sender == emailOutputDeviceToolStripMenuItem)
            {
                _device = OutputEmailDevice.Create();
            }
            IsModified = true;
            init(entityToSelect);
        }
예제 #8
0
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!checkModified()) return;
     _source = null;
     _device = null;
     IsModified = false;
     toolStripHelper.SetHelperButtons(null);
     init();
 }
예제 #9
0
 public ReportSource AddSource(MetaSource source)
 {
     ReportSource result = ReportSource.Create(Repository, (source == null));
     result.Report = this;
     if (source != null)
     {
         result.ConnectionGUID = ReportSource.DefaultRepositoryConnectionGUID;
         result.MetaSourceGUID = source.GUID;
         result.Name = source.Name + " (Repository)";
     }
     result.Name = Helper.GetUniqueName(result.Name, (from i in Sources select i.Name).ToList());
     Sources.Add(result);
     return result;
 }
예제 #10
0
 static public MetaSource Create(Repository repository)
 {
     MetaSource result = new MetaSource() { GUID = Guid.NewGuid().ToString(), Name = "Data Source", Repository = repository };
     result.AddDefaultConnection(repository);
     return result;
 }
예제 #11
0
 void addSchemaTables(DataTable schemaTables, List<MetaTable> tables, MetaSource source)
 {
     //Helper.DisplayDataTable(schemaTables);
     foreach (DataRow row in schemaTables.Rows)
     {
         //if (row["TABLE_TYPE"].ToString() == "SYSTEM TABLE" || row["TABLE_TYPE"].ToString() == "SYSTEM VIEW") continue;
         MetaTable table = MetaTable.Create();
         string schema = "";
         if (schemaTables.Columns.Contains("TABLE_SCHEMA")) schema = row["TABLE_SCHEMA"].ToString();
         else if (schemaTables.Columns.Contains("TABLE_SCHEM")) schema = row["TABLE_SCHEM"].ToString();
         table.Name = (!string.IsNullOrEmpty(schema) ? source.GetTableName(schema) + "." : "") + source.GetTableName(row["TABLE_NAME"].ToString());
         table.Type = row["TABLE_TYPE"].ToString();
         table.Source = source;
         tables.Add(table);
     }
 }
예제 #12
0
        List<MetaJoin> GetJoins(DbConnection connection, MetaSource source)
        {
            List<MetaJoin> joins = new List<MetaJoin>();
            if (!(connection is OleDbConnection)) return joins;
            DataTable schemaTables = ((OleDbConnection)connection).GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, null);

            foreach (DataRow row in schemaTables.Rows)
            {
                string table1Name = source.GetTableName(row["PK_TABLE_NAME"].ToString());
                string table2Name = source.GetTableName(row["FK_TABLE_NAME"].ToString());
                MetaTable table1 = source.MetaData.Tables.FirstOrDefault(i => i.Name == source.GetTableName(table1Name));
                MetaTable table2 = source.MetaData.Tables.FirstOrDefault(i => i.Name == source.GetTableName(table2Name));

                if (table1 == null)
                {
                    string pkschema = "";
                    if (schemaTables.Columns.Contains("PK_TABLE_SCHEMA")) pkschema = row["PK_TABLE_SCHEMA"].ToString();
                    else if (schemaTables.Columns.Contains("PK_TABLE_SCHEM")) pkschema = row["PK_TABLE_SCHEM"].ToString();
                    if (!string.IsNullOrEmpty(pkschema)) table1 = source.MetaData.Tables.FirstOrDefault(i => i.Name == pkschema + "." + table1Name);
                }

                if (table2 == null)
                {
                    string fkschema = "";
                    if (schemaTables.Columns.Contains("FK_TABLE_SCHEMA")) fkschema = row["FK_TABLE_SCHEMA"].ToString();
                    else if (schemaTables.Columns.Contains("FK_TABLE_SCHEM")) fkschema = row["FK_TABLE_SCHEM"].ToString();
                    if (!string.IsNullOrEmpty(fkschema)) table2 = source.MetaData.Tables.FirstOrDefault(i => i.Name == fkschema + "." + table2Name);
                }

                if (table1 != null && table2 != null && table1.Name != table2.Name && !source.MetaData.Joins.Exists(i => i.LeftTableGUID == table1.GUID && i.RightTableGUID == table2.GUID))
                {
                    MetaJoin join = joins.FirstOrDefault(i => i.LeftTableGUID == table1.GUID && i.RightTableGUID == table2.GUID);
                    if (join == null)
                    {
                        join = MetaJoin.Create();
                        join.Name = table1.Name + " - " + table2.Name;
                        join.LeftTableGUID = table1.GUID;
                        join.RightTableGUID = table2.GUID;
                        join.Source = source;
                        joins.Add(join);
                    }

                    if (!string.IsNullOrEmpty(join.Clause)) join.Clause += " AND ";
                    join.Clause += string.Format("{0}.{1} = {2}.{3}\r\n", table1.Name, source.GetColumnName(row["PK_COLUMN_NAME"].ToString()), table2.Name, source.GetColumnName(row["FK_COLUMN_NAME"].ToString()));
                    join.JoinType = JoinType.Inner;
                }
            }
            return joins;
        }
예제 #13
0
        public void addSource(TreeNodeCollection nodes, MetaSource source, int noSQLIndex)
        {
            int index = source.IsNoSQL ? noSQLIndex : 0;
            TreeNode mainTN = new TreeNode() { Tag = source, Text = source.Name, ImageIndex = index, SelectedImageIndex = index };
            nodes.Add(mainTN);

            TreeNode sourceConnectionTN = new TreeNode("Connections") { Tag = source.ConnectionFolder, ImageIndex = 2, SelectedImageIndex = 2 };
            mainTN.Nodes.Add(sourceConnectionTN);
            foreach (var item in source.Connections.OrderByDescending(i => i.IsEditable).ThenBy(i => i.Name))
            {
                TreeNode tn = new TreeNode(item.Name + (!item.IsEditable ? " (Repository)" : "")) { Tag = item, ImageIndex = 1, SelectedImageIndex = 1 };
                sourceConnectionTN.Nodes.Add(tn);
            }
            if (!ForReport) sourceConnectionTN.ExpandAll();

            TreeNode sourceTableTN = new TreeNode("Tables") { Tag = source.TableFolder, ImageIndex = 2, SelectedImageIndex = 2 };
            mainTN.Nodes.Add(sourceTableTN);
            foreach (var table in source.MetaData.Tables.OrderByDescending(i => i.IsEditable).ThenBy(i => i.AliasName))
            {
                TreeNode tableTN = new TreeNode(table.AliasName + (!table.IsEditable ? " (Repository)" : "")) { Tag = table, ImageIndex = 4, SelectedImageIndex = 4 };
                sourceTableTN.Nodes.Add(tableTN);

                //Add elements
                foreach (var column in table.Columns.OrderBy(i => i.DisplayOrder))
                {
                    TreeNode columnTN = new TreeNode(column.DisplayName) { Tag = column, ImageIndex = 7, SelectedImageIndex = 7 };
                    tableTN.Nodes.Add(columnTN);
                }
            }
            sourceTableTN.Expand();

            //Columns by category
            TreeNode categoryTN = new TreeNode("Columns by categories") { Tag = source.CategoryFolder, ImageIndex = 2, SelectedImageIndex = 2 };
            sourceTableTN.Nodes.Add(categoryTN);
            TreeViewHelper.InitCategoryTreeNode(categoryTN.Nodes, source.MetaData.Tables);
            categoryTN.Expand();

            if (!source.IsNoSQL)
            {
                TreeNode sourceJoinTN = new TreeNode("Joins") { Tag = source.JoinFolder, ImageIndex = 2, SelectedImageIndex = 2 };
                mainTN.Nodes.Add(sourceJoinTN);
                foreach (var item in source.MetaData.Joins.OrderByDescending(i => i.IsEditable).ThenBy(i => i.Name))
                {
                    TreeNode tn = new TreeNode(item.Name + (!item.IsEditable ? " (Repository)" : "")) { Tag = item, ImageIndex = 5, SelectedImageIndex = 5 };
                    sourceJoinTN.Nodes.Add(tn);
                }
                if (!ForReport) sourceJoinTN.ExpandAll();
            }

            TreeNode sourceEnumTN = new TreeNode("Enumerated Lists") { Tag = source.EnumFolder, ImageIndex = 2, SelectedImageIndex = 2 };
            mainTN.Nodes.Add(sourceEnumTN);
            foreach (var item in source.MetaData.Enums.OrderByDescending(i => i.IsEditable).ThenBy(i => i.Name))
            {
                TreeNode tn = new TreeNode(item.Name + (!item.IsEditable ? " (Repository)" : "")) { Tag = item, ImageIndex = 6, SelectedImageIndex = 6 };
                sourceEnumTN.Nodes.Add(tn);
            }
            if (!ForReport) sourceEnumTN.ExpandAll();

            mainTreeView.TreeViewNodeSorter = new NodeSorter();
        }
예제 #14
0
 public static MetaConnection Create(MetaSource source)
 {
     return new MetaConnection() { Name = "connection", GUID = Guid.NewGuid().ToString(), Source = source };
 }
예제 #15
0
 public void SetSourceReference(MetaSource source)
 {
     _metaColumn = null;
     _source = source;
 }
예제 #16
0
        /// <summary>
        /// Load the available MetaSources defined in the repository
        /// </summary>
        public void LoadRepositoryMetaSources(Repository repository)
        {
            if (Loaded)
            {
                return;
            }

            foreach (var connection in Connections)
            {
                connection.IsEditable = true;
            }
            foreach (var table in MetaData.Tables)
            {
                table.IsEditable = true;
            }
            foreach (var link in MetaData.TableLinks)
            {
                link.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;
                    InitScript      = source.InitScript;
                    _metaSourceName = source.Name;
                    foreach (var item in source.Connections)
                    {
                        item.Source     = source;
                        item.IsEditable = false;
                        Connections.Add(item);
                    }
                    foreach (var item in source.MetaData.Tables)
                    {
                        item.Source     = source;
                        item.IsEditable = false;
                        MetaData.Tables.Add(item);
                    }
                    foreach (var item in source.MetaData.TableLinks)
                    {
                        item.IsEditable = false;
                        MetaData.TableLinks.Add(item);
                    }
                    foreach (var item in source.MetaData.Joins)
                    {
                        item.Source     = source;
                        item.IsEditable = false;
                        MetaData.Joins.Add(item);
                    }
                    foreach (var item in source.MetaData.Enums)
                    {
                        item.Source     = source;
                        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;
            }

            Loaded = true;
        }
예제 #17
0
 public void SetSourceReference(MetaSource source)
 {
     _metaColumn = null;
     _source     = source;
 }
예제 #18
0
        public void Init(string path)
        {
            _path = path;
            CheckFolders();
            //Data sources
            if (_sources.Count == 0)
            {
                foreach (var file in Directory.GetFiles(SourcesFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        var source = MetaSource.LoadFromFile(file, this);
                        _sources.Add(source);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }
            }

            if (_devices.Count == 0)
            {
                //Devices, add a default folder device, then the other devices
                _devices.Add(new OutputFolderDevice()
                {
                    Name = "Folder Device"
                });
                foreach (var file in Directory.GetFiles(DevicesEmailFolder, "*." + SealConfigurationFileExtension))
                {
                    try
                    {
                        var device = OutputEmailDevice.LoadFromFile(file, true);
                        _devices.Add(device);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }
            }

            if (!_assembliesLoaded)
            {
                //Load extra assemblies defined in Repository
                var assemblies = Directory.GetFiles(AssembliesFolder, "*.dll");
                foreach (var assembly in assemblies)
                {
                    try
                    {
                        Assembly.LoadFrom(assembly);
                    }
                    catch (Exception Exception)
                    {
                        Debug.WriteLine(Exception.Message);
                    }
                }

                //Add this assembly resolve necessary when executing Razor scripts
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);

                _assembliesLoaded = true;
            }
        }