public IEnumerable <UIOMaticFilterPropertyInfo> GetFilterProperties(string typeName) { var ar = typeName.Split(','); var currentType = Type.GetType(ar[0] + ", " + ar[1]); foreach (var prop in currentType.GetProperties()) { var attris = prop.GetCustomAttributes(); if (attris.Any(x => x.GetType() == typeof(UIOMaticFilterFieldAttribute))) { var filter = (UIOMaticFilterFieldAttribute) attris.SingleOrDefault(x => x.GetType() == typeof(UIOMaticFilterFieldAttribute)); filter.DefaultValue = Helper.HandleDefaultValue(filter.DefaultValue); if (filter.DefaultToValue == "today") { filter.DefaultToValue = Helper.HandleDefaultValue(filter.DefaultToValue, 1); } else { filter.DefaultToValue = Helper.HandleDefaultValue(filter.DefaultToValue); } if (filter.ShowNumbers == 0) { filter.ShowNumbers = 1; } for (int i = 0; i < filter.ShowNumbers; i++) { if (attris.Any(x => x.GetType() == typeof(UIOMaticFieldAttribute))) { var attri = (UIOMaticFieldAttribute) attris.SingleOrDefault(x => x.GetType() == typeof(UIOMaticFieldAttribute)); var key = prop.Name; string view = attri.GetView(); if (prop.PropertyType == typeof(bool) && attri.View == "textfield") { view = "~/App_Plugins/UIOMatic/Backoffice/Views/checkbox.html"; } if (prop.PropertyType == typeof(DateTime) && attri.View == "textfield") { view = "~/App_Plugins/UIOMatic/Backoffice/Views/daterange.html"; } if ((prop.PropertyType == typeof(int) | prop.PropertyType == typeof(long)) && attri.View == "textfield") { view = "~/App_Plugins/UIOMatic/Backoffice/Views/number.html"; } var pi = new UIOMaticFilterPropertyInfo { Key = key, Name = attri.Name, Tab = string.IsNullOrEmpty(attri.Tab) ? "Misc" : attri.Tab, Description = attri.Description, View = IOHelper.ResolveUrl(view), Type = prop.PropertyType.ToString(), Config = string.IsNullOrEmpty(attri.Config) ? null : (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(attri.Config), OperatorID = "1" }; if (!string.IsNullOrWhiteSpace(filter.OperatorCode)) { pi.OperatorID = filter.OperatorCode; } if (!string.IsNullOrWhiteSpace(filter.DefaultValue)) { pi.Value = filter.DefaultValue; } if (!string.IsNullOrWhiteSpace(filter.DefaultToValue)) { pi.ToValue = filter.DefaultToValue; } yield return(pi); } else { var key = prop.Name; string view = "~/App_Plugins/UIOMatic/Backoffice/Views/textfield.html"; if (prop.PropertyType == typeof(bool)) { view = "~/App_Plugins/UIOMatic/Backoffice/Views/checkbox.html"; } if (prop.PropertyType == typeof(DateTime)) { view = "~/App_Plugins/UIOMatic/Backoffice/Views/daterange.html"; } if (prop.PropertyType == typeof(int) | prop.PropertyType == typeof(long)) { view = "~/App_Plugins/UIOMatic/Backoffice/Views/number.html"; } var pi = new UIOMaticFilterPropertyInfo { Key = key, Name = prop.Name, Tab = "Misc", Description = string.Empty, View = IOHelper.ResolveUrl(view), Type = prop.PropertyType.ToString(), OperatorID = "1" }; if (!string.IsNullOrWhiteSpace(filter.OperatorCode)) { pi.OperatorID = filter.OperatorCode; } if (!string.IsNullOrWhiteSpace(filter.DefaultValue)) { pi.Value = filter.DefaultValue; } if (!string.IsNullOrWhiteSpace(filter.DefaultToValue)) { pi.ToValue = filter.DefaultToValue; } yield return(pi); } } } } }
public UIOMaticTypeInfo GetTypeInfo(Type type, bool populateProperties = false) { // Types shouldn't change without an app pool recycle so might as well cache these return((UIOMaticTypeInfo)Umbraco.Web.Composing.Current.AppCaches.RuntimeCache.Get("PetaPocoObjectService_GetTypeInfo_" + type.AssemblyQualifiedName + "_" + populateProperties, () => { var attri = type.GetCustomAttribute <UIOMaticAttribute>(); var editableProperties = new List <UIOMaticEditablePropertyInfo>(); var listViewProperties = new List <UIOMaticViewablePropertyInfo>(); var listViewFilterProperties = new List <UIOMaticFilterPropertyInfo>(); var rawProperties = new List <UIOMaticPropertyInfo>(); var actions = new List <UIOMaticActionInfo>(); var nameFieldKey = ""; var dateCreatedFieldKey = ""; var dateModifiedFieldKey = ""; var props = type.GetProperties().ToArray(); foreach (var prop in props) { var attris = prop.GetCustomAttributes().ToArray(); // Get date created property key if (attris.Any(x => x.GetType() == typeof(UIOMaticDateCreatedAttribute))) { dateCreatedFieldKey = prop.Name; } // Get date modified property key if (attris.Any(x => x.GetType() == typeof(UIOMaticDateModifiedAttribute))) { dateModifiedFieldKey = prop.Name; } // Process properties if (populateProperties) { // Check for regular properties var attri2 = attris.FirstOrDefault(x => x.GetType() == typeof(UIOMaticFieldAttribute)) as UIOMaticFieldAttribute; if (attri2 != null) { var view = attri2.GetView(); // If field was left as textfield, see if we have a better match based on type if (attri2.View == "textfield") { if (prop.PropertyType == typeof(bool)) { view = Constants.FieldEditors.ViewPaths[Constants.FieldEditors.CheckBox]; } if (prop.PropertyType == typeof(DateTime)) { view = Constants.FieldEditors.ViewPaths[Constants.FieldEditors.DateTime]; } if (prop.PropertyType == typeof(int) || prop.PropertyType == typeof(long)) { view = Constants.FieldEditors.ViewPaths[Constants.FieldEditors.Number]; } } var pi = new UIOMaticEditablePropertyInfo { Key = prop.Name, Name = attri2.Name.IsNullOrWhiteSpace() ? prop.Name.ToSentenceCase() : attri2.Name, ColumnName = prop.GetColumnName(), Tab = attri2.Tab.IsNullOrWhiteSpace() ? "General" : attri2.Tab, TabOrder = attri2.TabOrder, Description = attri2.Description, View = IOHelper.ResolveUrl(view), Type = prop.PropertyType.ToString(), Config = attri2.Config.IsNullOrWhiteSpace() ? null : (JObject)JsonConvert.DeserializeObject(attri2.Config), Order = attri2.Order }; if (attri2.IsNameField) { nameFieldKey = prop.Name; } editableProperties.Add(pi); } else { //TODO: If someone needs to re-instate supporting non-attributed properties, logic to handle these should be added here } // Check for list view properties var attri3 = attris.FirstOrDefault(x => x.GetType() == typeof(UIOMaticListViewFieldAttribute)) as UIOMaticListViewFieldAttribute; if (attri3 != null) { var view = attri3.GetView(); // Handle custom views? var pi = new UIOMaticViewablePropertyInfo { Key = prop.Name, Name = attri3.Name.IsNullOrWhiteSpace() ? prop.Name : attri3.Name, ColumnName = prop.GetColumnName(), View = IOHelper.ResolveUrl(view), Type = prop.PropertyType.ToString(), Config = attri3.Config.IsNullOrWhiteSpace() ? null : (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(attri3.Config), Order = attri3.Order }; listViewProperties.Add(pi); } // Check for list view filter properties var attri4 = attris.FirstOrDefault(x => x.GetType() == typeof(UIOMaticListViewFilterAttribute)) as UIOMaticListViewFilterAttribute; if (attri4 != null) { var view = attri4.GetView(); var keyProp = attri4.KeyField.IsNullOrWhiteSpace() ? prop : props.FirstOrDefault(x => x.Name == attri4.KeyField); // Handle custom views? var pi = new UIOMaticFilterPropertyInfo { Key = prop.Name, Name = attri4.Name.IsNullOrWhiteSpace() ? prop.Name.ToSentenceCase() : attri4.Name, ColumnName = prop.GetColumnName(), KeyPropertyName = keyProp.Name, KeyColumnName = keyProp.GetColumnName(), View = IOHelper.ResolveUrl(view), Type = prop.PropertyType.ToString(), Config = attri4.Config.IsNullOrWhiteSpace() ? null : (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(attri4.Config), Order = attri4.Order }; listViewFilterProperties.Add(pi); } // Check for date/modified properties if (prop.GetCustomAttribute <UIOMaticDateCreatedAttribute>() != null) { dateCreatedFieldKey = prop.Name; } if (prop.GetCustomAttribute <UIOMaticDateModifiedAttribute>() != null) { dateModifiedFieldKey = prop.Name; } // Raw properties rawProperties.Add(new UIOMaticPropertyInfo { Key = prop.Name, Name = prop.Name, Type = prop.PropertyType.ToString() }); } } // Calculate the types path var path = new List <string>(new[] { attri.Alias, attri.ParentAlias }); var parentTypeAlias = attri.ParentAlias; while (parentTypeAlias != "-1") { var parentType = Helper.GetUIOMaticTypeByAlias(parentTypeAlias, includeFolders: true); if (parentType != null) { var parentAttri = parentType.GetCustomAttribute <UIOMaticFolderAttribute>(); parentTypeAlias = parentAttri.ParentAlias; } else { parentTypeAlias = "-1"; } path.Add(parentTypeAlias); } path.Reverse(); if (attri.ListViewActions != null) { foreach (var action in attri.ListViewActions) { var attri5 = action.GetCustomAttribute <UIOMaticActionAttribute>(); if (attri5 != null) { actions.Add(new UIOMaticActionInfo { Alias = attri5.Alias, Name = attri5.Name, View = IOHelper.ResolveUrl(attri5.View), Icon = attri5.Icon, Config = attri5.Config.IsNullOrWhiteSpace() ? null : (JObject)JsonConvert.DeserializeObject(attri5.Config), }); } } } return new UIOMaticTypeInfo { Alias = attri.Alias, DisplayNamePlural = attri.FolderName, DisplayNameSingular = attri.ItemName, FolderIcon = attri.FolderIcon, ItemIcon = attri.ItemIcon, Name = type.Name, TableName = type.GetTableName(), RenderType = attri.RenderType, PrimaryKeyColumnName = type.GetPrimaryKeyName(), AutoIncrementPrimaryKey = type.AutoIncrementPrimaryKey(), NameFieldKey = nameFieldKey, ReadOnly = attri.ReadOnly, EditableProperties = editableProperties.OrderBy(x => x.Order).ThenBy(x => x.Name).ToArray(), ListViewProperties = listViewProperties.OrderBy(x => x.Order).ThenBy(x => x.Name).ToArray(), ListViewFilterProperties = listViewFilterProperties.OrderBy(x => x.Order).ThenBy(x => x.Name).ToArray(), RawProperties = rawProperties.ToArray(), Path = path.ToArray(), Type = type, ListViewActions = actions.ToArray(), SortColumn = attri.SortColumn, SortOrder = attri.SortOrder, DateCreatedFieldKey = dateCreatedFieldKey, DateModifiedFieldKey = dateModifiedFieldKey }; })); }