Esempio n. 1
0
        public static void Start(string targetFramwork, string baseNameSpace, string ignoreFirstPrefix, string dataBaseName, IEnumerable <TableInfo> tables, GeneratorOptions generatorOptions)
        {
            var projectDirectory = InternalUtil.CreateProjectDirectory($"{baseNameSpace}.Cache", generatorOptions.BaseProjectPath);

            _ = InternalUtil.CreateProjectFile(targetFramwork, projectDirectory, $"{baseNameSpace}.Cache.csproj", generatorOptions.IsPublished, generatorOptions.WarshipVersion, isAutoIncludeWarshap: true, $"{baseNameSpace}.Constants", $"{baseNameSpace}.Repository");
        }
        public static void Start(string targetFramwork, string baseNameSpace, string ignoreFirstPrefix, string dataBaseName, IEnumerable <TableInfo> tables, GeneratorOptions generatorOptions)
        {
            var projectDirectory = InternalUtil.CreateProjectDirectory($"{baseNameSpace}.UnitOfWork", generatorOptions.BaseProjectPath);

            _ = InternalUtil.CreateProjectFile(targetFramwork, projectDirectory, $"{baseNameSpace}.UnitOfWork.csproj", generatorOptions.IsPublished, generatorOptions.WarshipVersion, isAutoIncludeWarshap: true, $"{baseNameSpace}.Constants");
            CreateIUnitOfWork(projectDirectory, baseNameSpace, dataBaseName, generatorOptions);
            var baseFilePath = FileUtil.CreateDirectory(projectDirectory, "Implement");

            CreateUnitOfWork(baseFilePath, baseNameSpace, dataBaseName, generatorOptions);
        }
 private static void CreateUnitOfWork(string baseTableFilePath, string baseNameSpace, string databaseName, GeneratorOptions generatorOptions)
 {
     if (generatorOptions.IsOverride)
     {
         FileUtil.CreateFile(baseTableFilePath, $"{databaseName.ToUpperFirst()}UnitOfWork.cs", GetUnitOfWorkStr(baseNameSpace, databaseName));
     }
     else if (!FileUtil.IsExistsFile(baseTableFilePath, $"{databaseName.ToUpperFirst()}UnitOfWork.cs"))
     {
         FileUtil.CreateFile(baseTableFilePath, $"{databaseName.ToUpperFirst()}UnitOfWork.cs", GetUnitOfWorkStr(baseNameSpace, databaseName));
     }
 }
Esempio n. 4
0
 private static void CreateInterface(string baseFilePath, string baseNameSpace, string ignoreFirstPrefix, TableInfo tableInfo, GeneratorOptions generatorOptions)
 {
     if (generatorOptions.IsOverride)
     {
         FileUtil.CreateFile(baseFilePath, $"{tableInfo.GetIApplicationName(ignoreFirstPrefix)}.cs", GetInterfaceStr(baseNameSpace, ignoreFirstPrefix, tableInfo));
     }
     else if (!FileUtil.IsExistsFile(baseFilePath, $"{tableInfo.GetIApplicationName(ignoreFirstPrefix)}.cs"))
     {
         FileUtil.CreateFile(baseFilePath, $"{tableInfo.GetIApplicationName(ignoreFirstPrefix)}.cs", GetInterfaceStr(baseNameSpace, ignoreFirstPrefix, tableInfo));
     }
 }
Esempio n. 5
0
        public static void Start(string targetFramwork, string baseNameSpace, string ignoreFirstPrefix, string dataBaseName, IEnumerable <TableInfo> tables, GeneratorOptions generatorOptions)
        {
            var projectDirectory = InternalUtil.CreateProjectDirectory($"{baseNameSpace}.Application", generatorOptions.BaseProjectPath);

            _ = InternalUtil.CreateProjectFile(targetFramwork, projectDirectory, $"{baseNameSpace}.Application.csproj", generatorOptions.IsPublished, generatorOptions.WarshipVersion, isAutoIncludeWarshap: true, $"{baseNameSpace}.Domain", $"{baseNameSpace}.Repository", $"{baseNameSpace}.DomainService", $"{baseNameSpace}.Cache", $"{baseNameSpace}.UnitOfWork");
            if (tables != null)
            {
                foreach (var tableInfo in tables)
                {
                    if (tableInfo.GetKeyColumn() == null)
                    {
                        continue;
                    }
                    string baseFilePath = projectDirectory;
                    var    bizName      = tableInfo.GetBizName(ignoreFirstPrefix);
                    if (!string.IsNullOrWhiteSpace(bizName))
                    {
                        baseFilePath = FileUtil.CreateDirectory(baseFilePath, bizName);
                    }
                    CreateInterface(baseFilePath, baseNameSpace, ignoreFirstPrefix, tableInfo, generatorOptions);
                    baseFilePath = FileUtil.CreateDirectory(baseFilePath, "Implement");
                    CreateImplement(baseFilePath, baseNameSpace, ignoreFirstPrefix, tableInfo, dataBaseName);
                }
            }
        }
Esempio n. 6
0
        public static void Start(string targetFramwork, string baseNameSpace, string ignoreFirstPrefix, string dataBaseName, IEnumerable <TableInfo> tables, GeneratorOptions generatorOptions)
        {
            var projectDirectory = InternalUtil.CreateProjectDirectory($"{baseNameSpace}.Constants", generatorOptions.BaseProjectPath);

            _ = InternalUtil.CreateProjectFile(targetFramwork, projectDirectory, $"{baseNameSpace}.Constants.csproj", generatorOptions.IsPublished, generatorOptions.WarshipVersion, isAutoIncludeWarshap: true);
            if (tables != null)
            {
                var tablesDirectory = FileUtil.CreateDirectory(projectDirectory, "Tables");
                foreach (var tableInfo in tables)
                {
                    if (tableInfo.GetKeyColumn() == null)
                    {
                        continue;
                    }
                    string baseFilePath = tablesDirectory;
                    var    bizName      = tableInfo.GetBizName(ignoreFirstPrefix);
                    if (!string.IsNullOrWhiteSpace(bizName))
                    {
                        baseFilePath = FileUtil.CreateDirectory(baseFilePath, bizName);
                    }
                    CreateTableConstants(baseNameSpace, ignoreFirstPrefix, baseFilePath, tableInfo);
                }
            }
            //创建ConfigName
            CreateConfigName(projectDirectory, baseNameSpace, dataBaseName, generatorOptions);
        }
Esempio n. 7
0
        public static void Start(string targetFramwork, string baseNameSpace, string ignoreFirstPrefix, IEnumerable <TableInfo> tables, GeneratorOptions generatorOptions)
        {
            var projectDirectory = InternalUtil.CreateProjectDirectory($"{baseNameSpace}.Domain", generatorOptions.BaseProjectPath);

            _ = InternalUtil.CreateProjectFile(targetFramwork, projectDirectory, $"{baseNameSpace}.Domain.csproj", generatorOptions.IsPublished, generatorOptions.WarshipVersion);
            if (tables != null)
            {
                foreach (var tableInfo in tables.Where(m => m.ColumnList != null && m.ColumnList.Count() > 0))
                {
                    if (tableInfo.GetKeyColumn() == null)
                    {
                        continue;
                    }
                    string baseFilePath = projectDirectory;
                    var    bizName      = tableInfo.GetBizName(ignoreFirstPrefix);
                    if (!string.IsNullOrWhiteSpace(bizName))
                    {
                        baseFilePath = FileUtil.CreateDirectory(baseFilePath, bizName);
                    }
                    CreateDomain(baseNameSpace, baseFilePath, ignoreFirstPrefix, tableInfo, generatorOptions);
                }
            }
        }
        public static GeneratorOptions Create(CodeClass codeClass, string baseDirPath)
        {
            var generatorOptions = new GeneratorOptions();

            generatorOptions.BaseProjectPath = baseDirPath;
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            foreach (CodeAttribute classAttribute in codeClass.Attributes)
            {
                switch (classAttribute.Name.ToLower())
                {
                //[CodeGeneratorConnection("localhost")]
                case "codegeneratorconnection":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.Connection = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorSchema("public")]
                case "codegeneratorschema":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.Schema = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorDatabaseType("public")]
                case "codegeneratordatabasetype":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.DatabaseType = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorTablePrefix("public")]
                case "codegeneratortableprefix":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.TablePrefix = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorIgnorePrefix("public")]
                case "codegeneratorignoreprefix":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.IgnorePrefix = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorTargetFramwork("public")]
                case "codegeneratortargetframwork":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.TargetFramwork = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorBaseNameSpace("public")]
                case "codegeneratorbasenamespace":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.BaseNameSpace = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorIsOverride(true)]
                case "codegeneratorisoverride":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.IsOverride = bool.Parse(classAttribute.Value.Trim().TrimStart('"').TrimEnd('"'));
                    }
                    break;

                //[CodeGeneratorBaseProjectPath("public")]
                case "codegeneratorbaseprojectpath":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.BaseProjectPath = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;

                //[CodeGeneratorIsPublished(true)]
                case "codegeneratorispublished":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.IsPublished = bool.Parse(classAttribute.Value.Trim().TrimStart('"').TrimEnd('"'));
                    }
                    break;

                //[CodeGeneratorWarshipVersion("1.0.0.0")]
                case "codegeneratorwarshipversion":
                    if (!string.IsNullOrEmpty(classAttribute.Value?.TrimStart('"').TrimEnd('"')))
                    {
                        generatorOptions.WarshipVersion = classAttribute.Value.Trim().TrimStart('"').TrimEnd('"');
                    }
                    break;
                }
            }
            generatorOptions.Check();
            return(generatorOptions);
        }