public EntityGenerator(GenerateOption option)
        {
            this._option = option;
            Logger.Level = option.LoggerLevel;

            // 硬编码;也可以将数据库实现分离到单独的程序集,然后反射装载
            switch (_option.DbType.ToLower())
            {
            case "mysql":
                _tableSelector = new MySQL.MySqlTableSelector(_option);
                break;

            case "mssql":
                _tableSelector = new MsSQL.MsSqlTableSelector(_option);
                break;

            default:
                throw new Exception("暂不支持数据库:" + _option.DbType);
            }

            if (!Directory.Exists(option.OutDirectory))
            {
                try
                {
                    Directory.CreateDirectory(option.OutDirectory);
                }
                catch (Exception ex)
                {
                    throw new Exception("无法创建输出目录", ex);
                }
            }
        }
Esempio n. 2
0
 public bool TryCreateTable(ITableSelector selector, out ITableConfig table)
 {
     table = Factories.Table.Create(this, selector);
     if (!TableValidator.Validate(table))
     {
         return(false);
     }
     table = this.Tables.AddOrUpdate(table.Identifier, table);
     this.Configure(table);
     return(true);
 }
Esempio n. 3
0
        public ITableConfig GetTable(ITableSelector selector)
        {
            var existing = default(ITableConfig);
            var table    = Factories.Table.Create(this, selector);

            if (!this.Tables.TryGetValue(table.Identifier, out existing) || !TableComparer.TableConfig.Equals(table, existing))
            {
                return(default(ITableConfig));
            }
            return(existing);
        }
Esempio n. 4
0
        public ITableConfig CreateTable(ITableSelector selector)
        {
            var table = Factories.Table.Create(this, selector);

            if (!TableValidator.Validate(table))
            {
                throw new InvalidOperationException(string.Format("Table has invalid configuration: {0}", table));
            }
            table = this.Tables.AddOrUpdate(table.Identifier, table);
            this.Configure(table);
            return(table);
        }
Esempio n. 5
0
        public ITableConfig Create(IConfig config, ITableSelector selector)
        {
            switch (selector.SelectorType)
            {
            case TableSelectorType.TableName:
                return(this.Create(config, selector.Identifier, selector.TableName, selector.Flags));

            case TableSelectorType.TableType:
                return(this.Create(config, selector.Identifier, selector.TableType, selector.Flags));

            case TableSelectorType.Mapping:
                return(this.Create(config, selector.Identifier, selector.LeftTable, selector.RightTable, selector.Flags));

            default:
                throw new NotImplementedException();
            }
        }