Exemple #1
0
        public override IEnumerable <HelpModuleOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
        {
            if (!OmniboxParser.Manager.AllowedPermission(HelpPermissions.ViewHelp))
            {
                yield break;
            }

            if (tokens.Count == 0 || !regex.IsMatch(tokenPattern))
            {
                yield break;
            }

            string key = tokens[0].Value;

            var keyMatch = OmniboxUtils.Contains(NiceName(), NiceName(), key) ?? OmniboxUtils.Contains("help", "help", key);

            if (keyMatch == null)
            {
                yield break;
            }

            if (tokenPattern == "I" && rawQuery.EndsWith(" "))
            {
                yield return(new HelpModuleOmniboxResult {
                    Distance = keyMatch.Distance, KeywordMatch = keyMatch, SecondMatch = null
                });

                yield break;
            }

            if (tokens.Count != 2)
            {
                yield break;
            }

            if (tokens[1].Type == OmniboxTokenType.String)
            {
                yield return(new HelpModuleOmniboxResult {
                    Distance = keyMatch.Distance, KeywordMatch = keyMatch, SearchString = tokens[1].Value.Trim('\'', '"')
                });

                yield break;
            }

            string pattern = tokens[1].Value;

            bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern);

            foreach (var match in OmniboxUtils.Matches(OmniboxParser.Manager.Types(), OmniboxParser.Manager.AllowedType, pattern, isPascalCase).OrderBy(ma => ma.Distance))
            {
                var type = (Type)match.Value;
                if (OmniboxParser.Manager.AllowedQuery(type))
                {
                    yield return(new HelpModuleOmniboxResult {
                        Distance = keyMatch.Distance + match.Distance, KeywordMatch = keyMatch, Type = type, SecondMatch = match
                    });
                }
            }
        }
Exemple #2
0
        public override IEnumerable <ChartOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
        {
            if (!OmniboxParser.Manager.AllowedPermission(ChartPermission.ViewCharting))
            {
                yield break;
            }

            Match m = regex.Match(tokenPattern);

            if (!m.Success)
            {
                yield break;
            }

            string key = tokens[0].Value;

            var keyMatch = OmniboxUtils.Contains(NiceName(), NiceName(), key);

            if (keyMatch == null)
            {
                yield break;
            }

            if (tokens.Count == 1)
            {
                yield return new ChartOmniboxResult {
                           Distance = keyMatch.Distance, KeywordMatch = keyMatch
                }
            }
            ;

            else
            {
                string pattern = tokens[1].Value;

                bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern);

                foreach (var match in OmniboxUtils.Matches(OmniboxParser.Manager.GetQueries(), OmniboxParser.Manager.AllowedQuery, pattern, isPascalCase).OrderBy(ma => ma.Distance))
                {
                    yield return(new ChartOmniboxResult
                    {
                        Distance = keyMatch.Distance + match.Distance,
                        KeywordMatch = keyMatch,
                        QueryName = match.Value,
                        QueryNameMatch = match
                    });
                }
            }
        }
Exemple #3
0
        public override IEnumerable <MapOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
        {
            if (!OmniboxParser.Manager.AllowedPermission(MapPermission.ViewMap))
            {
                yield break;
            }

            Match m = regex.Match(tokenPattern);

            if (!m.Success)
            {
                yield break;
            }

            string key = tokens[0].Value;

            var keyMatch = OmniboxUtils.Contains(NiceName(), NiceName(), key);

            if (keyMatch == null)
            {
                yield break;
            }

            if (tokens.Count == 1)
            {
                yield return new MapOmniboxResult {
                           Distance = keyMatch.Distance, KeywordMatch = keyMatch
                }
            }
            ;

            else
            {
                string pattern = tokens[1].Value;

                bool isPascalCase = OmniboxUtils.IsPascalCasePattern(pattern);

                var types = OmniboxParser.Manager.Types().Where(a => HasOperations(a.Value)).ToDictionary();

                foreach (var match in OmniboxUtils.Matches(types, OmniboxParser.Manager.AllowedType, pattern, isPascalCase).OrderBy(ma => ma.Distance))
                {
                    var type = match.Value;
                    yield return(new MapOmniboxResult {
                        Distance = keyMatch.Distance + match.Distance, KeywordMatch = keyMatch, Type = (Type)type, TypeMatch = match
                    });
                }
            }
        }
Exemple #4
0
        public override IEnumerable <UserQueryOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
        {
            if (tokenPattern != "S" || !OmniboxParser.Manager.AllowedPermission(UserQueryPermission.ViewUserQuery))
            {
                yield break;
            }

            string ident = OmniboxUtils.CleanCommas(tokens[0].Value);

            var userQueries = autoComplete(ident, AutoCompleteLimit);

            foreach (Lite <UserQueryEntity> uq in userQueries)
            {
                var match = OmniboxUtils.Contains(uq, uq.ToString(), ident);

                yield return(new UserQueryOmniboxResult
                {
                    ToStr = ident,
                    ToStrMatch = match,
                    Distance = match !.Distance,
                    UserQuery = (Lite <UserQueryEntity>)uq,
                });
    public override IEnumerable <DashboardOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
    {
        if (tokenPattern != "S" || !OmniboxParser.Manager.AllowedPermission(DashboardPermission.ViewDashboard))
        {
            yield break;
        }

        string ident = OmniboxUtils.CleanCommas(tokens[0].Value);

        var dashboard = autoComplete(ident, AutoCompleteLimit);

        foreach (var uq in dashboard)
        {
            var match = OmniboxUtils.Contains(uq, uq.ToString() !, ident) !;

            yield return(new DashboardOmniboxResult
            {
                ToStr = ident,
                ToStrMatch = match,
                Distance = match.Distance,
                Dashboard = (Lite <DashboardEntity>)uq,
            });
        }
    }
    public override IEnumerable <EntityOmniboxResult> GetResults(string rawQuery, List <OmniboxToken> tokens, string tokenPattern)
    {
        Match m = regex.Match(tokenPattern);

        if (!m.Success)
        {
            yield break;
        }

        string ident = tokens[0].Value;

        bool isPascalCase = OmniboxUtils.IsPascalCasePattern(ident);


        var matches = OmniboxUtils.Matches(OmniboxParser.Manager.Types(), OmniboxParser.Manager.AllowedType, ident, isPascalCase);

        if (tokens.Count == 1)
        {
            yield break;
        }
        else if (tokens[1].Type == OmniboxTokenType.Number || tokens[1].Type == OmniboxTokenType.Guid)
        {
            foreach (var match in matches.OrderBy(ma => ma.Distance))
            {
                Type type = (Type)match.Value;

                if (PrimaryKey.TryParse(tokens[1].Value, type, out PrimaryKey id))
                {
                    Lite <Entity>?lite = OmniboxParser.Manager.RetrieveLite(type, id);

                    yield return(new EntityOmniboxResult
                    {
                        Type = (Type)match.Value,
                        TypeMatch = match,
                        Id = id,
                        Lite = lite,
                        Distance = match.Distance,
                    });
                }
            }
        }
        else if (tokens[1].Type == OmniboxTokenType.String)
        {
            string pattern = OmniboxUtils.CleanCommas(tokens[1].Value);

            foreach (var match in matches.OrderBy(ma => ma.Distance))
            {
                var autoComplete = OmniboxParser.Manager.Autocomplete((Type)match.Value, pattern, AutoCompleteLimit);

                if (autoComplete.Any())
                {
                    foreach (Lite <Entity> lite in autoComplete)
                    {
                        OmniboxMatch?distance = OmniboxUtils.Contains(lite, lite.ToString() ?? "", pattern);

                        if (distance != null)
                        {
                            yield return new EntityOmniboxResult
                                   {
                                       Type       = (Type)match.Value,
                                       TypeMatch  = match,
                                       ToStr      = pattern,
                                       Lite       = lite,
                                       Distance   = match.Distance + distance.Distance,
                                       ToStrMatch = distance,
                                   }
                        }
                        ;
                    }
                }
                else
                {
                    yield return(new EntityOmniboxResult
                    {
                        Type = (Type)match.Value,
                        TypeMatch = match,
                        Distance = match.Distance + 100,
                        ToStr = pattern,
                    });
                }
            }
        }
    }
    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:
        case FilterType.Time:
            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;