public TypeHelpTS GetTypeHelp(string typeName, TypeHelpMode mode) { Type type = TypeLogic.TryGetType(typeName); if (type == null) { return(null); } var isEnum = EnumEntity.IsEnumEntity(type); var members = new List <TypeMemberHelpTS>(); if (isEnum) { var enumType = EnumEntity.Extract(type); var values = EnumEntity.GetValues(enumType).ToList(); members.AddRange(values.Select(ev => new TypeMemberHelpTS(ev))); } else { var routes = PropertyRoute.GenerateRoutes(type); var root = TreeHelper.ToTreeC(routes, a => a.Parent).SingleEx(); members = root.Children .Where(a => mode == TypeHelpMode.CSharp || ReflectionServer.InTypeScript(a.Value)) .Select(pr => new TypeMemberHelpTS(pr, mode)).ToList(); if (mode == TypeHelpMode.CSharp) { var expressions = DynamicQueryManager.Current.RegisteredExtensions.GetValue(type); members.AddRange(expressions.Values.Select(ex => new TypeMemberHelpTS(ex))); } } return(new TypeHelpTS { type = (isEnum ? EnumEntity.Extract(type).Name : type.Name), cleanTypeName = typeName, isEnum = isEnum, members = members }); }
protected virtual ValueTuple[]? SugestedValues(QueryToken queryToken) { var ft = QueryUtils.GetFilterType(queryToken.Type); switch (ft) { case FilterType.Integer: case FilterType.Decimal: return(new[] { new ValueTuple { Value = Activator.CreateInstance(queryToken.Type.UnNullify()), Match = null } }); case FilterType.String: return(new[] { new ValueTuple { Value = "", Match = null } }); case FilterType.DateTime: return(new[] { new ValueTuple { Value = DateTime.Today, Match = null } }); case FilterType.Time: return(new[] { new ValueTuple { Value = TimeSpan.Zero, Match = null } }); case FilterType.Lite: case FilterType.Embedded: break; case FilterType.Boolean: return(new[] { new ValueTuple { Value = true, Match = null }, new ValueTuple { Value = false, Match = null } }); case FilterType.Enum: return(EnumEntity.GetValues(queryToken.Type.UnNullify()).Select(e => new ValueTuple { Value = e, Match = null }).ToArray()); case FilterType.Guid: break; } return(null); }
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)); }
protected virtual ValueTuple[] GetValues(QueryToken queryToken, OmniboxToken omniboxToken) { if (omniboxToken.IsNull()) { return new[] { new ValueTuple { Value = null, Match = null } } } ; var ft = QueryUtils.GetFilterType(queryToken.Type); switch (ft) { case FilterType.Integer: case FilterType.Decimal: if (omniboxToken.Type == OmniboxTokenType.Number) { if (ReflectionTools.TryParse(omniboxToken.Value, queryToken.Type, out object?result)) { return new[] { new ValueTuple { Value = result, Match = null } } } ; } break; case FilterType.String: if (omniboxToken.Type == OmniboxTokenType.String) { return new[] { new ValueTuple { Value = OmniboxUtils.CleanCommas(omniboxToken.Value), Match = null } } } ; break; case FilterType.DateTime: if (omniboxToken.Type == OmniboxTokenType.String) { var str = OmniboxUtils.CleanCommas(omniboxToken.Value); if (ReflectionTools.TryParse(str, queryToken.Type, out object?result)) { return new[] { new ValueTuple { Value = result, Match = null } } } ; } break; case FilterType.Lite: if (omniboxToken.Type == OmniboxTokenType.String) { var patten = OmniboxUtils.CleanCommas(omniboxToken.Value); var result = OmniboxParser.Manager.Autocomplete(queryToken.GetImplementations() !.Value, patten, AutoCompleteLimit); return(result.Select(lite => new ValueTuple { Value = lite, Match = OmniboxUtils.Contains(lite, lite.ToString(), patten) }).ToArray()); } else if (omniboxToken.Type == OmniboxTokenType.Entity) { var error = Lite.TryParseLite(omniboxToken.Value, out Lite <Entity>?lite); if (string.IsNullOrEmpty(error)) { return new [] { new ValueTuple { Value = lite } } } ; } else if (omniboxToken.Type == OmniboxTokenType.Number) { var imp = queryToken.GetImplementations() !.Value; if (!imp.IsByAll) { return(imp.Types.Select(t => CreateLite(t, omniboxToken.Value)) .NotNull().Select(t => new ValueTuple { Value = t }).ToArray()); } } break; case FilterType.Embedded: case FilterType.Boolean: bool?boolean = ParseBool(omniboxToken.Value); if (boolean.HasValue) { return new [] { new ValueTuple { Value = boolean.Value } } } ; break; case FilterType.Enum: if (omniboxToken.Type == OmniboxTokenType.String || omniboxToken.Type == OmniboxTokenType.Identifier) { string value = omniboxToken.Type == OmniboxTokenType.Identifier ? omniboxToken.Value : OmniboxUtils.CleanCommas(omniboxToken.Value); bool isPascalValue = OmniboxUtils.IsPascalCasePattern(value); Type enumType = queryToken.Type.UnNullify(); var dic = EnumEntity.GetValues(enumType).ToOmniboxPascalDictionary(a => a.NiceToString(), a => (object)a); var result = OmniboxUtils.Matches(dic, e => true, value, isPascalValue) .Select(m => new ValueTuple { Value = m.Value, Match = m }) .ToArray(); return(result); } break; case FilterType.Guid: if (omniboxToken.Type == OmniboxTokenType.Guid) { if (Guid.TryParse(omniboxToken.Value, out Guid result)) { return new[] { new ValueTuple { Value = result, Match = null } } } ; } else if (omniboxToken.Type == OmniboxTokenType.String) { var str = OmniboxUtils.CleanCommas(omniboxToken.Value); if (Guid.TryParse(str, out Guid result)) { return new[] { new ValueTuple { Value = result, Match = null } } } ; } break; default: break; } return(new[] { new ValueTuple { Value = UnknownValue, Match = null } }); } Lite <Entity>?CreateLite(Type type, string value) { if (PrimaryKey.TryParse(value, type, out PrimaryKey id)) { return(Lite.Create(type, id, "{0} {1}".FormatWith(type.NiceName(), id))); } return(null); } bool?ParseBool(string val) { val = val.ToLower().RemoveDiacritics(); if (val == "true" || val == "t" || val == "yes" || val == "y" || val == OmniboxMessage.Yes.NiceToString()) { return(true); } if (val == "false" || val == "f" || val == "no" || val == "n" || val == OmniboxMessage.No.NiceToString()) { return(false); } return(null); }