示例#1
0
        public QueryTokenTS(QueryToken qt, bool recursive)
        {
            this.toString        = qt.ToString();
            this.niceName        = qt.NiceName();
            this.key             = qt.Key;
            this.fullKey         = qt.FullKey();
            this.type            = new TypeReferenceTS(qt.Type, qt.GetImplementations());
            this.filterType      = QueryUtils.TryGetFilterType(qt.Type);
            this.format          = qt.Format;
            this.unit            = qt.Unit;
            this.typeColor       = qt.TypeColor;
            this.niceTypeName    = qt.NiceTypeName;
            this.queryTokenType  = GetQueryTokenType(qt);
            this.isGroupable     = qt.IsGroupable;
            this.hasOrderAdapter = QueryUtils.OrderAdapters.ContainsKey(qt.Type);

            this.preferEquals = qt.Type == typeof(string) &&
                                qt.GetPropertyRoute() is PropertyRoute pr &&
                                typeof(Entity).IsAssignableFrom(pr.RootType) &&
                                Schema.Current.HasSomeIndex(pr);

            this.propertyRoute = qt.GetPropertyRoute()?.ToString();
            if (recursive && qt.Parent != null)
            {
                this.parent = new QueryTokenTS(qt.Parent, recursive);
            }
        }
示例#2
0
    public static bool Compatible(QueryToken subQuery, QueryToken mainQuery)
    {
        if (subQuery.Type == mainQuery.Type)
        {
            return(true);
        }

        var subQueryImp  = subQuery.GetImplementations();
        var mainQueryImp = mainQuery.GetImplementations();

        if (subQueryImp == null || mainQueryImp == null)
        {
            return(false);
        }

        if (subQueryImp.Value.IsByAll || mainQueryImp.Value.IsByAll)
        {
            return(true);
        }

        if (subQueryImp.Value.Types.Intersect(mainQueryImp.Value.Types).Any())
        {
            return(true);
        }

        return(false);
    }
示例#3
0
    internal static MetaExpression FromToken(QueryToken token, Type sourceType)
    {
        var pr = token.GetPropertyRoute();

        if (pr == null)
        {
            return(new MetaExpression(sourceType, new DirtyMeta(token.GetImplementations(), Array.Empty <Meta>())));
        }

        if (!sourceType.IsLite() && pr.Type.IsLite())
        {
            return(new MetaExpression(sourceType, new CleanMeta(token.GetImplementations(), new[] { pr.Add("Entity") })));
        }

        return(new MetaExpression(sourceType, new CleanMeta(token.GetImplementations(), new[] { pr })));

        //throw new InvalidOperationException("Impossible to convert {0} to {1}".FormatWith(pr.Type.TypeName(), sourceType.TypeName()));
    }
示例#4
0
 public QueryTokenTS(QueryToken qt, bool recursive)
 {
     this.toString       = qt.ToString();
     this.niceName       = qt.NiceName();
     this.key            = qt.Key;
     this.fullKey        = qt.FullKey();
     this.type           = new TypeReferenceTS(qt.Type, qt.GetImplementations());
     this.filterType     = QueryUtils.TryGetFilterType(qt.Type);
     this.format         = qt.Format;
     this.unit           = qt.Unit;
     this.typeColor      = qt.TypeColor;
     this.niceTypeName   = qt.NiceTypeName;
     this.queryTokenType = GetQueryTokenType(qt);
     this.isGroupable    = qt.IsGroupable;
     this.propertyRoute  = qt.GetPropertyRoute()?.ToString();
     if (recursive && qt.Parent != null)
     {
         this.parent = new QueryTokenTS(qt.Parent, recursive);
     }
 }
示例#5
0
        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;
        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);
            }
        }
示例#7
0
        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;
            }
        }
示例#8
0
        internal static MetaExpression FromToken(QueryToken token, Type sourceType)
        {
            var pr = token.GetPropertyRoute();

            if (pr == null)
                return new MetaExpression(sourceType, new DirtyMeta(token.GetImplementations(), new Meta[0]));

            if (!sourceType.IsLite()  && pr.Type.IsLite())
                return new MetaExpression(sourceType, new CleanMeta(token.GetImplementations(), new[] { pr.Add("Entity") }));

            return new MetaExpression(sourceType, new CleanMeta(token.GetImplementations(), new[] { pr }));

            //throw new InvalidOperationException("Impossible to convert {0} to {1}".FormatWith(pr.Type.TypeName(), sourceType.TypeName()));
        }
        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);
        }
示例#10
0
 public QueryTokenTS(QueryToken qt, bool recursive)
 {
     this.toString = qt.ToString();
     this.niceName = qt.NiceName();
     this.key = qt.Key;
     this.fullKey = qt.FullKey();
     this.type = new TypeReferenceTS(qt.Type, qt.GetImplementations());
     this.filterType = QueryUtils.TryGetFilterType(qt.Type);
     this.format = qt.Format;
     this.unit = qt.Unit;
     this.typeColor = qt.TypeColor;
     this.niceTypeName = qt.NiceTypeName;
     this.queryTokenType = GetQueryTokenType(qt);
     this.isGroupable = qt.IsGroupable;
     this.propertyRoute = qt.GetPropertyRoute()?.ToString();
     if (recursive && qt.Parent != null)
         this.parent = new QueryTokenTS(qt.Parent, recursive);
 }