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));
            }

        }
 public DatabaseConnectorFactory(ILogger logger, 
     IDatabaseConnectorConfiguration configuration, 
     DbAdvancedOptions options)
 {
     this._logger = logger;
     this._configuration = configuration;
     _options = options;
 }
Esempio n. 3
0
        private void ExitRunnerWithFailure(DbAdvancedOptions options,
            Exception exception = null)
        {
            if (exception != null)
            {
                _container.Resolve<ILogger>().Error(exception.Message, exception);
            }

            InspectForInteractiveSession(options);
            Environment.Exit(-1);
        }
Esempio n. 4
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;
        }
        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;
        }
 public void Configure(DbAdvancedOptions options)
 {
     if(!HelpPipeline.CommandAliases.Contains(options.Command))
     GetConnectionFromDatabaseName(options);
 }
 public DatabaseConnectorConfiguration(DbAdvancedOptions options)
 {
     _options = options;
     Configure(_options);
 }
Esempio n. 8
0
 private void InspectForInteractiveSession(DbAdvancedOptions options)
 {
     if (options.Wait)
     {
         Console.WriteLine("Press any key to exit...");
         Console.ReadKey();
     }
 }
Esempio n. 9
0
 private void ExitRunnerWithSuccess(DbAdvancedOptions options)
 {
     InspectForInteractiveSession(options);
     Environment.Exit(0);
 }
Esempio n. 10
0
 private void RunDesiredCommand(
     DbAdvancedOptions options,
     CommandPipelineFactoryConnector connector)
 {
     connector.Apply(options);
 }
 public CommandPipelineContext Apply(DbAdvancedOptions options)
 {
     return Apply(options.Command, options);
 }