Example #1
0
        public static ProjectConfig ConvertDatabaseConfigToProjectConfig(IDatabase database)
        {
            var config = database.Config;

            ProjectConfig projectConfig = new ProjectConfig();

            projectConfig.Database         = database;
            projectConfig.Enable           = config.EnableCodeGen;
            projectConfig.ClassNameMode    = config.CodeGenClassNameMode;
            projectConfig.PropertyNameMode = config.CodeGenPropertyNameMode;
            projectConfig.Name             = config.CodeGenProjectName;
            projectConfig.NameSpace        = config.CodeGenNameSpace;
            projectConfig.TableFilter      = config.CodeGenTableFilter;

            foreach (var temp in config.CodeGenTemplates)
            {
                GeneraterConfig genConfig = new GeneraterConfig();
                genConfig.Name = temp.Name;
                genConfig.OutputFileExtension = temp.OutputFileExtension;
                genConfig.FilePrefix          = temp.FilePrefix;
                genConfig.FileSuffix          = temp.FileSuffix;
                genConfig.FileNameFormat      = temp.FileNameFormat;
                genConfig.Enabled             = temp.Enabled;
                genConfig.TemplateFileName    = temp.TemplateFileName;
                //genConfig.Template = temp.Template;
                genConfig.OutputDirectory = temp.OutputDirectory;
                genConfig.Append          = temp.Append;
                genConfig.Encoding        = temp.Encoding;
                genConfig.OutputType      = temp.OutputType;

                projectConfig.GeneraterConfigs.Add(genConfig);
            }
            return(projectConfig);
        }
Example #2
0
        public static string Format(string str, ProjectConfig config, GeneraterConfig template, string tableName, string defaultName)
        {
            string result = defaultName;

            if (!string.IsNullOrEmpty(str))
            {
                result = str;
                result = result.Replace("{%ProjectName%}", config.Name);
                result = result.Replace("{%TemplateName%}", template.Name);
                result = result.Replace("{%ObjectName%}", tableName);
                //result = result.Replace("{%BoilerplatPath%}", tableName);
                //result = result.Replace("{%ProjectOutputPath%}", tableName);
            }
            return(result);
        }
Example #3
0
        public static string GetOutputFileName(ProjectConfig config, GeneraterConfig moduleconfig, string outputFileName, string modelName)
        {
            if (string.IsNullOrEmpty(outputFileName))
            {
                outputFileName = "";
            }
            string filename     = moduleconfig.FilePrefix + outputFileName + moduleconfig.FileSuffix + moduleconfig.OutputFileExtension;
            string dataFilePath = System.IO.Path.Combine(GetModuleDirectory(config, moduleconfig, modelName), filename);
            string directory    = Path.GetDirectoryName(dataFilePath);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            return(dataFilePath);
        }
Example #4
0
        public static string GetModuleDirectory(ProjectConfig config, GeneraterConfig moduleconfig, string modelname)
        {
            if (string.IsNullOrEmpty(moduleconfig.OutputDirectory))
            {
                moduleconfig.OutputDirectory = "";
            }
            //格式化
            //string outDir = Format(moduleconfig.OutputDirectory, config, moduleconfig, moduleconfig.OutputDirectory, moduleconfig.OutputDirectory);
            string outDir       = Format(moduleconfig.OutputDirectory, config, moduleconfig, modelname, moduleconfig.OutputDirectory);
            string dataFilePath = (GetProjectDirectory(config) + outDir); //(config.Database.Config.CodeGenBaseDirectory.TrimEnd('\\') +outDir);

            //string dataFilePath = System.IO.Path.Combine(GetProjectDirectory(config), outDir);
            if (!Directory.Exists(dataFilePath))
            {
                Directory.CreateDirectory(dataFilePath);
            }
            return(dataFilePath);
        }
Example #5
0
        /// <summary>
        /// 获取模板内容
        /// </summary>
        /// <param name="templateConfig"></param>
        /// <returns></returns>
        private string GetTemplate(GeneraterConfig templateConfig)
        {
            if (!string.IsNullOrEmpty(templateConfig.Template))
            {
                return(templateConfig.Template);
            }
            else
            {
                string template         = "";
                string templateFileName = templateConfig.TemplateFileName;
                string key = templateConfig.Name;
                //if (!_templatePools.ContainsKey(key) || (_templatePools.ContainsKey(key) && string.IsNullOrEmpty(_templatePools[key])))
                //{
                template = (DbLoader.GetTemplateContent(templateFileName, templateConfig.Encoding));

                //    _templatePools[key] = template;
                //}
                //else
                //    template = _templatePools[key];
                return(template);
            }
        }
Example #6
0
 public static string FormatFileName(ProjectConfig config, GeneraterConfig template, string tableName, string defaultName)
 {
     return(Format(template.FileNameFormat, config, template, tableName, defaultName));
 }