Ejemplo n.º 1
0
 public void Configure(DbAdvancedOptions options)
 {
     if (!HelpPipeline.CommandAliases.Contains(options.Command))
     {
         GetConnectionFromDatabaseName(options);
     }
 }
Ejemplo n.º 2
0
        public CommandPipelineContext Apply(string command,
                                            DbAdvancedOptions options = null)
        {
            var pipelineFactory = _kernel
                                  .ResolveAll <IPipelineFactory <CommandPipelineContext> >()
                                  .FirstOrDefault(f => f.Aliases.Contains(command));

            if (pipelineFactory == null)
            {
                return(null);
            }

            var context = new CommandPipelineContext
            {
                Options = options ?? _kernel.Resolve <DbAdvancedOptions>()
            };

            var pipeline = pipelineFactory.Create();

            if (pipeline == null)
            {
                return(null);
            }
            pipelineFactory.Execute(pipeline, context);

            return(context);
        }
Ejemplo n.º 3
0
 private void InspectForInteractiveSession(DbAdvancedOptions options)
 {
     if (options.Wait)
     {
         Console.WriteLine("Press any key to exit...");
         Console.ReadKey();
     }
 }
Ejemplo n.º 4
0
 public DatabaseConnectorFactory(ILogger logger,
                                 IDatabaseConnectorConfiguration configuration,
                                 DbAdvancedOptions options)
 {
     this._logger        = logger;
     this._configuration = configuration;
     _options            = options;
 }
Ejemplo n.º 5
0
        private void ExitRunnerWithFailure(DbAdvancedOptions options,
                                           Exception exception = null)
        {
            if (exception != null)
            {
                _container.Resolve <ILogger>().Error(exception.Message, exception);
            }

            InspectForInteractiveSession(options);
            Environment.Exit(-1);
        }
Ejemplo n.º 6
0
        private DbAdvancedOptions InitializeOptionsFromCommandLineArguments(string[] args)
        {
            var options = new DbAdvancedOptions(_container.Resolve <ILogger>());

            options.Configure(args);

            _container.Register(Component
                                .For <DbAdvancedOptions>()
                                .Instance(options));

            return(options);
        }
Ejemplo n.º 7
0
        private void GetConnectionFromDatabaseName(DbAdvancedOptions options)
        {
            if (string.IsNullOrEmpty(options.ConnectionString) &
                string.IsNullOrEmpty(options.Database))
            {
                throw new ArgumentException(
                          "The command line arguement for specifying the target database connection was not supplied");
            }

            if (string.IsNullOrEmpty(options.Database) & !string.IsNullOrEmpty(options.ConnectionString))
            {
                ConnectionString = options.ConnectionString;
                return;
            }

            if (!string.IsNullOrEmpty(options.Database) & string.IsNullOrEmpty(options.ConnectionString))
            {
                try
                {
                    ConnectionString = ConfigurationManager.ConnectionStrings[options.Database].ConnectionString;
                }
                catch
                {
                    throw new ArgumentException(
                              string.Format(
                                  "The connection setting for database via name '{0}' was not specified in the configuration settings file. ",
                                  options.Database));
                }

                if (string.IsNullOrEmpty(ConnectionString))
                {
                    throw new ArgumentException(
                              string.Format(
                                  "The database connection string was not supplied for connection setting via name '{0}' in the configuration settings file. ",
                                  options.Database));
                }
            }
        }
Ejemplo n.º 8
0
 public CommandPipelineContext Apply(DbAdvancedOptions options)
 {
     return(Apply(options.Command, options));
 }
Ejemplo n.º 9
0
 private void ExitRunnerWithSuccess(DbAdvancedOptions options)
 {
     InspectForInteractiveSession(options);
     Environment.Exit(0);
 }
Ejemplo n.º 10
0
 private void RunDesiredCommand(
     DbAdvancedOptions options,
     CommandPipelineFactoryConnector connector)
 {
     connector.Apply(options);
 }
Ejemplo n.º 11
0
 public DatabaseConnectorConfiguration(DbAdvancedOptions options)
 {
     _options = options;
     Configure(_options);
 }