コード例 #1
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));
            }

        }
コード例 #2
0
 public DatabaseConnectorFactory(ILogger logger, 
     IDatabaseConnectorConfiguration configuration, 
     DbAdvancedOptions options)
 {
     this._logger = logger;
     this._configuration = configuration;
     _options = options;
 }
コード例 #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);
        }
コード例 #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;
        }
コード例 #5
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;
        }
コード例 #6
0
 public void Configure(DbAdvancedOptions options)
 {
     if(!HelpPipeline.CommandAliases.Contains(options.Command))
     GetConnectionFromDatabaseName(options);
 }
コード例 #7
0
 public DatabaseConnectorConfiguration(DbAdvancedOptions options)
 {
     _options = options;
     Configure(_options);
 }
コード例 #8
0
 private void InspectForInteractiveSession(DbAdvancedOptions options)
 {
     if (options.Wait)
     {
         Console.WriteLine("Press any key to exit...");
         Console.ReadKey();
     }
 }
コード例 #9
0
 private void ExitRunnerWithSuccess(DbAdvancedOptions options)
 {
     InspectForInteractiveSession(options);
     Environment.Exit(0);
 }
コード例 #10
0
 private void RunDesiredCommand(
     DbAdvancedOptions options,
     CommandPipelineFactoryConnector connector)
 {
     connector.Apply(options);
 }
コード例 #11
0
 public CommandPipelineContext Apply(DbAdvancedOptions options)
 {
     return Apply(options.Command, options);
 }