/// <summary> /// 生成BQL实体 /// </summary> public void GenerateBQLEntity() { TagManager tag = new TagManager(); //FileInfo info = new FileInfo(EntityFileName); string dicPath = GenerateBasePath + "\\BQLEntity"; if (!Directory.Exists(dicPath)) { Directory.CreateDirectory(dicPath); } string fileName = dicPath + "\\" + ClassName + ".cs"; string idal = Models.BQLEntity; List <string> codes = new List <string>(); string baseType = null; if (EntityConfig.IsSystemTypeName(EntityBaseTypeName)) { baseType = "BQLEntityTableHandle"; } else { baseType = BaseNamespace + ".BQLEntity." + FormatClassName(EntityBaseTypeShortName); } using (StringReader reader = new StringReader(idal)) { string tmp = null; while ((tmp = reader.ReadLine()) != null) { if (tmp.StartsWith("<%#IF TableName%>")) { tag.AddTag("TableName"); } else if (tmp.StartsWith("<%#ENDIF%>")) { tag.PopTag(); } else { //if (tag.CurrentTag == "TableName" && string.IsNullOrEmpty(Table.TableName)) //{ // continue; //} tmp = tmp.Replace("<%=EntityNamespace%>", EntityNamespace); tmp = tmp.Replace("<%=BQLClassName%>", FormatClassName(ClassName)); tmp = tmp.Replace("<%=BQLEntityNamespace%>", BQLEntityNamespace); tmp = tmp.Replace("<%=Summary%>", Table.Description); tmp = tmp.Replace("<%=DBName%>", DBName); string args = GetBastGenericArgs(); string realbasetype = baseType; if (!string.IsNullOrEmpty(args)) { realbasetype += "<" + args + ">"; } tmp = tmp.Replace("<%=BQLEntityBaseType%>", realbasetype); tmp = tmp.Replace("<%=DataAccessNamespace%>", DataAccessNamespace); string className = ClassName; tmp = tmp.Replace("<%=ClassName%>", className); if (GenericInfo != null && GenericInfo.Count != 0) //有泛型 { StringBuilder generic = new StringBuilder(200); StringBuilder where = new StringBuilder(200); GetGeneric(generic, where); tmp = tmp.Replace("<%=Generic%>", generic.ToString()); tmp = tmp.Replace("<%=GenericWhere%>", where.ToString()); tmp = tmp.Replace("<%=HasGeneric%>", "<>"); } else { tmp = tmp.Replace("<%=Generic%>", ""); tmp = tmp.Replace("<%=GenericWhere%>", ""); tmp = tmp.Replace("<%=HasGeneric%>", ""); } string entityClassName = ClassName; tmp = tmp.Replace("<%=EntityClassName%>", entityClassName); tmp = tmp.Replace("<%=PropertyDetail%>", GenProperty()); tmp = tmp.Replace("<%=RelationDetail%>", GenRelation()); tmp = tmp.Replace("<%=PropertyInit%>", GenInit()); codes.Add(tmp); } } } CodeFileHelper.SaveFile(fileName, codes); EnvDTE.ProjectItem newit = DesignerInfo.CurrentProject.ProjectItems.AddFromFile(fileName); newit.Properties.Item("BuildAction").Value = (int)BuildAction.Code; }
/// <summary> /// 生成业务层 /// </summary> /// <param name="entity"></param> public void GenerateBusiness() { FileInfo info = new FileInfo(ClassDesignerFileName); string dicPath = info.DirectoryName + "\\Business"; if (!Directory.Exists(dicPath)) { Directory.CreateDirectory(dicPath); } string fileName = dicPath + "\\" + ClassName + "Business.cs"; if (File.Exists(fileName)) { return; } string model = Models.Business; string baseClass = null; string businessClassName = ClassName + "Business"; if (EntityConfig.IsSystemTypeName(EntityBaseTypeName)) { baseClass = "BusinessModelBase"; } else { baseClass = BaseNamespace + ".Business." + EntityBaseTypeShortName + "BusinessBase"; } List <string> codes = new List <string>(); TagManager tag = new TagManager(); using (StringReader reader = new StringReader(model)) { string tmp = null; while ((tmp = reader.ReadLine()) != null) { if (tmp.StartsWith("<%#IF TableName%>")) { tag.AddTag("TableName"); } else if (tmp.StartsWith("<%#ENDIF%>")) { tag.PopTag(); } else { if (tag.CurrentTag == "TableName" && string.IsNullOrEmpty(Table.TableName)) { continue; } tmp = tmp.Replace("<%=EntityNamespace%>", EntityNamespace); tmp = tmp.Replace("<%=Summary%>", Table.Description); tmp = tmp.Replace("<%=BusinessClassName%>", businessClassName); tmp = tmp.Replace("<%=ClassName%>", ClassName); tmp = tmp.Replace("<%=BusinessNamespace%>", BusinessNamespace); tmp = tmp.Replace("<%=BaseBusinessClass%>", baseClass); codes.Add(tmp); } } } CodeFileHelper.SaveFile(fileName, codes); EnvDTE.ProjectItem newit = DesignerInfo.CurrentProject.ProjectItems.AddFromFile(fileName); newit.Properties.Item("BuildAction").Value = (int)BuildAction.Code; }