/// <summary> /// 创建应用层的代码 /// </summary> /// <param name="overWrite">是否重写</param> /// <param name="overReadEntity">是否重新获取实体信息</param> public static void Create(bool overWrite, bool overReadEntity = false) { if (ProjectContainer.Application == null) { ProjectContainer.Application = SolutionCommon.Dte.AddClassLibrary(SolutionCommon.Application, true); } if (ProjectContainer.IApplication == null) { ProjectContainer.IApplication = SolutionCommon.Dte.AddClassLibrary(SolutionCommon.IApplication, true); } List <TemplateEntity> entitys = DomainEntityLogic.GetEntitys(overReadEntity); for (int i = 0; i < entitys.Count; i++) { // _work.ReportProgress((int)((i + 1) * 100 / entitys.Length), string.Format("添加实体类-{0}-的代码", fileEntity)); TemplateEntity tmpEntity = entitys[i]; CodeCreateManager codeManager = new CodeCreateManager(ConstructType.Application, tmpEntity); codeManager.IsOverWrite = overWrite; codeManager.BuildTaget = ProjectContainer.Application; codeManager.CreateCode(); codeManager = new CodeCreateManager(ConstructType.IApplication, tmpEntity); codeManager.IsOverWrite = overWrite; codeManager.BuildTaget = ProjectContainer.IApplication; codeManager.CreateCode(); } }
/// <summary> /// 创建DTO实体的代码 /// </summary> /// <param name="overWrite">是否重写</param> public static void Create(bool overWrite) { if (ProjectContainer.Data2Object == null) { ProjectContainer.Data2Object = SolutionCommon.Dte.AddClassLibrary(SolutionCommon.Data2Object); } else { if (overWrite) { ProjectContainer.Data2Object.Delete(); ProjectContainer.Data2Object = SolutionCommon.Dte.AddClassLibrary(SolutionCommon.Data2Object); } } List <TemplateEntity> entitys = DomainEntityLogic.GetEntitys(false); CodeBuilderContainer.ProfileBuilder.Clear(); for (int i = 0; i < entitys.Count; i++) { // _work.ReportProgress((int)((i + 1) * 100 / entitys.Length), string.Format("添加实体类-{0}-的代码", fileEntity)); TemplateEntity tmpEntity = entitys[i]; Data2ObjCerateManager codeManager = new Data2ObjCerateManager(ConstructType.Data2Obj, tmpEntity); codeManager.IsOverWrite = overWrite; codeManager.BuildTaget = ProjectContainer.Data2Object; codeManager.CreateCode(); CodeAppendManager appendManager = new CodeAppendManager(ConstructType.Profile, tmpEntity); appendManager.BuildTaget = CodeBuilderContainer.ProfileBuilder; appendManager.CreateCode(); } CodeStaticManager staticManager = new CodeStaticManager(ConstructType.Profile); //Profile ModelPathConverter.GetCodePath(ConstructType.Profile); staticManager.BuildTaget = new StringCodeArgment() { Folder = "Profile", Name = SolutionCommon.ProjectName + "Profile.cs", Target = ProjectContainer.Data2Object }; staticManager.CreateCode(); }
public static void CreateCode(bool overWrite) { if (ProjectContainer.Service == null) { throw new Exception("Entity2Code Service Project Can not be Find"); } if (overWrite) { CodeBuilderContainer.ServiceBuilder.Clear(); CodeBuilderContainer.IServiceBuilder.Clear(); CodeBuilderContainer.ContainBuilder.Clear(); List <TemplateEntity> entitys = DomainEntityLogic.GetEntitys(false); for (int i = 0; i < entitys.Count; i++) { CodeAppendManager codeManager = new CodeAppendManager(ConstructType.Service, entitys[i]); codeManager.BuildTaget = CodeBuilderContainer.ServiceBuilder; codeManager.CreateCode(); codeManager = new CodeAppendManager(ConstructType.IService, entitys[i]); codeManager.BuildTaget = CodeBuilderContainer.IServiceBuilder; codeManager.CreateCode(); codeManager = new CodeAppendManager(ConstructType.Container, entitys[i]); codeManager.BuildTaget = CodeBuilderContainer.ContainBuilder; codeManager.CreateCode(); } } CodeStaticManager staticManager = new CodeStaticManager(ConstructType.Service); //Service staticManager.BuildTaget = new StringCodeArgment() { Name = SolutionCommon.ProjectName + "Service.svc.cs", Target = ProjectContainer.Service }; staticManager.CreateCode(); //IService staticManager = new CodeStaticManager(ConstructType.IService); staticManager.BuildTaget = new StringCodeArgment() { Name = "I" + SolutionCommon.ProjectName + "Service.cs", Target = ProjectContainer.Service }; staticManager.CreateCode(); //Container if (SolutionCommon.infrastryctType == InfrastructType.CodeFirst) { ModelContainer.Regist("$DBAppContent$", " string db= System.Configuration.ConfigurationManager.AppSettings[\"DBSchema\"];", "获取数据库连接字符串的函数内容"); ModelContainer.Regist("$DBConstr$", "new InjectionConstructor(db)", "注册上下文的函数内容"); } else { ModelContainer.Regist("$DBAppContent$", "", "获取数据库连接字符串的函数内容"); ModelContainer.Regist("$DBConstr$", "", "注册上下文的函数内容"); } staticManager = new CodeStaticManager(ConstructType.Container); staticManager.BuildTaget = new StringCodeArgment() { Folder = "InstanceProviders", Name = "Container.cs", Target = ProjectContainer.Service }; staticManager.CreateCode(); }