private static void FillEntityCollections(Entity entity, EntityElement value) { foreach (EntityFieldElement fieldNode in value.Fields) { EntityField field = EntityFieldProvider.CreateEntityField(fieldNode); if (field != null) { entity.Fields.Add(field); } } foreach (EntityEventElement eventNode in value.Events) { EntityEvent entityEvent = EntityEvent.Create(eventNode); if (entityEvent != null) { entity.CustomEvents.Add(entityEvent); } } if (entity.EnableHierarchy) { foreach (EntityNodeTypeElement nodeTypeNode in value.Hierarchy.NodeTypes) { EntityNodeType nodeType = EntityNodeType.Create(nodeTypeNode); if (nodeType != null) { entity.NodeTypes.Add(nodeType); } } entity.NodeTypes.Sort(); } }
protected override TreeViewItem BuildRoot() { //Reset variables and create Root node. ids = 0; rows.Clear(); var root = new TreeViewItem(-1, -1, "Root"); if (entityManager.IsCreated) { var entities = entityManager.GetAllEntities().ToArray(); foreach (var entity in entities) { var entityItem = new EntityElement(ids++, entity); rows.Add(entityItem); foreach (var type in entityManager.GetComponentTypes(entity)) { var ctype = new ComponentElement(type, ids++, 1); rows.Add(ctype); entityItem.AddChild(ctype); } root.AddChild(entityItem); } } root.AddChild(new TreeViewItem(1)); SetupDepthsFromParentsAndChildren(root); return(root); }
/// <summary> /// Returns sorted list of name spaces needed for the entity. /// </summary> /// <param name="entity">Entity code is being generated for</param> /// <param name="isDaoClass">Indicates if a DAO class is being generated.</param> /// <returns></returns> public ArrayList GetUsingNamespaces(EntityElement entity, Boolean isDaoClass) { ArrayList namespaces = new ArrayList(); namespaces.Add("System"); if (isDaoClass) { namespaces.Add("System.Collections"); namespaces.Add("System.Configuration"); namespaces.Add("System.Data"); namespaces.Add("System.Data.SqlClient"); namespaces.Add("Spring2.Core.DAO"); namespaces.Add(GetDONameSpace(null)); } foreach (PropertyElement field in entity.Properties) { if (!field.Type.Package.Equals(String.Empty) && !namespaces.Contains(field.Type.Package)) { namespaces.Add(field.Type.Package); } } Array names = namespaces.ToArray(typeof(String)); Array.Sort(names); return(new ArrayList(names)); }
/// <summary> /// <para>Checks that current element(element is part of representantion of database object in the file) structure fits the definition.</para> /// <para></para> /// </summary> /// <param name="kvp">KeyValuePair in which the key is the current element in hierarchy, and value is definition of its internal structure</param> /// <returns>Validation Result -in terms of success/failure and messages</returns> protected KeyValuePair <bool, Result> CheckAttributes(KeyValuePair <T, EntityElement> kvp) { T element = kvp.Key; EntityElement e = kvp.Value; T parentElement = GetParent(element); List <T> elements = new List <T>(); if (parentElement != null) { elements = FindChildrenByName(parentElement, e.name); } else { elements.Add(element); } foreach (T elem in elements) { foreach (string c in e.attributes.Keys) { KeyValuePair <bool, Result> attributeSearchResult = GetAttribute(element, c); if (!attributeSearchResult.Key) { return(attributeSearchResult); } } } Result checkResult = new Result("success", "success"); return(new KeyValuePair <bool, Result>(true, checkResult)); }
protected override void CreateAttributes(XElement key, EntityElement value) { foreach (KeyValuePair <string, string> kvp in value.attributes) { key.SetAttributeValue(kvp.Key, kvp.Value); } }
private Type CreateType(ModuleBuilder moduleBuilder, EntityElement entityElement) { var typeName = entityElement.ResolveFullName(); var typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public); foreach (var propertyElement in entityElement.Properties) { var propertyName = propertyElement.ResolveName(); var propertyType = ResolveType(moduleBuilder, propertyElement); typeBuilder.DefineProperty(propertyName, propertyType); } foreach (var relationElement in entityElement.Relations) { var relationTarget = relationElement.Target; var relationCardinality = relationElement.Cardinality; var propertyName = relationElement.ResolveName(); var propertyType = CreateRelationType(BuildType(moduleBuilder, relationTarget), relationCardinality); typeBuilder.DefineProperty(propertyName, propertyType); } return(typeBuilder.CreateType()); }
private IEdmComplexType BuildComplexType(EntityElement entityElement) { var entityType = new EdmComplexType(_namespaceName, entityElement.ResolveName()); foreach (var propertyElement in entityElement.Properties) { var propertyName = propertyElement.ResolveName(); var propertyType = BuildPropertyType(propertyElement); entityType.AddStructuralProperty(propertyName, propertyType); } foreach (var relationElement in entityElement.Relations) { var propertyName = relationElement.ResolveName(); var structuredType = BuildSchemaType(relationElement.Target); if (structuredType is IEdmComplexType) { var typeReference = BuildTypeReference(relationElement); entityType.AddStructuralProperty(propertyName, typeReference); } } return(entityType); }
private static void AddEntityElementIdAnnotation(TypeBuilder typeBuilder, EntityElement entity) { var id = entity.Identity.Id.ToString(); var constructor = typeof(EntityElementIdAttribute).GetConstructors().First(); var customAttributeBuilder = new CustomAttributeBuilder(constructor, new object[] { id }); typeBuilder.SetCustomAttribute(customAttributeBuilder); }
/// <summary> /// Get the hierarchical /// </summary> /// <param name="name">Name of the element</param> /// <returns>Hierarchical structure of element by its name</returns> public EntityElement GetEntityElement(string name) { EntityElement e = new EntityElement(name); T element = GetElementWithName(name); SortedList <string, string> attributes = GetElementAttributes(element); e.attributes = attributes; return(e); }
public Type BuildType(ModuleBuilder moduleBuilder, EntityElement entityElement) { Type type; if (!_typesById.TryGetValue(entityElement.Identity, out type)) { _typesById.Add(entityElement.Identity, type = CreateType(moduleBuilder, entityElement)); } return type; }
public Type BuildType(ModuleBuilder moduleBuilder, EntityElement entityElement) { Type type; if (!_typesById.TryGetValue(entityElement.Identity, out type)) { _typesById.Add(entityElement.Identity, type = CreateType(moduleBuilder, entityElement)); } return(type); }
private static void ProcessEntity(DbModelBuilder builder, EntityElement entityElement, Type entityType) { var configuration = builder.RegisterEntity(entityType); ConfigureEntity(configuration, entityElement); var tableElement = entityElement.MappedEntity; if (tableElement != null) { ConfigureTable(configuration, tableElement); } }
public Type Resolve(EntityElement entityElement) { if (entityElement == null) { throw new ArgumentNullException("entityElement"); } Type type; if (!_typesById.TryGetValue(entityElement.Identity, out type)) { _typesById.Add(entityElement.Identity, type = CreateType(entityElement)); } return type; }
private static void AddContainmentEntitiesMethods(TypeBuilder typeBuilder, Type parentType, EntityElement entity, Type entityType) { var propertyInfos = entity.Relations .Where(x => x.Uses<EntityRelationContainmentFeature>()) .Select(x => { var propertyName = x.ResolveName(); return entityType.GetProperty(propertyName); }); foreach (var propertyInfo in propertyInfos) { AddContainmentEntitiesMethod(typeBuilder, parentType, propertyInfo); } }
public Type Resolve(EntityElement entityElement) { if (entityElement == null) { throw new ArgumentNullException("entityElement"); } Type type; if (!_typesById.TryGetValue(entityElement.Identity, out type)) { _typesById.Add(entityElement.Identity, type = CreateType(entityElement)); } return(type); }
public void Update(EntityElement entityElement) { PropertyMappings = new ObservableCollection <PropertyMappingViewModel>(); _entityElement = entityElement; EntityName = entityElement.Name; TableName = entityElement.TableName; foreach (var property in entityElement.Properties) { var mappingRule = new PropertyMappingViewModel(property) { PropertyName = property.Name, ColumnName = property.ColumnName }; PropertyMappings.Add(mappingRule); } }
public void Update(EntityElement entityElement) { PropertyMappings = new ObservableCollection<PropertyMappingViewModel>(); _entityElement = entityElement; EntityName = entityElement.Name; TableName = entityElement.TableName; foreach (var property in entityElement.Properties) { var mappingRule = new PropertyMappingViewModel(property) { PropertyName = property.Name, ColumnName = property.ColumnName }; PropertyMappings.Add(mappingRule); } }
public IEdmStructuredType ResolveComplexType(EntityElement entityElement) { var typeName = entityElement.ResolveName(); IEdmSchemaType complexType; if (!_registeredTypes.TryGetValue(typeName, out complexType)) { _registeredTypes.Add(typeName, complexType = entityElement.KeyProperties.Any() ? (IEdmSchemaType)BuildEntityType(typeName, entityElement) : (IEdmSchemaType)BuildComplexType(typeName, entityElement)); AnnotateElement(complexType, entityElement.Identity.Id); } return((IEdmStructuredType)complexType); }
/// <summary> /// Get All entity elements with name(Create a copy of this elements and returns) /// </summary> /// <param name="name">Name of the elements to search</param> /// <returns>List of elements with name</returns> public List <EntityElement> GetEntityElements(string name) { List <EntityElement> ee = new List <EntityElement>(); List <T> elem = GetElementsWithName(name); foreach (T e in elem) { EntityElement eeee = new EntityElement(name); SortedList <string, string> attributes = GetElementAttributes(e); eeee.attributes = attributes; ee.Add(eeee); } return(ee); }
private IEdmEntityType BuildEntityType(string typeName, EntityElement entityElement) { var entityType = new EdmEntityType(NamespaceName, typeName); var keyIds = new HashSet <IMetadataElementIdentity>(entityElement.KeyProperties.Select(x => x.Identity)); foreach (var propertyElement in entityElement.Properties) { var propertyName = propertyElement.ResolveName(); var typeReference = ResolveTypeReference(propertyElement); var property = entityType.AddStructuralProperty(propertyName, typeReference); if (keyIds.Contains(propertyElement.Identity)) { entityType.AddKeys(property); } } foreach (var relationElement in entityElement.Relations) { var propertyName = relationElement.ResolveName(); var structuredType = ResolveComplexType(relationElement.Target); if (structuredType is IEdmComplexType) { var typeReference = ResolveTypeReference(relationElement); entityType.AddStructuralProperty(propertyName, typeReference); } var relatedEntityType = structuredType as IEdmEntityType; if (relatedEntityType != null) { entityType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = propertyName, ContainsTarget = relationElement.ContainsTarget, Target = relatedEntityType, TargetMultiplicity = Convert(relationElement.Cardinality) }); } } return(entityType); }
internal static Entity Create(EntityElement value) { Entity entity = new Entity(); entity.Id = value.Id; entity.Name = value.Name; entity.TableName = value.TableName; entity.CustomNavigateUrl = value.Hierarchy.CustomNavigateUrl; entity.CustomRootNodeText = value.Hierarchy.CustomRootNodeText; entity.EnableHierarchy = value.Hierarchy.Enabled; entity.EnableRootNodeSelection = value.Hierarchy.EnableRootNodeSelection; entity.HierarchyMaxDepth = value.Hierarchy.MaxDepth; entity.HierarchyStartLevel = value.Hierarchy.StartLevel; entity.EnableNodeTypesCustomization = value.Hierarchy.EnableNodeTypesCustomization; FillEntityCollections(entity, value); return(entity); }
/// <summary> /// Validates that file on which this class operates is in acceptable format for the system /// and this is what descendant classes must supply. /// Also this method acts as template method. /// So it calls to other methods that are implemented in descendant classes. /// </summary> /// <param name="slDefinitions">SortedList- The key is type of database object, value-hierarchical definition of a structure(applicable only when data is stored in files but not in db)</param> /// <returns></returns> public KeyValuePair <bool, Result> Validate(SortedList <string, EntityElement> slDefinitions) { bool checkValidity = CheckValidExtension(); if (checkValidity) { entityType = GetEntityType(slDefinitions); if (!slDefinitions.ContainsKey(entityType)) { Result res = new Result("No legal entity", "File not represents table or connection"); return(new KeyValuePair <bool, Result>(false, res)); } EntityDefinition = slDefinitions[entityType]; return(CheckStructureAndContent()); } Result r = new Result("File is with invalid extension", string.Format("File extension is: {0} but file is not structured like {0}", extension)); return(new KeyValuePair <bool, Result>(false, r)); }
private void ProcessEntity(DbModelBuilder builder, EntityElement entityElement) { var entityType = _typeProvider.Resolve(entityElement); if (entityType == null) { return; } var configuration = builder.RegisterEntity(entityType); ConfigureEntity(configuration, entityElement); var tableElement = entityElement.MappedEntity; if (tableElement != null) { ConfigureTable(configuration, tableElement); } }
/// <summary> /// Stores the update change permanently in the file /// </summary> /// <param name="e">Data of the table in hierarchical structure</param> /// <returns>success/failure</returns> public virtual bool Update(EntityElement e) { Queue <KeyValuePair <T, EntityElement> > definitionEntityElement = new Queue <KeyValuePair <T, EntityElement> >(); T root = CreateRoot(e); KeyValuePair <T, EntityElement> kvp = new KeyValuePair <T, EntityElement>(root, e); definitionEntityElement.Enqueue(kvp); while (definitionEntityElement.Count != 0) { kvp = definitionEntityElement.Dequeue(); CreateAttributes(kvp.Key, kvp.Value); foreach (EntityElement ee in kvp.Value.entityelements) { T elem = CreateElement(ee); AddElement(kvp.Key, elem); kvp = new KeyValuePair <T, EntityElement>(elem, ee); definitionEntityElement.Enqueue(kvp); } } Save(); return(true); }
/// <summary> /// Creates connection elements that binded to control that displays diagram /// </summary> public void CreateDiagram() { Connection c = new Connection(); c.Name = manager.GetName(); IEntityDefinition definition = SystemDefinitionsManager.DefinitionsManager.GetValidationDefinition(EntityTypesDefinition.Connection); if (!(definition is ConnectionDefinition)) { return; } ConnectionDefinition connectionDefinition = definition as ConnectionDefinition; EntityElement connectionElement = manager.GetEntityElement(connectionDefinition.ConnectionTag); c.FirstTable = connectionElement.attributes.Where(x => x.Key == connectionDefinition.ConnectionFirstTableAttribute).First().Value; c.FirstRelation = connectionElement.attributes.Where(x => x.Key == connectionDefinition.ConnectionFirstRelationAttribute).First().Value; c.SecondTable = connectionElement.attributes.Where(x => x.Key == connectionDefinition.ConnectionSecondTableAttribute).First().Value; c.SecondRelation = connectionElement.attributes.Where(x => x.Key == connectionDefinition.ConnectionSecondRelationAttribute).First().Value; var m = Structure.Struct.model; m.connections.Add(c); }
private void CreateEntityElementAssociations(ParserValidationDelegate vd) { foreach (EntityElement entity in entities) { //Fields which are entities. foreach (PropertyElement property in entity.Fields) { if (property.Entity.Name.Length > 0) { EntityElement e = EntityElement.FindEntityByName(entities, property.Entity.Name); if (e != null) { property.Entity = e; } else { vd(ParserValidationArgs.NewError("Property (" + property.Name + ") specifies an entity " + property.Entity.Name + " that could not be found as an defined entity")); } } } //Dependant entities. ArrayList dependents = new ArrayList(); foreach (EntityElement dependent in entity.Dependents) { EntityElement e = EntityElement.FindEntityByName(entities, dependent.Name); if (e != null) { dependents.Add(e); } else { vd(ParserValidationArgs.NewError("Entity (" + entity.Name + ") specifies a dependent entity " + dependent.Name + " that could not be found as an defined entity")); } } entity.Dependents = dependents; } }
// public DatabaseParser(ParserElement parser, ConfigurationElement options, XmlDocument doc) : base(parser, options, doc) { // this.options = options; // this.sqltypes = sqltypes; // this.types = types; // enumtypes = EnumElement.ParseFromXml(options, doc, sqltypes, types, this); // collections = CollectionElement.ParseFromXml(options, doc, sqltypes, types, this); // // if (parser.FindArgumentByName("server") == null || parser.FindArgumentByName("database") == null || parser.FindArgumentByName("user") == null || parser.FindArgumentByName("password") == null) { // this.AddValidationMessage(ParserValidationMessage.NewError("expected to find the following arguments, but didn't: server, database, user, password.")); // } else { // String connectionString = "server=" + parser.FindArgumentByName("server").Value + ";databse=" + parser.FindArgumentByName("database").Value + ";user="******"user").Value + ";password="******"password").Value + ";"; // // DatabaseElement db = new DatabaseElement(); // db.Name = "db"; // db.Server = parser.FindArgumentByName("server").Value; // db.Database = parser.FindArgumentByName("database").Value; // db.User = parser.FindArgumentByName("user").Value; // db.Password = parser.FindArgumentByName("password").Value; // connectionString = db.ConnectionString; // // SqlConnection conn = new SqlConnection(connectionString); // db.SqlEntities = DiscoverSqlEntities(conn, this); // databases.Add(db); // entities = GetEntities(doc, conn, new ArrayList(), this); // } // // Validate(); // } private ArrayList GetEntities(XmlDocument doc, SqlConnection connection, ArrayList sqlentities, IParser vd) { ArrayList entities = new ArrayList(); // Get a list of the entities in the database DataTable objDataTable = new DataTable(); SqlDataAdapter objDataAdapter = new SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG = '" + connection.Database + "'", connection); objDataAdapter.Fill(objDataTable); foreach (DataRow row in objDataTable.Rows) { if (row["TABLE_TYPE"].ToString() == "BASE TABLE" && row["TABLE_NAME"].ToString() != "dtproperties") { EntityElement entity = new EntityElement(); entity.Name = row["TABLE_NAME"].ToString(); entity.SqlEntity.Name = row["TABLE_NAME"].ToString(); entity.SqlEntity.View = "vw" + entity.SqlEntity.Name; entity.Properties = GetFields(entity, connection, doc, sqltypes, types); entities.Add(entity); } } return(entities); }
public EntityRelationCardinalityFeature(EntityRelationCardinality cardinality, EntityElement target) { Cardinality = cardinality; Target = target; }
public EntityRelationElementBuilder DirectTo(EntityElementBuilder entityElementBuilder) { _targetEntityElement = null; _targetEntityElementConfig = entityElementBuilder; return(this); }
public void GenerateLifeSeed() { var lifeStart = GeneratePatternStamps(NumberOfStartingSeeds, GridSize, new int2[][] { gliderTable, lightweightspaceShip, pentomino, acorn }); // Generate the entities in one batch int entityCount = GridSize.x * GridSize.y; using (var cells = new NativeArray <Entity>(entityCount, Allocator.Persistent)) { var worldUpdateDetails = new WorldUpdateDetails { WorldUpdateRate = this.WorldUpdateRate, ShouldLimitUpdates = this.ShouldLimitUpdates, lastUpdateTime = this.WorldUpdateRate }; // Kick off the loading/setup for the particle system for this world/grid var particleDetails = SetupParticleSystem(); var(shouldDieFunction, shouldComeToLifeFunction) = GameRules.GetRuleFunctions(RuleSet); var worldDetails = new WorldDetails() { DeadRenderer = DeadCellPrefab, AliveRenderer = AliveCellPrefab, updateDetails = worldUpdateDetails, particleDetails = particleDetails, shouldDie = shouldDieFunction, shouldComeToLifeDie = shouldComeToLifeFunction }; entityManager.CreateEntity(cellArcheType, cells); // Offset from any given entity to the surrounding enities int2[] offsetTable = { new int2(-1, -1), new int2(-0, -1), new int2(1, -1), new int2(-1, 0), /*new int2( -0, 0 ),*/ new int2(1,0), new int2(-1, 1), new int2(0, 1), new int2(1, 1), }; var renderableEntitys = new NativeArray <Entity>(entityCount, Allocator.Persistent); // Generate adjency information for each cell for (int x = 0; x < GridSize.x; ++x) { for (int y = 0; y < GridSize.y; ++y) { int2 location = new int2(x, y); EntityElement[] adjacency = new EntityElement[offsetTable.Length]; for (int i = 0; i < offsetTable.Length; ++i) { int2 entityLocation = location + offsetTable[i]; entityLocation = WrapLocation(entityLocation, GridSize); int idx = ConvertToEntityIndex(entityLocation, GridSize); adjacency[i] = cells[idx]; } int entityIdx = ConvertToEntityIndex(location, GridSize); // Populate the entity information - all cells start off 'dead' entityManager.SetComponentData(cells[entityIdx], new LifeCell { gridPosition = location }); entityManager.SetComponentData(cells[entityIdx], new Translation { Value = GetLocationAroundCentre(new float3(x, 0, y)) }); // Setup which system will perform the update if (SystemToUse == UpdateSystem.SingleThreaded) { entityManager.AddComponentData(cells[entityIdx], new SingleThreadUpdateTag()); } else { entityManager.AddComponentData(cells[entityIdx], new MultiThreadUpdateTag()); } // This instantiates a copy of the dead cell prefab and parents it to the cell we are processing var cellMesh = entityManager.Instantiate(DeadCellPrefab); entityManager.AddComponentData(cellMesh, new Parent { Value = cells[entityIdx] }); entityManager.AddComponentData(cellMesh, new LocalToParent()); // This lets us track which entity is our current renderable so we can swap it out later when we need // to update our state of being entityManager.SetComponentData(cells[entityIdx], new Renderable { value = cellMesh }); renderableEntitys[entityIdx] = cellMesh; // As we can't hold an array of Entity references in a component the adjancy information is stored in a // buffer attached to the entity and populated by copying from the details we generated DynamicBuffer <EntityElement> entityBuffer = entityManager.GetBuffer <EntityElement>(cells[entityIdx]); entityBuffer.CopyFrom(adjacency); // And finally associate some shared data so that we can swap the prefabs around later // and track the world update state entityManager.AddSharedComponentData(cells[entityIdx], worldDetails); } } SetupBoardCondition(cells, GridSize, lifeStart, renderableEntitys); renderableEntitys.Dispose(); // Finally we setup an entity which tracks if this instance of the world needs to be updated or not // It has tags for the threading of the update system so we can correctly dispatch later var worldUpdateTracker = entityManager.CreateEntity(); entityManager.AddComponentData(worldUpdateTracker, new WorldUpdateTracker()); if (SystemToUse == UpdateSystem.SingleThreaded) { entityManager.AddComponentData(worldUpdateTracker, new SingleThreadUpdateTag()); } else { entityManager.AddComponentData(worldUpdateTracker, new MultiThreadUpdateTag()); } entityManager.AddSharedComponentData(worldUpdateTracker, worldDetails); } }
public void GenerateLifeSeed(int2 gridSize) { var lifeStart = GeneratePatternStamps(NumberOfStartingSeeds, gridSize, new int2[][] { gliderTable, lightweightspaceShip, pentomino, acorn }); // Generate the entities in one batch int entityCount = gridSize.x * gridSize.y; var cells = new NativeArray <Entity>(entityCount, Allocator.Persistent); EntityManager.CreateEntity(defaultArcheType, cells); // Offset from any given entity to the surrounding enities int2[] offsetTable = new int2[] { new int2(-1, -1), new int2(-0, -1), new int2(1, -1), new int2(-1, 0), /*new int2( -0, 0 ),*/ new int2(1, 0), new int2(-1, 1), new int2(0, 1), new int2(1, 1), }; // Generate adjency information for each cell for (int x = 0; x < gridSize.x; ++x) { for (int y = 0; y < gridSize.y; ++y) { int2 location = new int2(x, y); EntityElement[] adjacency = new EntityElement[offsetTable.Length]; for (int i = 0; i < offsetTable.Length; ++i) { int2 entityLocation = location + offsetTable[i]; entityLocation = WrapLocation(entityLocation, gridSize); int idx = ConvertToEntityIndex(entityLocation, gridSize); adjacency[i] = cells[idx]; } int entityIdx = ConvertToEntityIndex(location, gridSize); // Populate the entity information - all cells start off 'dead' EntityManager.SetComponentData(cells[entityIdx], new LifeCell { gridPosition = location }); EntityManager.SetComponentData(cells[entityIdx], new Translation { Value = new float3(x, 0, y) }); EntityManager.SetSharedComponentData(cells[entityIdx], deadRenderMesh); // As we can't hold an array of Entity references in a component the adjancy information is stored in a // buffer attached to the entity and populated by copying from the details we generated DynamicBuffer <EntityElement> entityBuffer = EntityManager.GetBuffer <EntityElement>(cells[entityIdx]); entityBuffer.CopyFrom(adjacency); } } SetupBoardCondition(cells, gridSize, lifeStart); cells.Dispose(); }
private ArrayList GetFields(EntityElement entity, SqlConnection connection, XmlDocument doc, Hashtable sqltypes, Hashtable types) { ArrayList fields = entity.Properties; if (entity.SqlEntity.AutoDiscoverProperties) { DataTable columns = GetTableColumns(entity.SqlEntity, connection); foreach (DataRow objDataRow in columns.Rows) { if (objDataRow["COLUMN_COMPUTED"].ToString() == "0") { if (entity.SqlEntity.FindColumnByName(objDataRow["COLUMN_NAME"].ToString()) == null) { PropertyElement field = new PropertyElement(); field.Name = objDataRow["COLUMN_NAME"].ToString(); field.Column.Name = field.Name; field.Column.SqlType.Name = objDataRow["DATA_TYPE"].ToString(); // if the sql type is defined, default to all values defined in it if (sqltypes.ContainsKey(field.Column.SqlType.Name)) { field.Column.SqlType = (SqlTypeElement)((SqlTypeElement)sqltypes[field.Column.SqlType.Name]).Clone(); if (types.Contains(field.Column.SqlType.Type)) { field.Type = (TypeElement)((TypeElement)types[field.Column.SqlType.Type]).Clone(); } else { WriteToLog("Type " + field.Column.SqlType.Type + " was not defined"); } } else { WriteToLog("SqlType " + field.Column.SqlType.Name + " was not defined"); } field.Column.SqlType.Length = objDataRow["CHARACTER_MAXIMUM_LENGTH"].ToString().Length > 0 ? (Int32)objDataRow["CHARACTER_MAXIMUM_LENGTH"] : (Int32)(Int16)objDataRow["COLUMN_LENGTH"]; if (!System.DBNull.Value.Equals(objDataRow["NUMERIC_PRECISION"])) { field.Column.SqlType.Precision = (Int32)(Byte)objDataRow["NUMERIC_PRECISION"]; } if (!System.DBNull.Value.Equals(objDataRow["NUMERIC_SCALE"])) { field.Column.SqlType.Scale = (Int32)objDataRow["NUMERIC_SCALE"]; } field.Column.Identity = objDataRow["IsIdentity"].ToString() == "1"; field.Column.RowGuidCol = objDataRow["IsRowGuidCol"].ToString() == "1"; // Check for unicode columns if (field.Column.SqlType.Name.ToLower() == "nchar" || field.Column.SqlType.Name.ToLower() == "nvarchar" || field.Column.SqlType.Name.ToLower() == "ntext") { field.Column.SqlType.Length = field.Column.SqlType.Length / 2; } // Check for text or ntext columns, which require a different length from what SQL Server reports if (field.Column.SqlType.Name.ToLower() == "text") { field.Column.SqlType.Length = 2147483647; } else if (field.Column.SqlType.Name.ToLower() == "ntext") { field.Column.SqlType.Length = 1073741823; } // Append the array to the array list fields.Add(field); } } } } return(fields); }
private static void AddContainmentEntitiesMethods(TypeBuilder typeBuilder, Type parentType, EntityElement entity, Type entityType) { var propertyInfos = entity.Relations .Where(x => x.Uses <EntityRelationContainmentFeature>()) .Select(x => { var propertyName = x.ResolveName(); return(entityType.GetProperty(propertyName)); }); foreach (var propertyInfo in propertyInfos) { AddContainmentEntitiesMethod(typeBuilder, parentType, propertyInfo); } }
private Type CreateType(ModuleBuilder moduleBuilder, EntityElement entityElement) { var typeName = entityElement.ResolveFullName(); var typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public); foreach (var propertyElement in entityElement.Properties) { var propertyName = propertyElement.ResolveName(); var propertyType = ResolveType(moduleBuilder, propertyElement); typeBuilder.DefineProperty(propertyName, propertyType); } foreach (var relationElement in entityElement.Relations) { var relationTarget = relationElement.Target; var relationCardinality = relationElement.Cardinality; var propertyName = relationElement.ResolveName(); var propertyType = CreateRelationType(BuildType(moduleBuilder, relationTarget), relationCardinality); typeBuilder.DefineProperty(propertyName, propertyType); } return typeBuilder.CreateType(); }
private IEdmEntityType BuildEntityType(string typeName, EntityElement entityElement) { var entityType = new EdmEntityType(NamespaceName, typeName); var keyIds = new HashSet<IMetadataElementIdentity>(entityElement.KeyProperties.Select(x => x.Identity)); foreach (var propertyElement in entityElement.Properties) { var propertyName = propertyElement.ResolveName(); var typeReference = ResolveTypeReference(propertyElement); var property = entityType.AddStructuralProperty(propertyName, typeReference); if (keyIds.Contains(propertyElement.Identity)) { entityType.AddKeys(property); } } foreach (var relationElement in entityElement.Relations) { var propertyName = relationElement.ResolveName(); var structuredType = ResolveComplexType(relationElement.Target); if (structuredType is IEdmComplexType) { var typeReference = ResolveTypeReference(relationElement); entityType.AddStructuralProperty(propertyName, typeReference); } var relatedEntityType = structuredType as IEdmEntityType; if (relatedEntityType != null) { entityType.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = propertyName, ContainsTarget = relationElement.ContainsTarget, Target = relatedEntityType, TargetMultiplicity = Convert(relationElement.Cardinality) }); } } return entityType; }
private IEdmComplexType BuildComplexType(string typeName, EntityElement entityElement) { var entityType = new EdmComplexType(NamespaceName, typeName); foreach (var propertyElement in entityElement.Properties) { var propertyName = propertyElement.ResolveName(); var typeReference = ResolveTypeReference(propertyElement); entityType.AddStructuralProperty(propertyName, typeReference); } foreach (var relationElement in entityElement.Relations) { var propertyName = relationElement.ResolveName(); var structuredType = ResolveComplexType(relationElement.Target); if (structuredType is IEdmComplexType) { var typeReference = ResolveTypeReference(relationElement); entityType.AddStructuralProperty(propertyName, typeReference); } } return entityType; }
public IEdmStructuredType ResolveComplexType(EntityElement entityElement) { var typeName = entityElement.ResolveName(); IEdmSchemaType complexType; if (!_registeredTypes.TryGetValue(typeName, out complexType)) { _registeredTypes.Add(typeName, complexType = entityElement.KeyProperties.Any() ? (IEdmSchemaType)BuildEntityType(typeName, entityElement) : (IEdmSchemaType)BuildComplexType(typeName, entityElement)); AnnotateElement(complexType, entityElement.Identity.Id); } return (IEdmStructuredType)complexType; }
/// <summary> /// Post-parse validations /// </summary> /// <param name="vd"></param> protected void Validate(ParserValidationDelegate vd) { //TODO: walk through collection to make sure that cross relations are correct. foreach (DatabaseElement database in databases) { foreach (SqlEntityElement sqlentity in database.SqlEntities) { if (sqlentity.GetPrimaryKeyColumns().Count == 0 && (sqlentity.AllowDelete || sqlentity.AllowInsert || sqlentity.AllowUpdate)) { vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any primary key columns defined.")); } if (!sqlentity.HasUpdatableColumns() && sqlentity.GenerateUpdateStoredProcScript) { vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any editable columns and does not have generateupdatestoredprocscript=\"false\" specified.")); } } } // make sure that all columns are represented in entities foreach (EntityElement entity in entities) { if (entity.SqlEntity.Name.Length > 0) { foreach (ColumnElement column in entity.SqlEntity.Columns) { if (!column.Obsolete && EntityElement.FindAnyFieldByColumnName(entities, column.Name) == null && !entity.HasEntityMappedColumn(column)) { vd(ParserValidationArgs.NewWarning("could not find property representing column " + column.Name + " in entity " + entity.Name + ".")); } } } foreach (PropertyElement property in entity.Fields) { // make sure that obsolete columns are not mapped to properties if (property.Column.Obsolete && property.Column.Name.Length > 0) { vd(ParserValidationArgs.NewWarning("property " + property.Name + " in entity " + entity.Name + " is mapped to column " + property.Column.Name + " which is obsolete.")); } // have property descriptions "inherit" from a column if they are not populated if (property.Column.Description.Length > 0 && property.Description.Length == 0) { property.Description = property.Column.Description; } } } // make sure that enum values are unique foreach (EnumElement enumtype in enumtypes) { Hashtable values = new Hashtable(); foreach (EnumValueElement value in enumtype.Values) { if (values.Contains(value.Code)) { vd(ParserValidationArgs.NewError("Enum " + enumtype.Name + " has the code '" + value.Code + "' specified more than once.")); } else { values.Add(value.Code, value.Code); } } } // find and assign types to collections if available (the TypeElement is needed for templates that need to add namespaces) foreach (CollectionElement collection in Collections) { if (types.Contains(collection.Type.Name)) { collection.Type = (TypeElement)types[collection.Type.Name]; } } foreach (TaskElement task in generator.Tasks) { IWriter w = GetWriter(task.Writer); if (w == null) { vd(ParserValidationArgs.NewError("Task specified writer '" + task.Writer + "' that was not defined.")); } // check to make sure the styler exists if it is specified (optional) if (task.Styler.Length > 0) { IStyler s = GetStyler(task.Styler); if (s == null) { vd(ParserValidationArgs.NewError("Task specified styler '" + task.Styler + "' that was not defined.")); } } } }