Ejemplo n.º 1
0
        private static void GenerateTemplate_Rep(GeneratorConfig allConfig)
        {
            Console.WriteLine("===============生成Repositories==================");
            DisplayTemplateName(allConfig.repTemplate);
            var templateText = TemplateHelper.ReadTemplate(allConfig.repTemplate);

            foreach (var tableName in allConfig.tableList)
            {
                if (!string.IsNullOrEmpty(allConfig.trimTablePre))
                {
                    allConfig.tableName = TrimPre(tableName, allConfig.trimTablePre);
                }

                var className = allConfig.tableName + "Repository";
                allConfig.repClassName     = className;
                allConfig.repInterfaceName = "I" + className;
                var outputText = TemplateHelper.Parse(TemplateKey.Dao, templateText, allConfig);
                outputText = TemplateHelper.Clean(outputText, RegexPub.H1());

                var path = allConfig.repSavePath + "\\Repositories\\" + allConfig.moduleName;

                Console.WriteLine("生成Repositories表名:" + className);

                FileHelper.Save(string.Format(@"{0}\{1}.cs", path, className), outputText);
            }

            Console.WriteLine("===============生成Repositories完成===============");
        }
Ejemplo n.º 2
0
        private static void GenerateTemplate_Model(string templateFileName, List <string> tableList, IDBSchema dbSchema, string modelNamespaceVal, string savePath)
        {
            DisplayTemplateName(templateFileName);
            var templateText = TemplateHelper.ReadTemplate(templateFileName);

            foreach (var tableName in tableList)
            {
                var table = dbSchema.GetTableMetadata(tableName);
                if (table.PKs.Count == 0)
                {
                    throw new Exception(string.Format("表{0}:没有设置主键!", tableName));
                }
                Display(tableName, table);
                dynamic viewbag = new DynamicViewBag();
                viewbag.classnameVal = tableName;
                viewbag.namespaceVal = modelNamespaceVal;
                var outputText = TemplateHelper.Parse(TemplateKey.Model, templateText, table, viewbag);
                outputText = TemplateHelper.Clean(outputText, RegexPub.H1());
                FileHelper.Save(string.Format(@"{0}\{1}.cs", savePath, viewbag.classnameVal), outputText);
            }
        }
Ejemplo n.º 3
0
        private static void GenerateTemplate_Model(GeneratorConfig allConfig)
        {
            Console.WriteLine("===============生成Model==================");
            DisplayTemplateName(allConfig.modelTemplate);
            var templateText = TemplateHelper.ReadTemplate(allConfig.modelTemplate);
            var db           = new MySqlSchema(allConfig.dbConfig);

            foreach (var tableName in allConfig.tableList)
            {
                var table = db.GetTableMetadata(tableName);

                if (!string.IsNullOrEmpty(allConfig.trimTablePre))
                {
                    table.ClassName = TrimPre(tableName, allConfig.trimTablePre);
                }
                if (!string.IsNullOrEmpty(allConfig.baseColumn))
                {
                    table.BaseColumns = allConfig.baseColumn.Split(',').ToList();
                }
                table.TableName = tableName;

                //if (table.PKs.Count == 0) throw new Exception(string.Format("表{0}:没有设置主键!", tableName));
                Display(tableName, table);
                dynamic viewbag = new DynamicViewBag();
                viewbag.classnameVal = table.ClassName;
                viewbag.namespaceVal = allConfig.modelNamespaceVal;
                allConfig.table      = table;
                var outputText = TemplateHelper.Parse(TemplateKey.Model, templateText, allConfig, viewbag);
                outputText = TemplateHelper.Clean(outputText, RegexPub.H1());

                var path = allConfig.modelSavePath + "\\" + allConfig.moduleName;

                FileHelper.Save(string.Format(@"{0}\{1}.cs", path, viewbag.classnameVal), outputText);
            }

            Console.WriteLine("===============生成Model完成==================");
        }