public string Process(ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity ientity, Dictionary <string, object> TemplateCache, out string CurrentFileName) { Entity entity = (Entity)ientity.ScriptObject; Actions actions = new Actions(); foreach (var att in ientity.MappedClass.SourceAttributesThatMustExist) { entity.MappedClass.EnsureHas() .AttributeNamed(att.Name) .Finish() .ApplyTo(actions); } foreach (var prop in ientity.MappedClass.SourcePropertiesThatMustExist) { string[] modifiers = prop.Modifiers == null ? new string[0] : prop.Modifiers.ToArray(); PropertyConstraintBuilder propertyConstraint = null; propertyConstraint = entity.MappedClass.EnsureHasProperty(prop.Name, prop.PreviousNames ?? new List <string>()) .WithType(prop.Type) .WithModifiers(modifiers) .WithGetAccessorBody(prop.GetAccessor.Body) .WithSetAccessorBody(prop.SetAccessor.Body); if (!string.IsNullOrEmpty(prop.SetAccessor.Modifier)) { propertyConstraint.WithSetAccessorAccessibility(prop.SetAccessor.Modifier); } propertyConstraint.ApplyTo(actions); } foreach (var prop in ientity.MappedClass.SourcePropertiesThatMustNotExist) { PropertyConstraintBuilder propertyConstraint = null; propertyConstraint.ApplyTo(actions); } foreach (var field in ientity.MappedClass.SourceFieldsThatMustExist) { string[] modifiers = field.Modifiers == null ? new string[0] : field.Modifiers.ToArray(); FieldConstraintBuilder fieldConstraint = null; fieldConstraint = entity.MappedClass.EnsureHasField(field.Name, field.PreviousNames ?? new List <string>()) .WithType(field.Type) .WithModifiers(modifiers) .WithInitialValue(field.InitialValue); fieldConstraint.ApplyTo(actions); } foreach (var function in ientity.MappedClass.SourceFunctionsThatMustExist) { string[] modifiers = function.Modifiers == null ? new string[0] : function.Modifiers.ToArray(); FunctionConstraintBuilder functionConstraint = null; functionConstraint = entity.MappedClass.EnsureHasFunction(function.Name, function.PreviousNames ?? new List <string>()) .WithBody(function.Body) .WithModifiers(modifiers) .WithParameterTypes(function.Parameters) .WithReturnType(function.ReturnType); functionConstraint.ApplyTo(actions); } foreach (var function in ientity.MappedClass.SourceFunctionsThatMustNotExist) { FunctionConstraintBuilder functionConstraint = null; functionConstraint.ApplyTo(actions); } // Load the existing C# file up var filename = entity.EntitySet.MappingSet.CodeParseResults.GetFilenameForParsedClass(entity.MappedClass); CurrentFileName = filename; string outputText; if (TemplateCache.ContainsKey(filename) || !System.IO.File.Exists(filename)) { outputText = actions.RunActions((string)TemplateCache[filename], entity.MappedClass.Controller.Root, false); } else { outputText = actions.RunActions(System.IO.File.ReadAllText(filename), entity.MappedClass.Controller.Root, true); } TemplateCache[filename] = outputText; return(outputText); }
private static ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity CreateIEntity(ArchAngel.Providers.EntityModel.Model.EntityLayer.Entity entity) { string camelName; if (entity.Name.Length > 1) camelName = entity.Name.Substring(0, 1).ToLower() + entity.Name.Substring(1); else if (entity.Name.Length > 0) camelName = entity.Name.Substring(0, 1).ToLower(); else camelName = ""; ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity newEntity = new ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity() { Name = entity.Name, NamePlural = entity.Name.Pluralize(), NameCamelCase = camelName, NameCamelCasePlural = camelName.Pluralize(), IsInherited = entity.HasParent, //ImplementEqualityMembers = (bool)entity.GetUserOptionValue("ImplementEqualityMembers"), ParentName = entity.HasParent ? entity.Parent.Name : "", IsMapped = ArchAngel.NHibernateHelper.MappingFiles.Version_2_2.Utility.IsEntityMappedToTables(entity), ScriptObject = entity, IsAbstract = entity.IsAbstract, IsReadOnly = !entity.GetEntityMutable(), IsDynamicUpdate = entity.GetEntityDynamicUpdate(), IsDynamicInsert = entity.GetEntityDynamicInsert() }; return newEntity; }
public static string GetRelativeFilenameForEntityCSharpFile(ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity entity, string csprojFullFilePath) { return(ArchAngel.NHibernateHelper.HibernateMappingHelper.GetRelativeFilenameForEntityCSharpFile((Entity)entity.ScriptObject, csprojFullFilePath)); }