예제 #1
0
        private async Task <IResponse> Suggest(IRequestContext ctx, Route route)
        {
            NameValueCollection p = await ParametersFromQueryStringAndBody(ctx);

            string     query         = p["q"];
            string     selectedTable = p["t"];
            IPrincipal user          = ctx.Request.User;

            IntelliSenseResult result = null;

            using (ctx.Monitor(MonitorEventLevel.Verbose, "Suggest", type: "Suggest", detail: query))
            {
                // Get all available tables
                List <Table> tables = new List <Table>();
                foreach (string tableName in this.Database.TableNames)
                {
                    if (this.HasTableAccess(tableName, user, PermissionScope.Reader))
                    {
                        if (String.IsNullOrEmpty(selectedTable) || selectedTable.Equals(tableName, StringComparison.OrdinalIgnoreCase))
                        {
                            tables.Add(this.Database[tableName]);
                        }
                    }
                }

                // Get IntelliSense results and return
                QueryIntelliSense qi = new QueryIntelliSense();
                result = qi.GetIntelliSenseItems(query, tables);
            }

            return(ArribaResponse.Ok(result));
        }
예제 #2
0
        private static string ItemsAndCounts(IntelliSenseResult result)
        {
            StringBuilder output = new StringBuilder();

            foreach (IntelliSenseItem item in result.Suggestions)
            {
                if (output.Length > 0)
                {
                    output.Append(", ");
                }
                output.Append($"{item.Display} {item.Hint}");
            }
            return(output.ToString());
        }
예제 #3
0
        private string CompleteEachKeystroke(string fullQuery)
        {
            QueryIntelliSense  qi     = new QueryIntelliSense();
            string             query  = "";
            IntelliSenseResult result = qi.GetIntelliSenseItems(query, this.Tables);

            foreach (char c in fullQuery)
            {
                if (result.CompletionCharacters.Contains(c))
                {
                    query = qi.CompleteQuery(query, result, (result.Suggestions.Count > 0 ? result.Suggestions[0] : null), c);
                }
                else
                {
                    query += c;
                }

                result = qi.GetIntelliSenseItems(query, this.Tables);
            }

            return(query);
        }