public ActionResult ListEntries(string TypeName = "", Guid?Target = null, int count = 20, int page = 0) { bool typeSelected = !string.IsNullOrWhiteSpace(TypeName); IQueryable <AuditEntry> FilterQuery(IQueryable <AuditEntry> toQuery) { return(toQuery.Where(a => (!typeSelected || a.TypeName == TypeName) && (Target == null || a.Target == Target))); } MetaConstructor c = Constructor; PagedListContainer <IMetaObject> model = new PagedListContainer <IMetaObject> { TotalCount = FilterQuery(AuditEntryRepository.All).Count(), Page = page, Count = count }; model.Items.AddRange(FilterQuery(AuditEntryRepository.All).OrderByDescending(a => a.Logged).Skip(page * count).Take(count).ToList().Select(o => { MetaObject me = new MetaObject(o, c); me.Hydrate(); return(me); })); if (Target.HasValue) { model.HiddenColumns.Add(nameof(Target)); model.HiddenColumns.Add(nameof(TypeName)); } else if (!string.IsNullOrWhiteSpace(TypeName)) { model.HiddenColumns.Add(nameof(TypeName)); } return(this.View(model)); }
internal MetaType(MetaConstructor c) : this(c.Type) { Type type = c.Type; if (Nullable.GetUnderlyingType(type) != null) { type = Nullable.GetUnderlyingType(type); this.IsNullable = true; } this.Parameters = new List <MetaType>(); List <MetaAttribute> attributes = new List <MetaAttribute>(); this.Attributes = attributes; if (type.BaseType != null) { this.BaseType = MetaType.FromConstructor(c, type.BaseType); } if (this.CoreType == CoreType.Collection) { this.CollectionType = MetaType.FromConstructor(c, type.GetCollectionType()); } foreach (Type g in type.GetGenericArguments()) { this.Parameters.Add(MetaType.FromConstructor(c, g)); } if (c.Settings.AttributeIncludeSettings != AttributeIncludeSetting.None) { foreach (AttributeInstance a in TypeCache.GetCustomAttributes(type)) { if (c.Settings.ShouldAddAttribute(a.Instance.GetType())) { attributes.Add(MetaAttribute.FromConstructor(c, a, type)); } } } this.Properties = new List <MetaProperty>(); if (this.CoreType != CoreType.Value) { foreach (PropertyInfo thisProperty in c.GetProperties()) { if (c.Validate(thisProperty)) { this.Properties.Add(MetaProperty.FromConstructor(c, thisProperty)); } } } }
public AttributeWrapper(AttributeInstance a, RType t, MetaConstructor c) { this.Attribute = a; this.Type = t; if (!c.Cache.Attributes.ContainsKey(a.Instance)) { c.Cache.Attributes.Add(a.Instance, c.Cache.Attributes.Count); } this.Key = $"@{c.Cache.Attributes[a.Instance]}|{a.IsInherited}"; }
/// <summary> /// Create an instance using information found in the MetaConstructor /// </summary> /// <param name="c">The MetaConstructor to use</param> public MetaAttribute(MetaConstructor c) : base() { if (c is null) { throw new System.ArgumentNullException(nameof(c)); } this.Instance = MetaObject.FromConstructor(c, new ObjectConstructor(c.PropertyInfo, c.Type, (c.Object as AttributeInstance).Instance)); this.Type = MetaType.FromConstructor(c, (c.Object as AttributeInstance).Instance); this.IsInherited = (c.Object as AttributeInstance).IsInherited; }
public AttributeWrapper(AttributeInstance a, PropertyInfo p, MetaConstructor c) { this.PropertyInfo = p; this.Attribute = a; this.Type = p.DeclaringType; if (!c.Cache.Attributes.ContainsKey(a.Instance)) { c.Cache.Attributes.Add(a.Instance, c.Cache.Attributes.Count); } this.Key = $"@{c.Cache.Attributes[a.Instance]}|{a.IsInherited}"; }
public virtual ActionResult List(string type, int count = 20, int page = 0, string text = "") { System.Type listType = type is null ? typeof(T) : TypeFactory.GetTypeByFullName(type, typeof(object), false); MetaConstructor c = Constructor; DynamicListRenderPageModel model = new DynamicListRenderPageModel() { PagedList = this.GenerateList <IMetaObject>(listType, count, page, text, (o) => new MetaObjectHolder(o)), Type = type ?? string.Empty }; return(this.View(model)); }
/// <summary> /// Creates a new MetaType from a given object /// </summary> /// <param name="c">The constructor to use</param> /// <param name="o">The object to base the MetaType on</param> /// <returns>A new instance of MetaType</returns> public static MetaType FromConstructor(MetaConstructor c, object o) { if (c is null) { throw new ArgumentNullException(nameof(c)); } if (o is null) { throw new ArgumentNullException(nameof(o)); } return(FromConstructor(c, o.GetType())); }
/// <summary> /// Creates a serialized and gzipped version of a MetaObject /// </summary> /// <param name="o">The object to serialize and zip</param> /// <param name="c">The optional constructor to use</param> /// <returns>A byte[] containing the gzipped string from the serialized object</returns> public static byte[] MetaZip(object o, MetaConstructor c = null) { if (o is null) { return(null); } c = c ?? new MetaConstructor(); StringBuilder target = new StringBuilder(); new MetaObject(o, c).Serialize(target); return(Zip(target.ToString())); }
internal static MetaProperty FromConstructor(MetaConstructor c, PropertyInfo propertyInfo) { MetaProperty p; if (!c.Contains(propertyInfo)) { AbstractMeta placeHolder = c.Claim(propertyInfo); p = new MetaProperty(c.Clone(propertyInfo)) { I = placeHolder.I }; c.UpdateClaim(p, propertyInfo); } else { p = new MetaProperty(c.GetId(propertyInfo)); } return(p); }
internal MetaProperty(MetaConstructor c) : base() { this.Name = c.PropertyInfo.Name; this.Type = MetaType.FromConstructor(c, c.PropertyInfo.PropertyType); this.DeclaringType = MetaType.FromConstructor(c, c.PropertyInfo.DeclaringType); List <MetaAttribute> attributes = new List <MetaAttribute>(); this.Attributes = attributes; if (c.Settings.AttributeIncludeSettings != AttributeIncludeSetting.None) { foreach (AttributeInstance a in TypeCache.GetCustomAttributes(c.PropertyInfo)) { if (c.Settings.ShouldAddAttribute(a.Instance.GetType())) { attributes.Add(MetaAttribute.FromConstructor(c, a, c.PropertyInfo)); } } } }
// GET: Form public ActionResult ViewByName(string Name) { Form thisForm = this.FormRepository.GetByName(Name); if (thisForm is null) { return(this.Redirect("/Error/NotFound")); } if (thisForm.IsJsonForm) { return(this.View("ViewJsonForm", thisForm)); } else { MetaConstructor c = AdminController.Constructor; MetaObject mo = new MetaObject(thisForm, c); mo.Hydrate(); return(this.View("ViewForm", mo)); } }
internal static MetaAttribute FromConstructor(MetaConstructor c, AttributeWrapper wrapper) { MetaAttribute a; if (!c.Contains(wrapper)) { AbstractMeta placeHolder = c.Claim(wrapper); //Drop the type the attribute is declared on so we dont think we're trying to override the attribute.GetType() a = new MetaAttribute(c.Clone(new ObjectConstructor(wrapper.PropertyInfo, wrapper.Attribute.Instance.GetType(), wrapper.Attribute))) { I = placeHolder.I }; c.UpdateClaim(a, wrapper); } else { a = new MetaAttribute(c.GetId(wrapper)); } return(a); }
/// <summary> /// Creates a new MetaType from a given type /// </summary> /// <param name="c">The constructor to use</param> /// <param name="t">The type to base the MetaType on</param> /// <returns>A new instance of MetaType</returns> public static MetaType FromConstructor(MetaConstructor c, Type t) // Leave this public. Its used by the Reporting Type Serializer { if (c is null) { throw new ArgumentNullException(nameof(c)); } if (t is null) { throw new ArgumentNullException(nameof(t)); } string Name = t.Name; foreach (System.Func <Type, Type> typeOverride in c.Settings.TypeGetterOverride) { t = typeOverride.Invoke(t); } MetaType i; if (!c.Contains(t)) { AbstractMeta placeHolder = c.Claim(t); i = new MetaType(c.Clone(t)) { I = placeHolder.I }; c.UpdateClaim(i, t); i = new MetaType(c.GetId(t)); } else { i = new MetaType(c.GetId(t)); } return(i); }
public CaisisDynamicControlModifier(Type iCICType) { if (iCICType.GetInterface(typeof(ICaisisInputControl).Name) != null) { this.modifierType = iCICType; this.controlConstructor = CreateConstructorDelegate(iCICType); IEnumerable <PropertyInfo> propList = EnumerateTypeMemberHierarchy(iCICType); foreach (PropertyInfo prop in propList) { CaisisMetaDataField cicMetaProp = Attribute.GetCustomAttribute(prop, typeof(CaisisMetaDataField), true) as CaisisMetaDataField; string propKey = prop.Name; if (cicMetaProp != null && !controlGetterSetters.ContainsKey(propKey)) { CaisisDynamicPropertyModifier cfh = new CaisisDynamicPropertyModifier(iCICType, propKey); controlGetterSetters.Add(propKey, cfh); } } } else { string err = "Unable to create {0}, Type '{1}' must implement interface {2} and be marked with Attribute [{3}]."; throw new Exception(string.Format(err, this.GetType().Name, iCICType.Name, ReflectionManager.BaseInterfaceType.Name, ReflectionManager.InvokeableAttributeType.Name)); } }
private static MetaConstructor CreateConstructorDelegate(Type iCICType) { ConstructorInfo cInfo = null; if (iCICType.GetInterface(typeof(ICaisisInputControl).FullName) != null && !iCICType.IsInterface) { cInfo = iCICType.GetConstructor(new Type[] { }); } if (cInfo != null) { DynamicMethod creator = new DynamicMethod( String.Concat("_Creator", cInfo.DeclaringType.Name, "_"), typeof(ICaisisInputControl) , new Type[] { }, cInfo.DeclaringType); ILGenerator generator = creator.GetILGenerator(); generator.Emit(OpCodes.Newobj, cInfo); generator.Emit(OpCodes.Ret); MetaConstructor metaC = creator.CreateDelegate(typeof(MetaConstructor)) as MetaConstructor; return(metaC); } else { return(null); } }
/// <summary> /// Converts an IEnumerable to an IEnumerable of MetObjects /// </summary> /// <typeparam name="T">The type of the list to convert</typeparam> /// <param name="source">The source IEnumerable</param> /// <param name="c">A constructor to use during the generation</param> /// <param name="Hydrate">Should the return objects be hydrated?</param> /// <returns>And IEnumerable of converted objects</returns> public static IEnumerable <IMetaObject> ToMetaList <T>(this IEnumerable <T> source, MetaConstructor c, bool Hydrate = false) { if (source is null) { throw new System.ArgumentNullException(nameof(source)); } c = c ?? new MetaConstructor(); foreach (T o in source) { MetaObject m = new MetaObject(o, c); if (Hydrate) { m.Hydrate(); } yield return(m); } }
internal static MetaAttribute FromConstructor(MetaConstructor c, AttributeInstance o, RType t) { return(FromConstructor(c, new AttributeWrapper(o, t, c))); }
internal static MetaAttribute FromConstructor(MetaConstructor c, AttributeInstance o, PropertyInfo p) { return(FromConstructor(c, new AttributeWrapper(o, p, c))); }
public ActionResult StoredProcedure(string Name) { List <SQLParameterInfo> parameters = this.ReportingDatabase.GetParameters(Name); DbMetaObject toRender = parameters.ToMetaObject(); foreach (SQLParameterInfo thisParam in parameters) { ParameterInfo DBInstance = this.ReportingParameterRepository.GetByProcedureAndName(Name, thisParam.PARAMETER_NAME); System.Type netType = TypeConverter.ToNetType(thisParam.DATA_TYPE); if (DBInstance != null) { if (DBInstance.Default != null) { toRender[thisParam.PARAMETER_NAME].Value = this.GetParamConstraint(DBInstance.Default, netType); } if (DBInstance.MinValue is null) { throw new NullReferenceException("DbInstance MinValue can not be null"); } if (DBInstance.MaxValue is null) { throw new NullReferenceException("DbInstance MaxValue can not be null"); } if (DBInstance.MinValue.Enabled || DBInstance.MaxValue.Enabled) { string?Min = null; string?Max = null; if (DBInstance.MinValue.Enabled) { Min = this.GetParamConstraint(DBInstance.MinValue, netType); } if (DBInstance.MaxValue.Enabled) { Max = this.GetParamConstraint(DBInstance.MaxValue, netType); } RangeAttribute range = new RangeAttribute(netType, Min, Max); MetaConstructor c = new MetaConstructor(); DbMetaObject instance = new DbMetaObject() { Properties = new List <DbMetaObject>() { new DbMetaObject() { Value = range.Minimum.ToString(), Property = new DbMetaProperty() } } }; MetaAttributeHolder toAdd = new MetaAttributeHolder(range, false); instance.Type = toAdd.Type; List <IMetaAttribute> existingAttributes = toRender[thisParam.PARAMETER_NAME].Property.Attributes.ToList(); existingAttributes.Add(toAdd); toRender[thisParam.PARAMETER_NAME].Property.Attributes = existingAttributes; } } } StoredProcedureDisplayModel model = new StoredProcedureDisplayModel { Name = Name, Parameters = toRender, Optimized = parameters.Any(p => p.PARAMETER_NAME == "count") && parameters.Any(p => p.PARAMETER_NAME == "page") }; return(this.View(model)); }
/// <summary> /// Converts a List of SQL parameters into MetaObjects so that they can be serialized and displayed through a dynamic editor /// </summary> /// <param name="parameters">A List of Sql parameters to serialize</param> /// <param name="c">The optional MetaConstructor to use as a start, for caching</param> /// <returns>A MetaObject representing a collection of the serialized parameters</returns> public static DbMetaObject ToMetaObject(this IEnumerable <SQLParameterInfo> parameters, MetaConstructor c = null) { if (parameters is null) { throw new System.ArgumentNullException(nameof(parameters)); } DbMetaObject metaObject = new DbMetaObject(); c = c ?? new MetaConstructor(new MetaConstructorSettings() { AttributeIncludeSettings = AttributeIncludeSetting.All }); c.ClaimOwnership(metaObject); foreach (SQLParameterInfo thisParam in parameters) { DbMetaObject prop = thisParam.ToMetaObject(); metaObject.Properties.Add(prop); } metaObject.Type = new DbMetaType("SqlStoredProc", metaObject.Properties) { CoreType = CoreType.Reference }; return(metaObject); }
/// <summary> /// Implements the constructor: MetaConstructor() /// Direct superclasses: global::MetaDslx.Core.MetaNamedElement, global::MetaDslx.Core.MetaAnnotatedElement /// All superclasses: global::MetaDslx.Core.MetaNamedElement, global::MetaDslx.Core.MetaDocumentedElement, global::MetaDslx.Core.MetaAnnotatedElement /// </summary> public virtual void MetaConstructor(MetaConstructor @this) { this.MetaNamedElement(@this); this.MetaAnnotatedElement(@this); }
static MetaFactory() { // initialise with Standard Constructor Constructor = new MetaConstructor(); }