private static async Task <object> OpenConnectionAndExec(string connectionString, string commandText, CommandActionDelegate actionDelegate, bool derive, object[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand(commandText, conn))
                {
                    // sp
                    command.CommandType = CommandType.StoredProcedure;

                    // Open
                    await conn.OpenAsync();

                    if (derive)
                    {
                        // get the parameters
                        var sqlParameters = _cache.Get(command);

                        // add they values
                        for (int i = 0; i < sqlParameters.Length; i++)
                        {
                            sqlParameters[i].Value = parameters[i];
                        }

                        // Change var
                        parameters = sqlParameters;
                    }

                    // Add the list of sql parameters.
                    command.Parameters.AddRange(parameters);

                    // Execute action
                    return(await actionDelegate.Invoke(command));
                }
            }
        }
Example #2
0
 /// <summary>
 /// Registers a new console command with help text and a tab completion provider.
 /// </summary>
 /// <param name="command">The name of the command.</param>
 /// <param name="helpText">Text to display for this command when used as an argument to the 'help' command.</param>
 /// <param name="action">The delegate to invoke for the command.</param>
 public void RegisterCommand(string command, string helpText, CommandActionDelegate action)
 {
     RegisterCommand(command, helpText, action, null);
 }
Example #3
0
        /// <summary>
        /// Registers a new console command with help text and a tab completion provider.
        /// </summary>
        /// <param name="command">The name of the command.</param>
        /// <param name="helpText">Text to display for this command when used as an argument to the 'help' command.</param>
        /// <param name="action">The delegate to invoke for the command.</param>
        /// <param name="tabCompletionProvider">The tab completion provider to use for the command arguments. Pass null to disable tab completion of arguments.</param>
        public void RegisterCommand(string command, string helpText, CommandActionDelegate action, ISuggestionProvider tabCompletionProvider)
        {
            if (string.IsNullOrEmpty(command)) throw new ArgumentNullException("command");
            if (action == null) throw new ArgumentNullException("action");
            if (string.IsNullOrEmpty(helpText)) throw new ArgumentNullException("helpText");

            commands.Add(command, new CommandInfo(command, action, helpText, tabCompletionProvider));
        }
Example #4
0
 public CommandInfo(string command, CommandActionDelegate action, string helpText, ISuggestionProvider tabCompletionProvider)
 {
     Command = command;
     Action = action;
     HelpText = helpText;
     TabCompletionProvider = tabCompletionProvider;
 }