public static Dictionary <string, TypeInfoTS> GetEntities(IEnumerable <Type> allTypes) { var models = (from type in allTypes where typeof(ModelEntity).IsAssignableFrom(type) && !type.IsAbstract select type).ToList(); var queries = QueryLogic.Queries; var schema = Schema.Current; var settings = Schema.Current.Settings; var result = (from type in TypeLogic.TypeToEntity.Keys.Concat(models) where !type.IsEnumEntity() && !ReflectionServer.ExcludeTypes.Contains(type) let descOptions = LocalizedAssembly.GetDescriptionOptions(type) let allOperations = !type.IsEntity() ? null : OperationLogic.GetAllOperationInfos(type) select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS { Kind = KindOfType.Entity, FullName = type.FullName, NiceName = descOptions.HasFlag(DescriptionOptions.Description) ? type.NiceName() : null, NicePluralName = descOptions.HasFlag(DescriptionOptions.PluralDescription) ? type.NicePluralName() : null, Gender = descOptions.HasFlag(DescriptionOptions.Gender) ? type.GetGender().ToString() : null, EntityKind = type.IsIEntity() ? EntityKindCache.GetEntityKind(type) : (EntityKind?)null, EntityData = type.IsIEntity() ? EntityKindCache.GetEntityData(type) : (EntityData?)null, IsLowPopulation = type.IsIEntity() ? EntityKindCache.IsLowPopulation(type) : false, IsSystemVersioned = type.IsIEntity() ? schema.Table(type).SystemVersioned != null : false, ToStringFunction = typeof(Symbol).IsAssignableFrom(type) ? null : LambdaToJavascriptConverter.ToJavascript(ExpressionCleaner.GetFieldExpansion(type, miToString)), QueryDefined = queries.QueryDefined(type), Members = PropertyRoute.GenerateRoutes(type).Where(pr => InTypeScript(pr)) .ToDictionary(p => p.PropertyString(), p => { var mi = new MemberInfoTS { NiceName = p.PropertyInfo?.NiceName(), TypeNiceName = GetTypeNiceName(p.PropertyInfo?.PropertyType), Format = p.PropertyRouteType == PropertyRouteType.FieldOrProperty ? Reflector.FormatString(p) : null, IsReadOnly = !IsId(p) && (p.PropertyInfo?.IsReadOnly() ?? false), Unit = UnitAttribute.GetTranslation(p.PropertyInfo?.GetCustomAttribute <UnitAttribute>()?.UnitName), Type = new TypeReferenceTS(IsId(p) ? PrimaryKey.Type(type).Nullify() : p.PropertyInfo?.PropertyType, p.Type.IsMList() ? p.Add("Item").TryGetImplementations() : p.TryGetImplementations()), IsMultiline = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.MultiLine ?? false, MaxLength = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.Max.DefaultToNull(-1), PreserveOrder = settings.FieldAttributes(p)?.OfType <PreserveOrderAttribute>().Any() ?? false, }; return(OnAddPropertyRouteExtension(mi, p)); }), Operations = allOperations == null ? null : allOperations.ToDictionary(oi => oi.OperationSymbol.Key, oi => OnAddOperationExtension(new OperationInfoTS(oi), oi, type)), RequiresEntityPack = allOperations != null && allOperations.Any(oi => oi.HasCanExecute != null), }, type))).ToDictionaryEx("entities"); return(result); }
static XElement GenerateField(PropertyInfo pi) { Type t = pi.PropertyType; Type lt = t.CleanType(); if (Reflector.IsIEntity(lt)) { if (EntityKindCache.IsLowPopulation(lt)) { return(new XElement(m + "EntityCombo", new XAttribute(m + "Common.Route", pi.Name))); } else { return(new XElement(m + "EntityLine", new XAttribute(m + "Common.Route", pi.Name))); } } if (t.IsEmbeddedEntity()) { return(new XElement(xmlns + "GroupBox", new XAttribute("Header", pi.Name), new XAttribute(m + "Common.Route", pi.Name), GenerateStackPanel(t))); } if (Reflector.IsMList(t)) { Type et = t.ElementType(); if (Reflector.IsIEntity(et.CleanType())) { return(new XElement(xmlns + "GroupBox", new XAttribute("Header", pi.Name), new XElement(m + "EntityList", new XAttribute(m + "Common.Route", pi.Name), new XAttribute("MaxHeight", "150")))); } if (et.IsEmbeddedEntity()) { return(new XElement(xmlns + "GroupBox", new XAttribute("Header", pi.Name), new XElement(xmlns + "Grid", new XElement(xmlns + "Grid.ColumnDefinitions", new XElement(xmlns + "ColumnDefinition", new XAttribute("Width", "*")), new XElement(xmlns + "ColumnDefinition", new XAttribute("Width", "*"))), new XElement(m + "EntityList", new XAttribute(m + "Common.Route", pi.Name), new XAttribute("ViewOnCreate", "False"), new XAttribute("Grid.Column", "0"), new XAttribute("MaxHeight", "150")), new XElement(m + "DataBorder", new XAttribute(m + "Common.Route", pi.Name + "/"), new XAttribute("Grid.Column", "1"), GenerateStackPanel(et))))); } return (new XElement(xmlns + "GroupBox", new XAttribute("Header", pi.Name), new XElement(xmlns + "ListBox", new XAttribute("ItemsSource", "{Binding " + pi.Name + "}")))); } return(new XElement(m + "ValueLine", new XAttribute(m + "Common.Route", pi.Name))); }
public static Control GetValueControl(QueryToken token, string bindingPath) { Type type = token.Type; if (type.IsLite()) { Implementations implementations = token.GetImplementations().Value; Type cleanType = Lite.Extract(type); if (EntityKindCache.IsLowPopulation(cleanType) && !implementations.IsByAll) { EntityCombo ec = new EntityCombo { Type = type, Implementations = implementations, }; ec.SetBinding(EntityCombo.EntityProperty, new Binding { Path = new PropertyPath(bindingPath), NotifyOnValidationError = true, ValidatesOnDataErrors = true, ValidatesOnExceptions = true, }); return(ec); } else { EntityLine el = new EntityLine { Type = type, Create = false, Implementations = implementations, }; el.SetBinding(EntityLine.EntityProperty, new Binding { Path = new PropertyPath(bindingPath), NotifyOnValidationError = true, ValidatesOnDataErrors = true, ValidatesOnExceptions = true }); return(el); } } else if (type.IsEmbeddedEntity()) { EntityLine el = new EntityLine { Type = type, Create = false, Autocomplete = false, Find = false, Implementations = null, }; el.SetBinding(EntityLine.EntityProperty, new Binding { Path = new PropertyPath(bindingPath), NotifyOnValidationError = true, ValidatesOnDataErrors = true, ValidatesOnExceptions = true }); return(el); } else { ValueLine vl = new ValueLine() { Type = type, Format = token.Format, UnitText = token.Unit, }; if (type.UnNullify().IsEnum) { vl.ItemSource = EnumEntity.GetValues(type.UnNullify()).PreAndNull(type.IsNullable()).ToObservableCollection(); } vl.SetBinding(ValueLine.ValueProperty, new Binding { Path = new PropertyPath(bindingPath), //odd NotifyOnValidationError = true, ValidatesOnDataErrors = true, ValidatesOnExceptions = true, Converter = Reflector.IsNumber(type) ? Converters.Identity : null, }); return(vl); } }
private static MvcHtmlString PrintValueField(HtmlHelper helper, Context parent, FilterOption filterOption) { var implementations = filterOption.Token.GetImplementations(); if (filterOption.Token.Type.IsLite()) { Lite <IEntity> lite = (Lite <IEntity>)Common.Convert(filterOption.Value, filterOption.Token.Type); if (lite != null && string.IsNullOrEmpty(lite.ToString())) { Database.FillToString(lite); } Type cleanType = Lite.Extract(filterOption.Token.Type); if (EntityKindCache.IsLowPopulation(cleanType) && !cleanType.IsInterface && !implementations.Value.IsByAll) { EntityCombo ec = new EntityCombo(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute()) { Implementations = implementations.Value, }; EntityBaseHelper.ConfigureEntityButtons(ec, filterOption.Token.Type.CleanType()); ec.FormGroupStyle = FormGroupStyle.None; ec.Create = false; ec.ReadOnly = filterOption.Frozen; return(EntityComboHelper.InternalEntityCombo(helper, ec)); } else { EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute()) { Implementations = implementations.Value, }; if (el.Implementations.Value.IsByAll) { el.Autocomplete = false; } EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType()); el.FormGroupStyle = FormGroupStyle.None; el.Create = false; el.ReadOnly = filterOption.Frozen; return(EntityLineHelper.InternalEntityLine(helper, el)); } } else if (filterOption.Token.Type.IsEmbeddedEntity()) { EmbeddedEntity lite = (EmbeddedEntity)Common.Convert(filterOption.Value, filterOption.Token.Type); EntityLine el = new EntityLine(filterOption.Token.Type, lite, parent, "", filterOption.Token.GetPropertyRoute()) { Implementations = null, Autocomplete = false, }; EntityBaseHelper.ConfigureEntityButtons(el, filterOption.Token.Type.CleanType()); el.FormGroupStyle = FormGroupStyle.None; el.Create = false; el.ReadOnly = filterOption.Frozen; return(EntityLineHelper.InternalEntityLine(helper, el)); } else { var vl = new ValueLine(filterOption.Token.Type, filterOption.Value, parent, "", filterOption.Token.GetPropertyRoute()) { FormGroupStyle = FormGroupStyle.None, ReadOnly = filterOption.Frozen, Format = filterOption.Token.Format, UnitText = filterOption.Token.Unit, }; if (filterOption.Token.Type.UnNullify().IsEnum) { vl.EnumComboItems = ValueLine.CreateComboItems(EnumEntity.GetValues(vl.Type.UnNullify()), vl.UntypedValue == null || vl.Type.IsNullable()); } return(ValueLineHelper.ValueLine(helper, vl)); } throw new InvalidOperationException("Invalid filter for type {0}".FormatWith(filterOption.Token.Type.Name)); }