public void BuildMetadata() { var classes = typeof(T).Assembly.GetTypes().Where(t => t.GetCustomAttributes(typeof(MetaEntityAttribute), true).Length > 0); var maxEntityId = 1; var maxFieldId = 1; foreach (var type in classes) { var metaEntityAttribute = type.GetCustomAttributes(typeof(MetaEntityAttribute), true).FirstOrDefault() as MetaEntityAttribute; var metaEntity = new MetaEntity { Id = maxEntityId, Name = type.Name, DisplayName = metaEntityAttribute.DisplayName }; foreach (var property in type.GetProperties()) { var metaField = new MetaEntityField { Id = maxFieldId, Name = property.Name, DisplayName = property.Name, Type = GetDataType(property), Editable = EditableType.Editable, Visible = true, MetaEntityId = metaEntity.Id, Entity = metaEntity }; foreach (var attribute in property.GetCustomAttributes(typeof(MetaAttribute), true)) { switch (attribute) { case DisplayAttribute da: metaField.DisplayName = da.DisplayName; break; case EditableAttribute ea: metaField.Editable = ea.Editable; break; case VisibleAttribute va: metaField.Visible = va.Visible; break; default: throw new Exception("Meta attribute not supported"); } } Fields.Add(metaField); maxFieldId++; } Entities.Add(metaEntity); maxEntityId++; } }
public override void VisitEntity(MetaEntity entity) { foreach (var convention in _entityConventions) { convention.Apply(entity); } }
public static MetaEntity GetMeta(int id) { DataTable tbl = new DataTable(); string key = String.Format("GetMeta__{0}", id); MetaEntity ce = Utils.GetFromCache <MetaEntity>(key); if (ce == default(MetaEntity) || ce == null) { using (MainDB db = new MainDB()) { tbl = db.StoredProcedures.GetMetaByID(id); } ce = new MetaEntity(); if (tbl != null && tbl.Rows.Count > 0) { DataRow row = tbl.Rows[0]; ce.Description = Utils.GetObj <string>(row["Description"]); ce.Keyword = Utils.GetObj <string>(row["Keywords"]); } Utils.SaveToCacheDependency(TableName.DATABASE_NAME, TableName.META, key, ce); } if (ce == null) { ce = new MetaEntity(); } return(ce); }
private IConformistHoldersProvider GetEntityClassMapping(MetaEntity entityInfo) { var classMappingType = typeof(EntityMappingClass <>).MakeGenericType(entityInfo.ClrType); var classMapping = _services.GetService(classMappingType) as IConformistHoldersProvider; return(classMapping); }
public void Refresh_Employee_From_Cache_Populated() { DB.Prepare(); using (var repo = Repo.Create()) { var id = DB.Employees[0].Id; ConsoleEx.WriteLine("\n\n- Populating cache..."); var list = repo.Query <Employee>().ToList(); Assert.AreEqual(DB.Employees.Count, list.Count); var root = list.FirstOrDefault(x => x.Id == id); Assert.IsNotNull(root); ConsoleEx.WriteLine("\n\n- Refreshing a new instance..."); var obj = new Employee() { Id = id }; var temp = repo.RefreshNow(obj); var metaObj = MetaEntity.Locate(obj); ConsoleEx.WriteLine("\n> Implicit: {0}", metaObj); var metaTemp = MetaEntity.Locate(temp); ConsoleEx.WriteLine("\n> Returned: {0}", metaTemp); Assert.IsNotNull(temp); Assert.IsNotNull(metaTemp.Map); Assert.IsNotNull(metaObj.Map); // Validanting the new one is also refreshed... Assert.AreEqual(root.FirstName, obj.FirstName); Assert.AreEqual(root.LastName, obj.LastName); } }
public override void MapField(ICustomizersHolder customizerHolder, IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder, PropertyPath currentPropertyPath, MetaEntity entity, MetaField property) { var o2mProperty = property as OneToManyMetaField; var refEntity = _entityManager.GetEntity(o2mProperty.RefEntityName); var refProperty = refEntity.Fields[o2mProperty.MappedByFieldName]; var bagMappingAction = new Action <IBagPropertiesMapper>(mapper => { mapper.Inverse(true); mapper.Key(keyMapper => { keyMapper.Column(property.DbName); }); }); var o2mMappingAction = new Action <IOneToManyMapper>(mapper => { mapper.Class(refEntity.ClrType); }); var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo); customizerHolder.AddCustomizer(next, o2mMappingAction); customizerHolder.AddCustomizer(next, bagMappingAction); modelExplicitDeclarationsHolder.AddAsOneToManyRelation(property.ClrPropertyInfo); modelExplicitDeclarationsHolder.AddAsBag(property.ClrPropertyInfo); }
public void DeploySetters(Object output, MetaEntity entity, TypedObjectProvider provider) { foreach (TypePropertyMapItem item in provider.items) { if (item.metaProperty == null) { } else { MetaPropertySetter setter = entity.GetSetter(item.metaProperty.PropertyName); if (setter != null) { Object setterValue = setter.Value; if (setterValue != null) { if (item.converter != null) { setterValue = item.converter.Convert(setterValue); } SetPropertyValue(item.metaProperty, item.propertyInfo, setterValue, output, true); } } } } }
public override void MapField(ICustomizersHolder customizerHolder, IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder, PropertyPath currentPropertyPath, MetaEntity entity, MetaField property) { var m2mProperty = property as ManyToManyMetaField; var refEntity = _entityManager.GetEntity(m2mProperty.RefEntityName); var refProperty = refEntity.Fields[m2mProperty.MappedByFieldName]; var joinTableThisSideFkColumn = _nameConvention.EntityFieldToColumn(entity.Name.Split('.').Last() + "Id"); var joinTableOtherSideFkColumn = _nameConvention.EntityFieldToColumn(refEntity.Name.Split('.').Last() + "Id"); var bagMappingAction = new Action <IBagPropertiesMapper>(mapper => { mapper.Table(m2mProperty.JoinTable); mapper.Key(keyMapper => { keyMapper.Column(joinTableThisSideFkColumn); keyMapper.NotNullable(true); }); }); var m2mMappingAction = new Action <IManyToManyMapper>(mapper => { mapper.Class(refEntity.ClrType); mapper.Column(joinTableOtherSideFkColumn); }); var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo); customizerHolder.AddCustomizer(next, m2mMappingAction); customizerHolder.AddCustomizer(next, bagMappingAction); modelExplicitDeclarationsHolder.AddAsManyToManyItemRelation(property.ClrPropertyInfo); modelExplicitDeclarationsHolder.AddAsBag(property.ClrPropertyInfo); }
public override void MapField( ICustomizersHolder customizerHolder, IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder, PropertyPath currentPropertyPath, MetaEntity entity, MetaField field) { var primitiveProperty = (PrimitiveMetaField)field; var mappingAction = new Action <IPropertyMapper>(mapper => { if (field.MaxLength != null && field.MaxLength > 0) { mapper.Length(field.MaxLength.Value); } else { mapper.Type(NHibernateUtil.StringClob); } mapper.Column(field.DbName); mapper.Unique(field.IsUnique); mapper.Lazy(field.IsLazy); mapper.NotNullable(primitiveProperty.IsRequired); }); var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo); customizerHolder.AddCustomizer(next, mappingAction); modelExplicitDeclarationsHolder.AddAsProperty(field.ClrPropertyInfo); }
private FullTextSearchOptions GetFilterOptions(MetaEntity entity, bool isLookup) { return(new FullTextSearchOptions { Filter = (prop) => { var attr = entity?.FindAttribute(a => a.PropInfo == prop); if (attr == null) { return false; } #pragma warning disable CS0618 // Type or member is obsolete if (!attr.IsVisible || !attr.ShowOnView) #pragma warning restore CS0618 // Type or member is obsolete { return false; } if (isLookup && !attr.ShowInLookup && !attr.IsPrimaryKey) { return false; } return true; }, Depth = 0 }); }
/// <summary> /// Asserts that a parameter should has the value. /// </summary> /// <param name="metaEntity">The meta entity to assert.</param> /// <returns>The or constraint.</returns> public OrConstraint <MetaEntityAssertions> Be(MetaEntity metaEntity) { if (metaEntity == null) { throw new ArgumentNullException(nameof(metaEntity)); } return(Be(metaEntity.Meta)); }
public MetaEntity GetMeta() { MetaEntity meta = new MetaEntity(); meta.Title = Title; meta.CategoryId = CategoryId; meta.MetaValue = Value; return(meta); }
public void Save(MetaEntity meta) { if (meta == null) { throw new ArgumentNullException(nameof(meta)); } _metaDataProvider.Save(meta); }
protected virtual MetaEntityAttr CreateEntityAttribute(MetaEntity entity, IEntityType entityType, IProperty property) { var entityName = GetEntityNameByType(entityType); var propertyName = property.Name; var columnName = property.GetColumnName(); var entityAttr = Model.CreateEntityAttr(new MetaEntityAttrDescriptor(entity)); entityAttr.Id = DataUtils.ComposeKey(entityName, propertyName); entityAttr.Expr = columnName; entityAttr.Caption = propertyName; entityAttr.DataType = DataUtils.GetDataTypeBySystemType(property.ClrType); entityAttr.PropInfo = property.PropertyInfo; entityAttr.IsPrimaryKey = property.IsPrimaryKey(); entityAttr.IsForeignKey = property.IsForeignKey(); entityAttr.IsNullable = property.IsNullable; if (property.ClrType.IsEnum) { entityAttr.DisplayFormat = DataUtils.ComposeDisplayFormatForEnum(property.ClrType); } var propInfo = property.PropertyInfo; if (propInfo != null) { if (propInfo.GetCustomAttribute(typeof(DisplayAttribute)) is DisplayAttribute displayAttr) { entityAttr.Caption = displayAttr.Name; } else { entityAttr.Caption = DataUtils.PrettifyName(entityAttr.Caption); } var enabled = ApplyMetaEntityAttrAttribute(entityAttr, propInfo); if (!enabled) { return(null); } } if (entityAttr.DataType == DataType.Blob) { entityAttr.IsEditable = false; entityAttr.ShowOnView = false; entityAttr.ShowOnEdit = false; entityAttr.ShowOnCreate = false; } return(entityAttr); }
public GenericRestEntityRemoteService( ISafeRepository <TEntity> repository, ILogger <GenericRestEntityRemoteService <TEntity> > logger, IEntityManager entityManager) { this.Repository = repository; this.Logger = logger; this.EntityManager = entityManager; this.Entity = entityManager.GetEntityByClrType(typeof(TEntity)); }
public ImportingJob( ImportingJobDescriptor descriptor, IFeatureInfo feature, MetaEntity entity, IFileInfo importFileInfo) { this.Descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor)); this.IsSudo = this.Descriptor.IsSudo; this.Feature = feature ?? throw new ArgumentNullException(nameof(entity)); this.Entity = entity ?? throw new ArgumentNullException(nameof(entity)); this.ImportFileInfo = importFileInfo ?? throw new ArgumentNullException(nameof(importFileInfo)); }
// Use this for initialization void Start() { //get the time context _context = Contexts.sharedInstance.meta; //creating an entity to represent this MetaEntity e = _context.CreateEntity(); //add the appropriate listeners e.AddMenuStateListener(this); OnMenuState(e, MenuState.INTRO); }
public override object Apply(MetaEntity entity, bool isLookup, object data) { if (string.IsNullOrWhiteSpace(_filterText)) { return(data); } return(GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic) .Single(m => m.Name == "Apply" && m.IsGenericMethodDefinition) .MakeGenericMethod(entity.ClrType) .Invoke(this, new object[] { entity, isLookup, data })); }
public void Find_From_Cache_Clean() { DB.Prepare(); using (var repo = Repo.Create()) { var id = DB.Employees[0].Id; var obj = repo.FindNow <Employee>(x => x.Id == id); ConsoleEx.WriteLine("\n> Source: {0}", obj); Assert.IsNotNull(obj); Assert.IsNotNull(MetaEntity.Locate(obj).Map); } }
public override void Apply(MetaEntity entity) { var m2oFields = entity.Fields.Values .Where(x => x.Type is ManyToOneFieldType) .Select(x => (ManyToOneMetaField)x); foreach (var f in m2oFields) { if (!entity.DependentEntities.Contains(f.RefEntityName)) { entity.DependentEntities.Add(f.RefEntityName); } } }
public EntityMappingClass( IEnumerable <Fields.IFieldMapper> propertyMappers, IEntityManager entityManager) { _entityManager = entityManager; foreach (var pm in propertyMappers) { _propertyMappers.Add(pm.FieldTypeName, pm); } this.MetaEntity = entityManager.GetEntityByClrType(typeof(TEntity)); this.DoMapping(); }
public override void MapField(ICustomizersHolder customizerHolder, IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder, PropertyPath currentPropertyPath, MetaEntity entity, MetaField field) { var mappingAction = new Action <IClassMapper>(mapper => { mapper.Id(idMapper => { idMapper.Column(field.DbName); }); }); var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo); customizerHolder.AddCustomizer(field.ClrPropertyInfo.DeclaringType, mappingAction); modelExplicitDeclarationsHolder.AddAsPoid(field.ClrPropertyInfo); }
public override void MapField(ICustomizersHolder customizerHolder, IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder, PropertyPath currentPropertyPath, MetaEntity entity, MetaField property) { var m2oProperty = property as ManyToOneMetaField; var mappingAction = new Action <IManyToOneMapper>(mapper => { mapper.Column(property.DbName); mapper.NotNullable(m2oProperty.IsRequired); }); var next = new PropertyPath(currentPropertyPath, property.ClrPropertyInfo); customizerHolder.AddCustomizer(next, mappingAction); modelExplicitDeclarationsHolder.AddAsManyToOneRelation(property.ClrPropertyInfo); }
public override void Apply(MetaEntity metadata) { var keysToRemove = new List <string>(); foreach (var field in metadata.Fields) { if (field.Value.Attributes.Where(x => x.GetType() == typeof(NotFieldAttribute)).SingleOrDefault() != null) { keysToRemove.Add(field.Key); } } foreach (var key in keysToRemove) { metadata.Fields.Remove(key); } }
public void Attach_New_And_Detach() { using (var repo = Repo.Create()) { var reg = new Region() { Id = "000" }; repo.Attach(reg); var meta = MetaEntity.Locate(reg); Assert.IsNotNull(meta.Map); Assert.AreEqual(1, repo.Entities.Count()); repo.Detach(reg); Assert.IsNull(meta.Map); Assert.AreEqual(0, repo.Entities.Count()); } }
public string ReturnValue(MetaEntity obj, EA.Attribute l_Attr, EAPEnumeration en = null) { if (l_Attr.Default != null && (l_Attr.Default != "")) { if (!l_Attr.Default.StartsWith("0x", true, CultureInfo.InvariantCulture)) { return(l_Attr.Default); } else { string helpString = l_Attr.Default.Remove(0, 2).Trim(); try { long val = Convert.ToInt64(helpString, 16); return(val.ToString()); } catch { if (Validate) { if (en != null) { tw.WriteLine("Model Code for enum: {0},", en.Code); tw.WriteLine("Name for enum: {0},", en.Name); } else { tw.WriteLine("Model Code: {0},", obj.Code); } tw.WriteLine("Name: {0},", obj.Name); tw.WriteLine("Value Default {0},\n", l_Attr.Default); tw.WriteLine(l_Attr.Default + " value can not be converted in number."); tw.WriteLine("*************************************************************************"); tw.WriteLine("\n\n"); } } } } return(null); }
public override void MapField(ICustomizersHolder customizerHolder, IModelExplicitDeclarationsHolder modelExplicitDeclarationsHolder, PropertyPath currentPropertyPath, MetaEntity entity, MetaField field) { var genericHibernateEnumTypeType = typeof(global::NHibernate.Type.EnumStringType <>); var hibernateEnumTypeType = genericHibernateEnumTypeType.MakeGenericType(field.ClrPropertyInfo.PropertyType); var hibernateEnumType = Activator.CreateInstance(hibernateEnumTypeType) as IType; var primitiveField = (EnumerableMetaField)field; var mappingAction = new Action <global::NHibernate.Mapping.ByCode.IPropertyMapper>(mapper => { mapper.Column(field.DbName); mapper.Type(hibernateEnumType); mapper.NotNullable(primitiveField.IsRequired); }); var next = new PropertyPath(currentPropertyPath, field.ClrPropertyInfo); customizerHolder.AddCustomizer(next, mappingAction); modelExplicitDeclarationsHolder.AddAsProperty(field.ClrPropertyInfo); }
//public TypePropertyMap(Type _type, TaskPropertyDictionary schema, TypePropertyMapDefinition definition, IDataMiningTypeProvider typeProvider) //{ // type = _type; // typeProvider = typeProvider; // Dictionary<String, TypePropertyMapDefinitionItem> mappedProperties = new Dictionary<string, TypePropertyMapDefinitionItem>(); // Dictionary<MetaTablePropertyAliasEntry, PropertyInfo> reverseMap = new Dictionary<MetaTablePropertyAliasEntry, PropertyInfo>(); // MetaTablePropertyAliasList alist = new MetaTablePropertyAliasList(); // var prop = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); // List<TaskPropertyEntry> taskProperties = new List<TaskPropertyEntry>(); // foreach (TypePropertyMapDefinitionItem item in definition.items) // { // var pi = prop.FirstOrDefault(x => x.Name.Equals(item.typePropertyName)); // //if (item.IsUID) // //{ // // TypeUIDProperty = prop.FirstOrDefault(x => x.Name.Equals(item.typePropertyName, StringComparison.InvariantCultureIgnoreCase)); // // UIDMetaProperties.items.Add(item.metaPropertyNames); // //} // if (pi == null) // { // throw new Exception("Specified property name [" + item.typePropertyName + "] not found in type [" + type.Name + "]"); // } // alist.items.Add(item.metaPropertyNames); // taskProperties.AddRange(taskProperties.Where(x => item.metaPropertyNames.isMatch(x.propertyName))); // mappedProperties.Add(item.typePropertyName, item); // reverseMap.Add(item.metaPropertyNames, pi); // } // foreach (MetaTableProperty item in taskProperties.Select(x=>x.Meta)) // { // MetaTablePropertyAliasEntry a = alist.Match(item.PropertyName); // if (a != null) // { // var pi = reverseMap[a]; // propertyLinkABs.Add(item, pi); // propertyLinkBAs.Add(pi,item); // } // } // SetDefaultInstance(); //} /// <summary> /// Sets values from <see cref="MetaEntity.Setters"/> items of <c>MetaEntity</c> /// </summary> /// <param name="entity">The entity.</param> /// <param name="existing">The existing.</param> /// <param name="OverwriteExisting">if set to <c>true</c> [overwrite existing].</param> /// <returns></returns> public Object SetObjectByMetaEntitySetters(MetaEntity entity, Object existing = null, Boolean OverwriteExisting = true) { if (existing == null) { existing = type.getInstance(null); } foreach (KeyValuePair <MetaTableProperty, PropertyInfo> pair in propertyLinkABs) { MetaPropertySetter setter = entity.GetSetter(pair.Key.PropertyName); if (setter == null) { continue; } SetPropertyValue(pair.Key, pair.Value, setter.Value, existing, OverwriteExisting); } return(existing); }
public void Refresh_Employee_From_Cache_Clean() { DB.Prepare(); using (var repo = Repo.Create()) { var id = DB.Employees[0].Id; var obj = new Employee() { Id = id }; var temp = repo.RefreshNow(obj); var metaObj = MetaEntity.Locate(obj); ConsoleEx.WriteLine("\n> Implicit: {0}", metaObj); var metaTemp = MetaEntity.Locate(temp); ConsoleEx.WriteLine("\n> Returned: {0}", metaTemp); Assert.IsNotNull(temp); Assert.IsNotNull(metaTemp.Map); Assert.IsNotNull(metaObj.Map); } }
public void Refresh_Employee_From_Cache_Clean() { DB.Prepare(); using (var repo = Repo.Create()) { var id = DB.Employees[0].Id; var obj = new Employee() { Id = id }; var temp = repo.RefreshNow(obj); ConsoleEx.WriteLine("\n> Source: {0}", obj); ConsoleEx.WriteLine("\n> Refreshed: {0}", temp); ConsoleEx.WriteLine("\n> Are the same reference: {0}", object.ReferenceEquals(obj, temp)); Assert.IsNotNull(temp); Assert.IsNotNull(MetaEntity.Locate(temp).Map); Assert.IsNotNull(MetaEntity.Locate(obj).Map); } }