Example #1
0
        void LoadEntityType(XmlElement et, string ns)
        {
            var e = new EntityTypeInfo {
                Name      = et.GetAttribute("Name").Trim(),
                Namespace = ns
            };

            foreach (var p in et.ElementsWithName("Property"))
            {
                var prop = new EntityPropertyInfo {
                    Name         = p.GetAttribute("Name").Trim(),
                    TypeFullName = p.GetAttribute("Type").Trim(),
                    IsKey        = false
                };
                e.Properties.Add(prop);
            }

            foreach (var key in et.ElementsWithName("Key"))
            {
                foreach (var p in key.ElementsWithName("PropertyRef"))
                {
                    var name = p.GetAttribute("Name").Trim();

                    foreach (var prop in e.Properties)
                    {
                        if (prop.Name == name)
                        {
                            prop.IsKey = true;
                        }
                    }
                }
            }

            EntityTypes.Add(e);
        }
        public QuantityDescription(string baseName, IFCEntityType entityType)
        {
            string quantitySetName = (ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4) ?
                                     "BaseQuantities" : "Qto_" + baseName + "BaseQuantities";

            Name = quantitySetName;
            EntityTypes.Add(entityType);
        }
Example #3
0
        public SmartSqlBuilder RegisterEntity(TypeScanOptions typeScanOptions)
        {
            var entityTypes = TypeScan.Scan(typeScanOptions);

            foreach (var entityType in entityTypes)
            {
                EntityTypes.Add(entityType);
            }

            return(this);
        }
Example #4
0
        /// <summary>
        /// Add the invalidations for the given key to the context. Used for a cache hit.
        /// </summary>
        /// <param name="cacheInvalidator"></param>
        /// <param name="key"></param>
        public void AddInvalidationsFor <TKey, TValue>(CacheInvalidator <TKey, TValue> cacheInvalidator, TKey key)
        {
            if (cacheInvalidator == null)
            {
                throw new ArgumentNullException("cacheInvalidator");
            }
            if (_entry == null)
            {
                throw new InvalidOperationException("Not valid for ContextType.None");
            }

            Entities.Add(cacheInvalidator.EntityToCacheKey.GetKeys(key));
            RelationshipTypes.Add(cacheInvalidator.RelationshipTypeToCacheKey.GetKeys(key));
            FieldTypes.Add(cacheInvalidator.FieldTypeToCacheKey.GetKeys(key));
            EntityInvalidatingRelationshipTypes.Add(cacheInvalidator.EntityInvalidatingRelationshipTypesToCacheKey.GetKeys(key));
            EntityTypes.Add(cacheInvalidator.EntityTypeToCacheKey.GetKeys(key));
        }
        private Type CreateEntityType(ModuleBuilder builder, Random rand, string id)
        {
            Type baseType = null;

            // for 25% chance, find a type which was already created as a base type
            if (rand.Next(4) == 0 && this.EntityTypes.Any())
            {
                baseType = this.EntityTypes[rand.Next(this.EntityTypes.Count())];
            }

            string      name        = builder.Assembly.GetName().Name + ".EntityType" + id;
            TypeBuilder typeBuilder = baseType == null
                ? builder.DefineType(name, TypeAttributes.Public)
                : builder.DefineType(name, TypeAttributes.Public, baseType);

            if (baseType == null)
            {
                var  idTypes = (new Type[] { typeof(string), typeof(Guid), typeof(int), typeof(long) }).ToList();
                Type idType  = idTypes[rand.Next(idTypes.Count())];
                typeBuilder.DefineAutoImplementedProperty("ID", idType);
            }

            // define 1~20 properties on the new entity type
            typeBuilder.DefineProperties(
                rand.Next(20) + 1,
                rand,
                primitiveTypes.Union(_complexTypes)
                .Union(_entityTypes)
                .Union(new Type[] { typeBuilder }).ToArray());


            var result = typeBuilder.CreateType();

            EntityTypes.Add(result);

            return(result);
        }
Example #6
0
 public SmartSqlBuilder RegisterEntity(Type entityType)
 {
     EntityTypes.Add(entityType);
     return(this);
 }
Example #7
0
 /// <summary>
 /// LĂȘ os dados serializados.
 /// </summary>
 /// <param name="reader"></param>
 void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
 {
     reader.MoveToElement();
     if (!reader.IsEmptyElement)
     {
         reader.ReadStartElement();
         while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
         {
             if (reader.IsEmptyElement)
             {
                 reader.Skip();
                 continue;
             }
             if (reader.LocalName == "EntityTypes")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "EntityType")
                     {
                         var type = new EntityType();
                         ((System.Xml.Serialization.IXmlSerializable)type).ReadXml(reader);
                         EntityTypes.Add(type);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "PropertySettings")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "PropertySetting")
                     {
                         var settings = new PropertySettings();
                         ((System.Xml.Serialization.IXmlSerializable)settings).ReadXml(reader);
                         PropertySettings.Add(settings);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "ValidationTypes")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "ValidationType")
                     {
                         var validationType = new ValidationType();
                         ((System.Xml.Serialization.IXmlSerializable)validationType).ReadXml(reader);
                         ValidationTypes.Add(validationType);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "Validations")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "Validation")
                     {
                         var validation = new Validation();
                         ((System.Xml.Serialization.IXmlSerializable)validation).ReadXml(reader);
                         Validations.Add(validation);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "InputRules")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "InputRules")
                     {
                         var inputRules = new InputRules();
                         ((System.Xml.Serialization.IXmlSerializable)inputRules).ReadXml(reader);
                         InputRules.Add(inputRules);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "InputRulesGroups")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "InputRulesGroup")
                     {
                         var inputRulesGroup = new InputRulesGroup();
                         ((System.Xml.Serialization.IXmlSerializable)inputRulesGroup).ReadXml(reader);
                         InputRulesGroups.Add(inputRulesGroup);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else if (reader.LocalName == "InputValidates")
             {
                 reader.ReadStartElement();
                 while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
                 {
                     if (reader.LocalName == "InputValidate")
                     {
                         var validate = new InputValidate();
                         ((System.Xml.Serialization.IXmlSerializable)validate).ReadXml(reader);
                         InputValidates.Add(validate);
                     }
                     else
                     {
                         reader.Skip();
                     }
                 }
                 reader.ReadEndElement();
             }
             else
             {
                 reader.Skip();
             }
         }
         reader.ReadEndElement();
     }
 }
Example #8
0
        private Ingestion DeserializeEntityTypes(XElement element)
        {
            foreach (XElement entityElement in element.Elements())
            {
                CFEntityType entityType = new CFEntityType();
                entityType.Id = entityElement.Attribute("id") == null ? 0 : int.Parse(entityElement.Attribute("id").Value);

                foreach (XElement child in entityElement.Elements())
                {
                    string name = child.Name.LocalName;

                    if (name == "name")
                    {
                        entityType.Name = child.Value;
                    }
                    else if (name == "description")
                    {
                        entityType.Description = child.Value;
                    }
                    else if (name == "target-type")
                    {
                        entityType.TargetTypes = child.Value;
                    }
                    else if (name == "metadata-sets")
                    {
                        foreach (XElement metadata in child.Elements())
                        {
                            if (metadata.Name.LocalName == "metadata-set")
                            {
                                //MetadataSet set = MetadataSets.Where(m => m.Guid == metadata.Attribute("ref").Value).FirstOrDefault();
                                //if (set == null)
                                //{
                                CFMetadataSet set = new CFMetadataSet();
                                set.Guid = metadata.Attribute("ref").Value;
                                set.Id   = -1;
                                //}

                                entityType.MetadataSets.Add(set);

                                foreach (XElement attrElement in metadata.Elements())
                                {
                                    if (attrElement.Name.LocalName == "attribute-mapping")
                                    {
                                        CFEntityTypeAttributeMapping mapping = new CFEntityTypeAttributeMapping();
                                        mapping.MetadataSet = set;

                                        foreach (XElement attrChild in attrElement.Elements())
                                        {
                                            string attrName = attrChild.Name.LocalName;
                                            if (attrName == "name")
                                            {
                                                mapping.Name = attrChild.Value;
                                            }
                                            else if (attrName == "field-name")
                                            {
                                                mapping.FieldName = attrChild.Value;
                                            }
                                            else if (attrName == "label")
                                            {
                                                //When we implement the new mappings in a later sprint, we will need this field.
                                            }
                                        }

                                        entityType.AttributeMappings.Add(mapping);
                                    }
                                }
                            }
                        }
                    }
                }

                EntityTypes.Add(entityType);
            }

            return(this);
        }
Example #9
0
        protected override void LoadMetaData()
        {
            EntityMetadata meta;

            meta = new EntityMetadata()
            {
                EntityType = typeof(Actor), Container = Actors
            };
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Actor)e).User));
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Actor)e).Room));
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Actor)e).ClassTemplate));
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Actor)e).RaceTemplate));
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => Actor.GenerateInsertCommand(c, (Actor)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => Actor.GenerateUpdateCommand(c, (Actor)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => Actor.GenerateDeleteCommand(c, (Actor)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(ClassTemplate), Container = ClassTemplates
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => ClassTemplate.GenerateInsertCommand(c, (ClassTemplate)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => ClassTemplate.GenerateUpdateCommand(c, (ClassTemplate)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => ClassTemplate.GenerateDeleteCommand(c, (ClassTemplate)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(Currency), Container = Currencies
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => Currency.GenerateInsertCommand(c, (Currency)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => Currency.GenerateUpdateCommand(c, (Currency)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => Currency.GenerateDeleteCommand(c, (Currency)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(Item), Container = Items
            };
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Item)e).ItemTemplate));
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Item)e).Actor));
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Item)e).Room));
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => Item.GenerateInsertCommand(c, (Item)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => Item.GenerateUpdateCommand(c, (Item)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => Item.GenerateDeleteCommand(c, (Item)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(ItemTemplate), Container = ItemTemplates
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => ItemTemplate.GenerateInsertCommand(c, (ItemTemplate)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => ItemTemplate.GenerateUpdateCommand(c, (ItemTemplate)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => ItemTemplate.GenerateDeleteCommand(c, (ItemTemplate)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(RaceTemplate), Container = RaceTemplates
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => RaceTemplate.GenerateInsertCommand(c, (RaceTemplate)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => RaceTemplate.GenerateUpdateCommand(c, (RaceTemplate)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => RaceTemplate.GenerateDeleteCommand(c, (RaceTemplate)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(Region), Container = Regions
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => Region.GenerateInsertCommand(c, (Region)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => Region.GenerateUpdateCommand(c, (Region)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => Region.GenerateDeleteCommand(c, (Region)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(Room), Container = Rooms
            };
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Room)e).Region));
            meta.Relationships.Add(new EntityRelationship((IEntity e) => ((Room)e).TextBlock));
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => Room.GenerateInsertCommand(c, (Room)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => Room.GenerateUpdateCommand(c, (Room)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => Room.GenerateDeleteCommand(c, (Room)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(Setting), Container = Settings
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => Setting.GenerateInsertCommand(c, (Setting)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => Setting.GenerateUpdateCommand(c, (Setting)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => Setting.GenerateDeleteCommand(c, (Setting)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(TextBlock), Container = TextBlocks
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => TextBlock.GenerateInsertCommand(c, (TextBlock)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => TextBlock.GenerateUpdateCommand(c, (TextBlock)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => TextBlock.GenerateDeleteCommand(c, (TextBlock)e);
            EntityTypes.Add(meta);

            meta = new EntityMetadata()
            {
                EntityType = typeof(User), Container = Users
            };
            meta.GenerateInsertCommand = (SqlCommand c, IEntity e) => User.GenerateInsertCommand(c, (User)e);
            meta.GenerateUpdateCommand = (SqlCommand c, IEntity e) => User.GenerateUpdateCommand(c, (User)e);
            meta.GenerateDeleteCommand = (SqlCommand c, IEntity e) => User.GenerateDeleteCommand(c, (User)e);
            EntityTypes.Add(meta);

            this.LinkTypes.Add(RaceClassRestrictions);
        }