Пример #1
0
        private static ConfigType GenerateType(VirtualDataTable table)
        {
            CheckAndGetIdMeta(table, out var idMeta);

            var configType = new ConfigType(table.TableName + Config.GenerateClassSuffix);

            configType.SetIdField(GetType(idMeta.FieldFullName, idMeta.TypeSpec), idMeta.Description);

            var rootSplitFields = new Dictionary <string, SplitField>();

            var tableConfig = TableConfigs.Get(table.TableName);

            //先填充xml定义的列
            if (tableConfig != null)
            {
                foreach (var typeDefine in tableConfig.DefineTypes)
                {
                    ParseDefineTypes(rootSplitFields, typeDefine, typeDefine.FieldName.Trim());
                }
            }

            foreach (var meta in table.ColumnMetas.Skip(1))
            {
                var fieldFullName = meta.FieldFullName.Trim();
                try
                {
                    var fieldType = GetType(fieldFullName.Replace(".", ""), meta.TypeSpec);
                    //split field
                    if (fieldFullName.Contains("."))
                    {
                        ParseSplitField(rootSplitFields, fieldFullName, fieldType, meta.Description);
                    }
                    //normal field
                    else
                    {
                        configType.AddField(fieldType, fieldFullName, meta.Description);
                    }
                }
                catch (MakeConfigException e)
                {
                    throw new MakeConfigException($"在文件{table.File.GetAbsolutePath()}中解析字段{fieldFullName}时遇到错误:{e.Message}");
                }
            }

            foreach (var kv in rootSplitFields)
            {
                var fieldName = kv.Key;
                var ctx       = kv.Value;

                var virtualType = ctx.Type ?? CreateSplitType(fieldName, ctx);

                configType.AddField(virtualType, fieldName, ctx.Description);
            }

            return(configType);
        }
 public static MakeConfigException SheetNotMatch(VirtualDataTable left, VirtualDataTable right, int i)
 {
     if (!left.TryGetColumnMeta(i, out _))
     {
         throw new MakeConfigException($"分表{left.File.GetAbsolutePath()}和{right.File.GetAbsolutePath()}数据第{i+1}列不一致,左侧缺失");
     }
     if (!right.TryGetColumnMeta(i, out _))
     {
         throw new MakeConfigException($"分表{left.File.GetAbsolutePath()}和{right.File.GetAbsolutePath()}数据第{i+1}列不一致,右侧缺失");
     }
     return(null);
 }
Пример #3
0
        public VirtualDataBase(DataSource ds, string name)
        {
            ds_ = ds;
            VirtualDataTable table = VirtualDataTable.FromName(ds_, name);

            table_ = new DataTable(table.Name);
            foreach (VirtualDataColumn column in table.Columns)
            {
                table_.Columns.Add(column.Name, column.Type);
            }
            pks_ = table.PrimaryKeys;
        }
Пример #4
0
        public static void Run()
        {
            //初始化所有配置文件
            ConfigReader.Read();

            if (Config.BaseTypeDll != null)
            {
                var assembly = Assembly.ReflectionOnlyLoadFrom(Config.BaseTypeDll);

                //加载所有导入类型
                ImportTypePool.Load(assembly);
            }

            var tableNameToTables = new Dictionary <string, List <VirtualDataTable> >();

            foreach (var file in WalkAllExcelFiles(Config.InputFolder))
            {
                var package = LoadExcelPackage(file.ToString());
                foreach (var sheet in package.Workbook.Worksheets)
                {
                    var table = new VirtualDataTable(file, sheet);
                    tableNameToTables.GetValueOrCreate(table.TableName).Add(table);
                }
            }

            using (var writer = new FileWriter($"{Config.OutputFolder}/ConfigBase.cs"))
            {
                TemplateFile.Copy("ConfigBase", writer);
            }

            foreach (var kv in tableNameToTables)
            {
                var tables     = kv.Value;
                var configType = TypeGenerator.GenerateType(tables);

                if (Config.OutputType == OutputType.CSharp)
                {
                    CSharpOutput.Output(configType, tables);
                }
            }
        }
 public static MakeConfigException NeedId(VirtualDataTable table)
 {
     throw new MakeConfigException($"表结构缺少Id列:{table.File.GetAbsolutePath()},Id列的名称必须设为{Config.IdName},约束指定#id");
 }
 internal static MakeConfigException SheetNotMatch(VirtualDataTable left, VirtualDataTable right, int i, string column)
 {
     throw new MakeConfigException($"分表{left.File.GetAbsolutePath()}和{right.File.GetAbsolutePath()}数据第{i+1}列{column}不一致");
 }
 public SimpleVirtualArrayDataSource(VirtualDataTable aCreatedBy, object[][] aData, string[] aColumnCaptions, string aTableName) : base(aTableName, aCreatedBy)
 {
     FData           = aData;
     FColumnCaptions = aColumnCaptions;
 }