private static void PopulateActiveRecordAttribute(ActiveRecordAttribute attribute, ActiveRecordModel model) { model.ActiveRecordAtt = attribute; if (attribute.DiscriminatorColumn != null) { model.IsDiscriminatorBase = true; if (attribute.DiscriminatorValue == null) { throw new ActiveRecordException( String.Format("You must specify a discriminator value for the type {0}", model.Type.FullName)); } } else if (attribute.DiscriminatorType != null) { throw new ActiveRecordException( String.Format("The usage of DiscriminatorType for {0} is meaningless", model.Type.FullName)); } if (model.ActiveRecordAtt.Table == null) { string safename = GetSafeName(model.Type.Name); model.ActiveRecordAtt.Table = ActiveRecordModel.pluralizeTableNames ? Inflector.Pluralize(safename) : safename; } }
/// <summary> /// Helper method to retrieve the physical table name from the entity metadata /// </summary> /// <param name="entity"></param> /// <returns></returns> private static string GetRealTableName(Type entity) { if (Attribute.IsDefined(entity, typeof(ActiveRecordAttribute))) { ActiveRecordAttribute attribute = (ActiveRecordAttribute)Attribute.GetCustomAttribute(entity, typeof(ActiveRecordAttribute)); return(attribute.Table); } return(string.Empty); }
protected void Page_Load(object sender, EventArgs e) { EntityPage entityPage = Page as EntityPage; if (entityPage != null) { Type entityType = Type.GetType(entityPage.EntityTypeName); object[] temp = entityType.GetCustomAttributes(true); object[] entityArAttributes = entityType.GetCustomAttributes(typeof(ActiveRecordAttribute), true); if (entityArAttributes.Length > 0) { ActiveRecordAttribute arAttribute = (ActiveRecordAttribute)entityArAttributes[0]; EntityDisplayName = arAttribute.Table; KeyAlias = GroupInfo.GetTableKeyField(arAttribute.Table); ColumnAlias = KeyAlias; ColumnDisplayName = KeyAlias; } EntityDisplayName = entityType.GetPluralDisplayName(); object[] entityDisplayAttributes = entityType.GetCustomAttributes(typeof(DisplayValuePropertyNameAttribute), true); if (entityDisplayAttributes.Length > 0) { DisplayValuePropertyNameAttribute displayAttribute = (DisplayValuePropertyNameAttribute)entityDisplayAttributes[0]; PropertyInfo displayProperty = entityType.GetProperty(displayAttribute.PropertyName); if (displayProperty != null) { object[] propertyAttributes = displayProperty.GetCustomAttributes(typeof(FieldAttribute), true); if (propertyAttributes.Length > 0) { FieldAttribute fieldAttribute = (FieldAttribute)propertyAttributes[0]; ColumnAlias = fieldAttribute.Field.ToUpper(); ColumnDisplayName = fieldAttribute.Field.ToUpper(); } } } } StringBuilder resources = new StringBuilder(); resources.AppendFormat("Sage.TaskPane.GroupListTasklet.Resources = {0};", JsonConvert.SerializeObject(new ClientResourcesRepresentation(this))); ScriptManager.RegisterStartupScript(Page, typeof(Page), "taskpane-grouplist-resources", resources.ToString(), true); /* * ScriptManager.RegisterClientScriptInclude(Page, typeof(Control), "Ext_BufferedGridView", ResolveUrl("~/Libraries/Ext3/ux/widgets/grid/BufferedGridView.js")); * ScriptManager.RegisterClientScriptInclude(Page, typeof(Control), "Ext_BufferedRowSelectionModel", ResolveUrl("~/Libraries/Ext3/ux/widgets/grid/BufferedRowSelectionModel.js")); * ScriptManager.RegisterClientScriptInclude(Page, typeof(Control), "Ext_BufferedStore", ResolveUrl("~/Libraries/Ext3/ux/widgets/grid/BufferedStore.js")); * ScriptManager.RegisterClientScriptInclude(Page, typeof(Control), "Ext_BufferedGridToolbar", ResolveUrl("~/Libraries/Ext3/ux/widgets/BufferedGridToolbar.js")); * ScriptManager.RegisterClientScriptInclude(Page, typeof(Control), "Ext_BufferedJsonReader", ResolveUrl("~/Libraries/Ext3/ux/data/BufferedJsonReader.js")); */ }
private void LoadIndexes() { if ((_Indexes == null) || (_Indexes.Count == 0)) { IRepository <IIndexDefinition> rep = EntityFactory.GetRepository <IIndexDefinition>(); IQueryable qry = (IQueryable)rep; IExpressionFactory ef = qry.GetExpressionFactory(); ICriteria crit = qry.CreateCriteria(); IExpression accessExp = ef.Le("UserAccess", _UserType); crit.Add(ef.And(accessExp, ef.Eq("Enabled", true))); crit.AddOrder(ef.Asc("IndexName")); IList <IIndexDefinition> tempIndexes = crit.List <IIndexDefinition>(); //c.Add(NHibernate.Expression.Expression.Eq("Enabled", true)); //c.Add(Expression.Le("UserAccess", _UserType)); //c.AddOrder(Order.Asc("IndexName")); //List<IndexDefinition> tempIndexes = (List<IndexDefinition>)c.List<IndexDefinition>(); Assembly interfaceAsm = Assembly.GetAssembly(typeof(IIndexDefinition)); Type[] types = interfaceAsm.GetTypes(); _TablesEntities = new Dictionary <string, Type>(); foreach (Type entity in types) { AttributeCollection attrs = TypeDescriptor.GetAttributes(entity); foreach (Attribute attr in attrs) { ActiveRecordAttribute activeRecord = attr as ActiveRecordAttribute; if (activeRecord != null) { _TablesEntities.Add(activeRecord.Table.ToUpper(), entity); } } } _Indexes = new List <IIndexDefinition>(); foreach (IIndexDefinition index in tempIndexes) { if (index.Type == 1) // database index { DBIndexDefinition dbid = DBIndexDefinition.SetFromString(index.MetaData); if (_TablesEntities.ContainsKey(dbid.MainTable.ToUpper())) { _Indexes.Add(index); } } else { _Indexes.Add(index); } } } }
private static void ProcessActiveRecordAttribute(Type type, ActiveRecordModel model) { object[] attrs = type.GetCustomAttributes(typeof(ActiveRecordAttribute), false); if (attrs.Length == 0) { throw new ActiveRecordException( String.Format("Type {0} is not using the ActiveRecordAttribute, which is obligatory.", type.FullName)); } ActiveRecordAttribute arAttribute = attrs[0] as ActiveRecordAttribute; PopulateActiveRecordAttribute(arAttribute, model); }
protected void Page_Load(object sender, EventArgs e) { EntityPage entityPage = Page as EntityPage; if (entityPage != null) { Type entityType = Type.GetType(entityPage.EntityTypeName, true); object[] temp = entityType.GetCustomAttributes(true); object[] entityArAttributes = entityType.GetCustomAttributes(typeof(ActiveRecordAttribute), true); if (entityArAttributes.Length > 0) { ActiveRecordAttribute arAttribute = (ActiveRecordAttribute)entityArAttributes[0]; EntityDisplayName = arAttribute.Table; KeyAlias = GroupInfo.GetTableKeyField(arAttribute.Table); ColumnAlias = KeyAlias; ColumnDisplayName = KeyAlias; } EntityDisplayName = entityType.GetPluralDisplayName(); object[] entityDisplayAttributes = entityType.GetCustomAttributes(typeof(DisplayValuePropertyNameAttribute), true); if (entityDisplayAttributes.Length > 0) { DisplayValuePropertyNameAttribute displayAttribute = (DisplayValuePropertyNameAttribute)entityDisplayAttributes[0]; PropertyInfo displayProperty = entityType.GetProperty(displayAttribute.PropertyName); if (displayProperty != null) { object[] propertyAttributes = displayProperty.GetCustomAttributes(typeof(FieldAttribute), true); if (propertyAttributes.Length > 0) { FieldAttribute fieldAttribute = (FieldAttribute)propertyAttributes[0]; ColumnAlias = fieldAttribute.Field.ToUpper(); ColumnDisplayName = fieldAttribute.Field.ToUpper(); } } } } }
private static bool ShouldCheckBase(Type type) { // Changed as suggested http://support.castleproject.org/jira/browse/AR-40 bool shouldCheck = IsRootType(type); if (shouldCheck) // Perform more checks { Type basetype = type.BaseType; while (basetype != typeof(object)) { if (basetype.IsDefined(typeof(JoinedBaseAttribute), false)) { return(false); } object[] attrs = basetype.GetCustomAttributes(typeof(ActiveRecordAttribute), false); if (attrs.Length != 0) { ActiveRecordAttribute arAttribute = attrs[0] as ActiveRecordAttribute; if (arAttribute.DiscriminatorColumn != null) { return(false); } } else { return(true); } basetype = basetype.BaseType; } } return(shouldCheck); }