示例#1
0
        protected void Initialize(
            string assemblyName,
            string assemblyFileName,
            AssemblyBuilderAccess assemblyBuilderAccess)
        {
            if (assemblyName != null)
            {
                assemblyName = assemblyName.Trim();
            }
            if (string.IsNullOrEmpty(assemblyName))
            {
                throw new NullReferenceException(string.Format(
                                                     "{0} may not be null when constructing a {1}.",
                                                     EntityReaderGeneric <OrmAssemblyWindows> .GetPropertyName(p => p.AssemblyName, false),
                                                     this.GetType().FullName));
            }
            _assemblyName          = assemblyName;
            _assemblyFileName      = assemblyFileName;
            _assemblyBuilderAccess = assemblyBuilderAccess;
            _assemblyBuilder       = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(_assemblyName), _assemblyBuilderAccess);
            string domainName = AppDomain.CurrentDomain.FriendlyName;

            if (string.IsNullOrEmpty(_assemblyFileName))
            {
                _moduleBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName);
            }
            else
            {
                _moduleBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName, _assemblyFileName);
            }
            _ormTypes = new EntityCacheGeneric <string, OrmTypeWindows>();
        }
示例#2
0
 public DatabaseTableWindows(string tableName, string connectionString)
 {
     _columns          = new EntityCacheGeneric <string, DatabaseTableColumnWindows>();
     _tableName        = tableName;
     _connectionString = connectionString;
     _childrenTables   = new EntityCacheGeneric <string, EntityCacheGeneric <string, ForeignKeyInfoWindows> >();
 }
示例#3
0
        public virtual EntityCacheGeneric <string, DatabaseTableColumnWindows> GetForeignKeyColumns()
        {
            EntityCacheGeneric <string, DatabaseTableColumnWindows> result = new EntityCacheGeneric <string, DatabaseTableColumnWindows>();

            _columns.Where(c => c.IsForeignKey).ToList().ForEach(c => result.Add(c.ColumnName, c));
            return(result);
        }
 public override void Initialize(
     string connectionString,
     bool populateTablesFromSchema,
     bool createOrmAssembly,
     bool saveOrmAssembly,
     string ormAssemblyOutputDirectory,
     bool overrideNameWithDatabaseNameFromSchema)
 {
     _tables           = new EntityCacheGeneric <string, DatabaseTableWindows>();
     _connectionString = connectionString;
     using (SQLiteConnection connection = new SQLiteConnection(_connectionString))
     {
         PublishFeedback(string.Format("Opening connection to {0} ...", _connectionString));
         connection.Open();
         if (overrideNameWithDatabaseNameFromSchema)
         {
             PublishFeedback("Getting DB name from schema ...");
             _name = GetDatabaseNameFromSchema(connection, false);
         }
         if (populateTablesFromSchema)
         {
             PublishFeedback("Populating DB tables from schema ...");
             PopulateTablesFromSchema(true, connection, false);
         }
         if (createOrmAssembly)
         {
             PublishFeedback("Generating ORM assembly ...");
             CreateOrmAssembly(saveOrmAssembly, ormAssemblyOutputDirectory);
         }
     }
 }
示例#5
0
        public EntityCacheGeneric <string, SettingItem> GetAllSettingItems(string name)
        {
            Type settingsType = this.GetType();
            List <SettingItem> settingItems = new List <SettingItem>();

            foreach (PropertyInfo p in settingsType.GetProperties())
            {
                object[] categoryAttributes = p.GetCustomAttributes(typeof(SettingInfoAttribute), true);
                if (categoryAttributes == null)
                {
                    continue;
                }
                foreach (SettingInfoAttribute c in categoryAttributes)
                {
                    SettingItem settingItem = new SettingItem(
                        c.Category,
                        p.Name,
                        EntityReader.GetPropertyValue(p.Name, this, false),
                        p.PropertyType,
                        c.AutoFormatDisplayName,
                        c.DisplayName,
                        c.Description,
                        c.CategorySequenceId,
                        c.PasswordChar,
                        null,
                        new SettingsCategoryInfo(this, c.Category));
                    settingItems.Add(settingItem);
                }
            }
            string entityCacheName = string.IsNullOrEmpty(name) ? DataShaper.ShapeCamelCaseString(this.GetType().Name) : name;
            EntityCacheGeneric <string, SettingItem> result = new EntityCacheGeneric <string, SettingItem>(entityCacheName);

            settingItems.OrderBy(p => p.Category).ToList().ForEach(p => result.Add(p.SettingName, p));
            return(result);
        }
示例#6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="schemaRow">The DataRow retrieved from a database schema containing information about this column.</param>
 public DatabaseTableWindows(DataRow schemaRow, string connectionString)
 {
     _columns = new EntityCacheGeneric <string, DatabaseTableColumnWindows>();
     PopulateFromSchema(schemaRow);
     _connectionString = connectionString;
     _childrenTables   = new EntityCacheGeneric <string, EntityCacheGeneric <string, ForeignKeyInfoWindows> >();
 }
示例#7
0
 public void Clean()
 {
     _ormTypes.ToList().ForEach(p => p.Clean());
     _ormTypes.Clear();
     _ormTypes        = null;
     _moduleBuilder   = null;
     _assemblyBuilder = null;
 }
示例#8
0
        public EntityCacheGeneric <string, List <SettingItem> > GetAllSettingItemsGroupedByCategories()
        {
            EntityCacheGeneric <string, List <SettingItem> > result = new EntityCacheGeneric <string, List <SettingItem> >();

            foreach (var group in GetAllSettingItems().GroupBy(p => p.Category))
            {
                result.Add(group.Key, group.OrderBy(p => p.CategorySequenceId).ToList());
            }
            return(result);
        }
示例#9
0
        protected virtual FileContentResult GetCsvFileResult <E>(EntityCacheGeneric <Guid, E> cache) where E : class
        {
            string filePath = Path.GetTempFileName();

            cache.ExportToCsv(filePath, null, false, false);
            string downloadFileName = string.Format("{0}-{1}.csv", typeof(E).Name, DateTime.Now);

            byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
            System.IO.File.Delete(filePath);
            return(File(fileBytes, "text/plain", downloadFileName));
        }
 public SqliteDatabaseBaseWindows(string name, string connectionString)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(string.Format(
                                             "{0} not be null or empty when constructing {1}.",
                                             EntityReaderGeneric <SqliteDatabaseBaseWindows> .GetPropertyName(p => p.Name, false),
                                             this.GetType().FullName));
     }
     _tables           = new EntityCacheGeneric <string, SqliteDatabaseTableWindows> ();
     _name             = name;
     _connectionString = connectionString;
 }
示例#11
0
 private static EntityCacheGeneric<string, ForeignKeyInfoWindows> GetForeignKeysFromSqlDataReader(SqlDataReader reader)
 {
     EntityCacheGeneric<string, ForeignKeyInfoWindows> result = new EntityCacheGeneric<string, ForeignKeyInfoWindows>();
     while (reader.Read())
     {
         ForeignKeyInfoWindows f = new ForeignKeyInfoWindows()
         {
             ChildTableName = reader[FOREIGN_KEY_TABLE_COLUMN_NAME].ToString(),
             ChildTableForeignKeyName = reader[FOREIGN_KEY_COLUMN_NAME].ToString(),
             ParentTableName = reader[PRIMARY_KEY_TABLE_COLUMN_NAME].ToString(),
             ParentTablePrimaryKeyName = reader[PRIMARY_KEY_COLUMN_NAME].ToString(),
             ConstraintName = reader[CONSTRAINT_NAME_COLUMN_NAME].ToString()
         };
         result.Add(f.ChildTableForeignKeyName, f);
     }
     return result;
 }
 private void PopulateChildrenTables()
 {
     foreach (DatabaseTableWindows pkTable in _tables)
     {
         foreach (DatabaseTableWindows fkTable in _tables) //Find children tables i.e. tables that have foreign keys mapped this table's primary keys'.
         {
             EntityCacheGeneric <string, ForeignKeyInfoWindows> mappedForeignKeys = new EntityCacheGeneric <string, ForeignKeyInfoWindows>();
             fkTable.GetForeignKeyColumns().Where(c => c.ParentTableName == pkTable.TableName).ToList().ForEach(fk => mappedForeignKeys.Add(fk.ColumnName, new ForeignKeyInfoWindows()
             {
                 ChildTableName            = fkTable.TableName,
                 ChildTableForeignKeyName  = fk.ColumnName,
                 ParentTableName           = fk.ParentTableName,
                 ParentTablePrimaryKeyName = fk.ParentTablePrimaryKeyName,
                 ConstraintName            = fk.ConstraintName
             }));
             if (mappedForeignKeys.Count > 0) //If there are any foreign keys mapped to parent table's name.
             {
                 pkTable.ChildrenTables.Add(fkTable.TableName, mappedForeignKeys);
             }
         }
     }
 }
示例#13
0
        /// <summary>
        /// Queries all the settings in this class grouped by their categorires and writes the categories with each setting name and value to a string which can be logged or displayed.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();
            EntityCacheGeneric <string, List <SettingItem> > settings = GetAllSettingItemsGroupedByCategories();
            List <string> categories = settings.GetEntitiesKeys();

            for (int i = 0; i < categories.Count; i++)
            {
                string category = categories[i];
                result.AppendLine($"*** {category} Settings ***");
                result.AppendLine();
                foreach (SettingItem s in settings[category])
                {
                    result.AppendLine($" * {s.SettingDisplayName} : {s.SettingValue}");
                }
                if (i < (categories.Count - 1))
                {
                    result.AppendLine(); //There are more categories to go.
                }
            }
            return(result.ToString());
        }
示例#14
0
        public EntityCacheGeneric <string, SettingItem> GetSettingsByCategory(SettingsCategoryInfo settingsCategoryInfo, SettingsControlWindows settingsControl)
        {
            string             categoryLower = settingsCategoryInfo.Category.Trim().ToLower();
            Type               settingsType  = this.GetType();
            List <SettingItem> settingItems  = new List <SettingItem>();

            foreach (PropertyInfo p in settingsType.GetProperties())
            {
                object[] categoryAttributes = p.GetCustomAttributes(typeof(SettingInfoAttribute), true);
                if (categoryAttributes == null)
                {
                    continue;
                }
                foreach (SettingInfoAttribute c in categoryAttributes)
                {
                    if (c.Category.Trim().ToLower() == categoryLower)
                    {
                        SettingItem settingItem = new SettingItem(
                            c.Category,
                            p.Name,
                            EntityReader.GetPropertyValue(p.Name, this, false),
                            p.PropertyType,
                            c.AutoFormatDisplayName,
                            c.DisplayName,
                            c.Description,
                            c.CategorySequenceId,
                            c.PasswordChar,
                            settingsControl,
                            settingsCategoryInfo);
                        settingItems.Add(settingItem);
                    }
                }
            }
            string entityCacheName = string.Format("{0} {1} Settings", DataShaperWindows.ShapeCamelCaseString(settingsType.Name).Replace("Settings", "").Trim(), settingsCategoryInfo.Category);
            EntityCacheGeneric <string, SettingItem> result = new EntityCacheGeneric <string, SettingItem>(entityCacheName);

            settingItems.OrderBy(p => p.CategorySequenceId).ToList().ForEach(p => result.Add(p.SettingName, p));
            return(result);
        }
 public SqliteDatabaseBaseWindows(string connectionString)
 {
     _tables           = new EntityCacheGeneric <string, SqliteDatabaseTableWindows> ();
     _name             = this.GetType().Name;
     _connectionString = connectionString;
 }
示例#16
0
 public DatabaseWindows()
 {
     _tables = new EntityCacheGeneric <string, DatabaseTableWindows>();
     _name   = this.GetType().Name;
 }
 public override void PopulateColumnsFromSchema(DbConnection connection, bool disposeConnectionAfterExecute)
 {
     try
     {
         if (connection == null)
         {
             connection = new SQLiteConnection(_connectionString);
         }
         if (connection.State != ConnectionState.Open)
         {
             connection.Open();
         }
         _columns.Clear();
         DataTable schema = connection.GetSchema("Columns", new string[] { null, null, _tableName, null });
         List <DatabaseTableColumnWindows> tempColumns = new List <DatabaseTableColumnWindows>();
         foreach (DataRow row in schema.Rows)
         {
             tempColumns.Add(new SqliteDatabaseTableColumnWindows(row));
         }
         tempColumns.OrderBy(c => c.OrdinalPosition).ToList().ForEach(c => _columns.Add(c.ColumnName, c));
         if (!(connection is SQLiteConnection))
         {
             throw new InvalidCastException(string.Format(
                                                "Expected a {0}, and received a {1}.",
                                                typeof(SQLiteConnection).FullName,
                                                connection.GetType().FullName));
         }
         List <string> keyColumns = GetKeyColummnNames(connection, false);
         if (keyColumns.Count < 0)
         {
             throw new Exception(string.Format("Table {0} has no key columns.", _tableName));
         }
         foreach (string k in keyColumns)
         {
             DatabaseTableColumnWindows c = _columns[k];
             if (c == null)
             {
                 throw new NullReferenceException(string.Format(
                                                      "Could not find key column {0} on table {1}.",
                                                      k,
                                                      _tableName));
             }
             c.IsKey = true;
         }
         SQLiteConnection sqliteConnection = connection as SQLiteConnection;
         if (sqliteConnection == null)
         {
             throw new InvalidCastException(string.Format("Expected connection to be a {0} in {1}.", typeof(SQLiteConnection).FullName, this.GetType().FullName));
         }
         EntityCacheGeneric <string, ForeignKeyInfoWindows> foreignKeys = sqliteConnection.GetTableForeignKeys(_tableName);
         foreach (ForeignKeyInfoWindows f in foreignKeys)
         {
             if (_columns.Exists(f.ChildTableForeignKeyName))
             {
                 DatabaseTableColumnWindows c = _columns[f.ChildTableForeignKeyName];
                 c.IsForeignKey              = true;
                 c.ParentTableName           = f.ParentTableName;
                 c.ParentTablePrimaryKeyName = f.ParentTablePrimaryKeyName;
                 c.ConstraintName            = f.ConstraintName;
             }
         }
     }
     finally
     {
         if (disposeConnectionAfterExecute &&
             connection != null &&
             connection.State != ConnectionState.Closed)
         {
             connection.Dispose();
         }
     }
 }
示例#18
0
 public DatabaseTableWindows()
 {
     _columns        = new EntityCacheGeneric <string, DatabaseTableColumnWindows>();
     _tableName      = this.GetType().Name;
     _childrenTables = new EntityCacheGeneric <string, EntityCacheGeneric <string, ForeignKeyInfoWindows> >();
 }