public void CreateBatchDeleteModelCode() { string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_view_model); string template_file = template_folder + "{{entity_sub_namespace}}_BatchDeleteModel.cs"; string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); string target_file = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace); target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace); target_file = target_file.Replace("{{namespace}}", settings.code_namespace); target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace); string template = FileHelper.ReadAll(template_file); template = template.Replace("{{namespace}}", settings.code_namespace); template = template.Replace("{{entity_name}}", entity_name); template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace); StringBuilder sb = new StringBuilder(); sb.Append(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties.First(x => x.Name == entity_id_properties.Name)) + "[] ids { get; set; }"); template = template.Replace("{{Model-Parameters}}", sb.ToString()); FileHelper.CheckAndCreateFolder(target_folder); FileHelper.WriteAll(target_file, template); }
public void Create_ListModel_Code() { #region folders string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_query_models); string template_file = template_folder + "{{entity_sub_namespace}}\\ListModel.cs"; string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); string target_file = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace); target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace); target_file = target_file.Replace("{{namespace}}", settings.code_namespace); target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace); #endregion string template = FileHelper.ReadAll(template_file); template = template.Replace("{{namespace}}", settings.code_namespace); template = template.Replace("{{entity_name}}", entity_name); template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace); #region Create code StringBuilder sb = new StringBuilder(); //foreach (var p in entity_properties) //{ // //sb.AppendLine(""); // sb.AppendLine(" public " + NameHelper.GetEntityPropertyTypeString(p) + " " + NameHelper.Get_Property_Name_For_Query_ListModel(p.Name) + " { get; set; }"); //} for (int i = 0; i < entity_properties.Count; i++) { if (i == entity_properties.Count - 1) { sb.Append(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties[i]) + " " + NameHelper.Get_Property_Name_For_Query_ListModel(entity_properties[i].Name) + " { get; set; }"); } else { sb.AppendLine(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties[i]) + " " + NameHelper.Get_Property_Name_For_Query_ListModel(entity_properties[i].Name) + " { get; set; }"); } } template = template.Replace("{{List-Model-Parmeters}}", sb.ToString()); #endregion FileHelper.CheckAndCreateFolder(target_folder); FileHelper.WriteAll(target_file, template); }
/// <summary> /// 创建代码 /// </summary> public void Create_Add_Command() { #region folders string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_command); string template_file = template_folder + "AddCommand.cs"; string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); string target_file = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace); target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace); target_file = target_file.Replace("{{namespace}}", settings.code_namespace); target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace); #endregion string template = FileHelper.ReadAll(template_file); template = template.Replace("{{namespace}}", settings.code_namespace); template = template.Replace("{{entity_name}}", entity_name); template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace); StringBuilder sb = new StringBuilder(); //foreach (var p in entity_properties.Where(x => x.Name != entity_id_properties.Name).ToList()) //foreach (var p in entity_properties.ToList()) //{ // //sb.AppendLine(""); // sb.AppendLine(" public " + NameHelper.GetEntityPropertyTypeString(p) + " " + NameHelper.Get_Property_Name_For_Command(p.Name) + " { get; set; }"); //} for (int i = 0; i < entity_properties.Count; i++) { if (i == entity_properties.Count - 1) { sb.Append(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties[i]) + " " + NameHelper.Get_Property_Name_For_Command(entity_properties[i].Name) + " { get; set; }"); } else { sb.AppendLine(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties[i]) + " " + NameHelper.Get_Property_Name_For_Command(entity_properties[i].Name) + " { get; set; }"); } } template = template.Replace("{{Properties}}", sb.ToString()); FileHelper.CheckAndCreateFolder(target_folder); FileHelper.WriteAll(target_file, template); }
public void CreateUpdateModelCode() { string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_view_model); string template_file = template_folder + "{{entity_sub_namespace}}_UpdateModel.cs"; string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); string target_file = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace); target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace); target_file = target_file.Replace("{{namespace}}", settings.code_namespace); target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace); string template = FileHelper.ReadAll(template_file); template = template.Replace("{{namespace}}", settings.code_namespace); template = template.Replace("{{entity_name}}", entity_name); template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace); StringBuilder sb = new StringBuilder(); for (int i = 0; i < entity_properties.Count; i++) { if (i == entity_properties.Count - 1) { sb.Append(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties[i]) + " " + NameHelper.Get_Property_Name_For_ViewModel(entity_properties[i].Name) + " { get; set; }"); } else { sb.AppendLine(" public " + NameHelper.GetEntityPropertyTypeString(entity_properties[i]) + " " + NameHelper.Get_Property_Name_For_ViewModel(entity_properties[i].Name) + " { get; set; }"); } } template = template.Replace("{{Model-Parameters}}", sb.ToString()); FileHelper.CheckAndCreateFolder(target_folder); FileHelper.WriteAll(target_file, template); }
/// <summary> /// 创建代码 /// </summary> public void Create_Code() { #region folders string template_folder = context.Server.MapPath(settings.folder_templates + settings.template_folder_domain_models); string template_file = template_folder + "{{entity_sub_namespace}}.cs"; string target_folder = template_folder.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); string target_file = template_file.Replace(context.Server.MapPath(settings.folder_templates), context.Server.MapPath(settings.folder_result)); target_folder = target_folder.Replace("{{namespace}}", settings.code_namespace); target_folder = target_folder.Replace("{{entity_sub_namespace}}", entity_sub_namespace); target_file = target_file.Replace("{{namespace}}", settings.code_namespace); target_file = target_file.Replace("{{entity_sub_namespace}}", entity_sub_namespace); #endregion string template = FileHelper.ReadAll(template_file); template = template.Replace("{{namespace}}", settings.code_namespace); template = template.Replace("{{entity_name}}", entity_name); template = template.Replace("{{entity_sub_namespace}}", entity_sub_namespace); template = template.Replace("{{domain_model_name}}", NameHelper.Get_Domain_Model_Name(entity_name)); #region Create code StringBuilder sb = new StringBuilder(); sb.AppendLine(" public " + NameHelper.Get_Identities_Name(entity_name) + " " + NameHelper.Get_Property_Name_For_DomainModels(entity_id_properties.Name) + " { get; set; }"); foreach (var p in entity_properties.Where(x => x.Name != entity_id_properties.Name).ToList()) { sb.AppendLine(" public " + NameHelper.GetEntityPropertyTypeString(p) + " " + NameHelper.Get_Property_Name_For_DomainModels(p.Name) + " { get; set; }"); } //sb.AppendLine(""); sb.AppendLine(" public " + entity_name + " ConvertToEntity()"); sb.AppendLine(" {"); sb.AppendLine(" " + entity_name + " entity = new " + entity_name + "();"); foreach (var p in entity_properties.ToList()) { if (p.Name == entity_id_properties.Name) { sb.AppendLine(" entity." + p.Name + " = (Guid)this." + NameHelper.Get_Property_Name_For_DomainModels(p.Name) + ".GetPersistId();"); } else { sb.AppendLine(" entity." + p.Name + " = this." + NameHelper.Get_Property_Name_For_DomainModels(p.Name) + ";"); } } sb.AppendLine(" return entity;"); sb.Append(" }"); template = template.Replace("{{Domain-Model-Parmeters}}", sb.ToString()); #endregion FileHelper.CheckAndCreateFolder(target_folder); FileHelper.WriteAll(target_file, template); }