Esempio n. 1
0
        GetCompletionResponse IProvider.GetCompletion(ConnectionBase connection, IDbTransaction transaction, string text, int position)
        {
            var response = new GetCompletionResponse();

            string[]     values       = null;
            SqlStatement sqlStatement = new SqlStatement(text);

            Token[] tokens = sqlStatement.Tokens;

            if (tokens.Length > 0)
            {
                Token previousToken, currentToken;
                sqlStatement.FindToken(position, out previousToken, out currentToken);
                if (currentToken != null)
                {
                    response.StartPosition = currentToken.StartPosition;
                    response.Length        = currentToken.EndPosition - currentToken.StartPosition + 1;
                }
                else
                {
                    response.StartPosition = position;
                    response.Length        = 0;
                }

                if (previousToken != null)
                {
                    Token token = previousToken;

                    if (token.Type == TokenType.KeyWord && string.Compare(token.Value, "exec", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        var names = new List <string>();

                        foreach (var name in TfsDataReaderFactory.Dictionary.Keys)
                        {
                            names.Add(name);
                        }

                        values = names.ToArray();
                    }
                    else if (tokens.Length > 1)
                    {
                        token = tokens[0];

                        if (token.Type == TokenType.KeyWord && string.Compare(token.Value, "exec", StringComparison.InvariantCultureIgnoreCase) == 0)
                        {
                            //token = tokens[1];
                            //TfsDataReaderFactory.DataReaderInfo info;
                            //bool contains = TfsDataReaderFactory.Dictionary.TryGetValue(token.Value, out info);

                            //if (contains)
                            //{
                            //    TfsParameterCollection parameters = info.Parameters;
                            //    TfsParameter parameter = parameters[index - 2];
                            //    Type type = parameter.Type;

                            //    if (type.IsEnum)
                            //    {
                            //        string[] names = Enum.GetNames(type);
                            //        values = names;
                            //    }
                            //}
                            var command = sqlStatement.CreateCommand(this, connection, CommandType.StoredProcedure, 0);
                            TfsDataReaderFactory.DataReaderInfo info;
                            var contains = TfsDataReaderFactory.Dictionary.TryGetValue(command.CommandText, out info);
                            if (contains)
                            {
                                var parameters     = info.Parameters;
                                var parameterIndex = previousToken.Index / 2;
                                if (parameterIndex < parameters.Count)
                                {
                                    var parameter = parameters[parameterIndex];
                                    var type      = parameter.Type;
                                    if (type.IsEnum)
                                    {
                                        var names = Enum.GetNames(type);
                                        values = names;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            response.Items = values.Select(value => (IObjectName) new ObjectName(value)).ToList();
            return(response);
        }