Ejemplo n.º 1
0
        public IDecorationCommandImplementation Get(IBatchRunCommand command)
        {
            var connectionFactory = new ConnectionFactory();
            var connection        = connectionFactory.Get(command.ConnectionString);

            var directory = AssemblyDirectory;
            var filename  = string.Format("NBi.Core.{0}.dll", command.Version);
            var filepath  = string.Format("{0}\\{1}", directory, filename);

            if (!File.Exists(filepath))
            {
                throw new InvalidOperationException(string.Format("Can't find the dll for version '{0}' in '{1}'. NBi was expecting to find a dll named '{2}'.", "2014", directory, filename));
            }

            var assembly = Assembly.LoadFrom(filepath);
            var types    = assembly.GetTypes()
                           .Where(m => m.IsClass && m.GetInterface("IBatchRunnerFatory") != null);

            if (types.Count() == 0)
            {
                throw new InvalidOperationException(string.Format("Can't find a class implementing 'IBatchRunnerFatory' in '{0}'.", assembly.FullName));
            }
            if (types.Count() > 1)
            {
                throw new InvalidOperationException(string.Format("Found more than one class implementing 'IBatchRunnerFatory' in '{0}'.", assembly.FullName));
            }

            var batchRunnerFactory = Activator.CreateInstance(types.ElementAt(0)) as IBatchRunnerFatory;

            var batchRunner = batchRunnerFactory.Get(command, connection);

            return(batchRunner);
        }
Ejemplo n.º 2
0
        public IDecorationCommandImplementation Get(IBatchRunCommand command, IDbConnection connection)
        {
            if (command is IBatchRunCommand)
            {
                if (connection == null)
                {
                    throw new ArgumentNullException("connection");
                }
                if (string.IsNullOrEmpty(connection.ConnectionString))
                {
                    throw new ArgumentNullException("No connection-string defined for the sql-run");
                }
                if (!(connection is SqlConnection))
                {
                    throw new ArgumentException(
                              String.Format("To execute a SQL Batch on a SQL Server, you must provide a connection-string that is associated to a '{0}'. The connection-string '{1}' is associated to a '{2}'"
                                            , typeof(SqlConnection).FullName
                                            , connection.ConnectionString
                                            , connection.GetType().FullName)
                              , "connection");
                }
                return(new BatchRunCommand(command.FullPath, connection.ConnectionString));
            }

            throw new ArgumentException("The command must be a IBatchRunCommand", "command");
        }
Ejemplo n.º 3
0
 public BatchRunCommand(IBatchRunCommand command, SqlConnection connection)
 {
     this.connectionString = connection.ConnectionString;
     this.fullPath = command.FullPath;
 }
Ejemplo n.º 4
0
 public BatchRunCommand(IBatchRunCommand command, SqlConnection connection)
 {
     this.connectionString = connection.ConnectionString;
     this.fullPath         = command.FullPath;
 }