protected override Type CompileMigration(MigrationReference migrationReference)
 {
   Dictionary<string, string> providerOptions = new Dictionary<string, string>();
   if (!String.IsNullOrEmpty(_configuration.CompilerVersion))
   {
     providerOptions["CompilerVersion"] = _configuration.CompilerVersion;
   }
   CodeDomProvider provider = new CSharpCodeProvider(providerOptions);
   CompilerParameters parameters = new CompilerParameters();
   parameters.GenerateExecutable = false;
   parameters.OutputAssembly = Path.Combine(_workingDirectoryManager.WorkingDirectory,
                                            Path.GetFileNameWithoutExtension(migrationReference.Path) + ".dll");
   parameters.ReferencedAssemblies.Add(typeof (IDatabaseMigration).Assembly.Location);
   parameters.ReferencedAssemblies.Add(typeof (SqlMoney).Assembly.Location);
   parameters.IncludeDebugInformation = true;		
   foreach (string reference in _configuration.References)
   {
     parameters.ReferencedAssemblies.Add(reference);
   }
   _log.InfoFormat("Compiling {0}", migrationReference);
   CompilerResults cr = provider.CompileAssemblyFromFile(parameters, GetFiles(migrationReference.Path).ToArray());
   if (cr.Errors.Count > 0)
   {
     foreach (CompilerError error in cr.Errors)
     {
       _log.ErrorFormat("{0}", error);
     }
     throw new InvalidOperationException();
   }
   if (cr.CompiledAssembly == null)
   {
     throw new InvalidOperationException();
   }
   return MigrationHelpers.LookupMigration(cr.CompiledAssembly, migrationReference);
 }
 protected override Type CompileMigration(MigrationReference migrationReference)
 {
   BooCompiler compiler = new BooCompiler();
   compiler.Parameters.Input.Add(new FileInput(migrationReference.Path));
   compiler.Parameters.References.Add(typeof(IDatabaseMigration).Assembly);
   foreach (string reference in _configuration.References)
   {
     _log.Debug("Referencing: " + reference);
     compiler.Parameters.References.Add(Assembly.LoadFrom(reference));
   }
   compiler.Parameters.OutputType = CompilerOutputType.Library;
   compiler.Parameters.GenerateInMemory = true;
   compiler.Parameters.OutputAssembly = Path.Combine(_workingDirectoryManager.WorkingDirectory, Path.GetFileNameWithoutExtension(migrationReference.Path) + ".dll");
   compiler.Parameters.Ducky = true;
   compiler.Parameters.Pipeline = new CompileToFile();
   CompilerContext cc = compiler.Run();
   if (cc.Errors.Count > 0)
   {
     foreach (CompilerError error in cc.Errors)
     {
       _log.ErrorFormat("{0}", error);
     }
     throw new InvalidOperationException();
   }
   if (cc.GeneratedAssembly == null)
   {
     throw new InvalidOperationException();
   }
   return MigrationHelpers.LookupMigration(cc.GeneratedAssembly, migrationReference);
 }
    public ICollection<MigrationReference> FindMigrations()
    {
      List<MigrationReference> refs = new List<MigrationReference>();

      foreach (Type type in assembly.GetTypes())
      {
        if (type.IsPublic && type.IsClass && !type.IsAbstract && typeof(IDatabaseMigration).IsAssignableFrom(type))
        {
          object[] attrs = type.GetCustomAttributes(typeof(MigrationAttribute), false);

          if (attrs.Length == 0)
          {
            throw new Exception("Found migration type that has no version information. See type " + type.FullName);
          }

          MigrationAttribute att = (MigrationAttribute)attrs[0];

          MigrationReference mref = new MigrationReference(att.Version, type.Name, "", String.Empty);
          mref.Reference = type;

          refs.Add(mref);
        }
      }

      refs.Sort(delegate(MigrationReference mr1, MigrationReference mr2) { return mr1.Version.CompareTo(mr2.Version); });

      return refs;
    }
示例#4
0
        public ICollection <MigrationReference> FindMigrations()
        {
            List <MigrationReference> refs = new List <MigrationReference>();

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsPublic && type.IsClass && !type.IsAbstract && typeof(IDatabaseMigration).IsAssignableFrom(type))
                {
                    object[] attrs = type.GetCustomAttributes(typeof(MigrationAttribute), false);

                    if (attrs.Length == 0)
                    {
                        throw new Exception("Found migration type that has no version information. See type " + type.FullName);
                    }

                    MigrationAttribute att = (MigrationAttribute)attrs[0];

                    MigrationReference mref = new MigrationReference(att.Version, type.Name, "", String.Empty);
                    mref.Reference = type;

                    refs.Add(mref);
                }
            }

            refs.Sort(delegate(MigrationReference mr1, MigrationReference mr2) { return(mr1.Version.CompareTo(mr2.Version)); });

            return(refs);
        }
示例#5
0
        protected override Type CompileMigration(MigrationReference migrationReference)
        {
            BooCompiler compiler = new BooCompiler();

            compiler.Parameters.Input.Add(new FileInput(migrationReference.Path));
            compiler.Parameters.References.Add(typeof(IDatabaseMigration).Assembly);
            foreach (string reference in _configuration.References)
            {
                _log.Debug("Referencing: " + reference);
                compiler.Parameters.References.Add(Assembly.LoadFrom(reference));
            }
            compiler.Parameters.OutputType       = CompilerOutputType.Library;
            compiler.Parameters.GenerateInMemory = true;
            compiler.Parameters.OutputAssembly   = Path.Combine(_workingDirectoryManager.WorkingDirectory, Path.GetFileNameWithoutExtension(migrationReference.Path) + ".dll");
            compiler.Parameters.Ducky            = true;
            compiler.Parameters.Pipeline         = new CompileToFile();
            CompilerContext cc = compiler.Run();

            if (cc.Errors.Count > 0)
            {
                foreach (CompilerError error in cc.Errors)
                {
                    _log.ErrorFormat("{0}", error);
                }
                throw new InvalidOperationException();
            }
            if (cc.GeneratedAssembly == null)
            {
                throw new InvalidOperationException();
            }
            return(MigrationHelpers.LookupMigration(cc.GeneratedAssembly, migrationReference));
        }
        public ICollection <MigrationReference> FindMigrations()
        {
            var migrations = new Dictionary <string, MigrationReference>();

            foreach (var match in FindFiles(_configuration.MigrationsDirectory))
            {
                var m         = match.Match;
                var migration = new MigrationReference(Int64.Parse(m.Groups[1].Value), _namer.ToCamelCase(m.Groups[2].Value), match.Path, match.ConfigurationKey);

                if (migrations.ContainsKey(migration.ConfigurationKey + migration.Version))
                {
                    throw new DuplicateMigrationVersionException("Duplicate Version " + migration.Version);
                }

                migrations.Add(migration.ConfigurationKey + migration.Version, migration);
            }
            var sortedMigrations = new List <MigrationReference>(migrations.Values);

            sortedMigrations.Sort((mr1, mr2) => mr1.Version.CompareTo(mr2.Version));

            if (sortedMigrations.Count == 0)
            {
                _log.InfoFormat("Found {0} migrations in '{1}'!", migrations.Count, _configuration.MigrationsDirectory);
            }
            return(sortedMigrations);
        }
        public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
        {
            var migrationFileContent = _ReadMigrationFile(migrationReference);
            if (migrationFileContent == "") return GetEmptySqlScriptMigration();

            return new SqlScriptMigration(ReadUpScriptPartFrom(migrationFileContent),
                                      ReadDownScriptPartFrom(migrationFileContent));
        }
 protected IDatabaseMigration CreateMigrationInstance(MigrationReference migrationReference)
 {
     Type type = CompileMigration(migrationReference);
       object fixture = Activator.CreateInstance(type);
       IDatabaseMigration instance = fixture as IDatabaseMigration;
       if (instance == null)
       {
     throw new ArgumentException(type + " should be a " + typeof(IDatabaseMigration));
       }
       return instance;
 }
        public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
        {
            var migrationFileContent = _ReadMigrationFile(migrationReference);

            if (migrationFileContent == "")
            {
                return(GetEmptySqlScriptMigration());
            }

            return(new SqlScriptMigration(ReadUpScriptPartFrom(migrationFileContent),
                                          ReadDownScriptPartFrom(migrationFileContent)));
        }
        protected IDatabaseMigration CreateMigrationInstance(MigrationReference migrationReference)
        {
            Type               type     = CompileMigration(migrationReference);
            object             fixture  = Activator.CreateInstance(type);
            IDatabaseMigration instance = fixture as IDatabaseMigration;

            if (instance == null)
            {
                throw new ArgumentException(type + " should be a " + typeof(IDatabaseMigration));
            }
            return(instance);
        }
示例#11
0
 public static Type LookupMigration(Assembly assembly, MigrationReference migrationReference)
 {
     foreach (string alias in migrationReference.Aliases)
       {
     Type migrationType = assembly.GetType(alias);
     if (migrationType != null)
     {
       return migrationType;
     }
       }
       throw new ArgumentException("Unable to locate Migration: " + migrationReference.Path);
 }
示例#12
0
 public bool CanMigrate(IDictionary <string, List <MigrationStep> > steps)
 {
     foreach (MigrationStep step in steps.SelectMany(row => row.Value).OrderBy(row => row.Version))
     {
         MigrationReference migrationReference = step.MigrationReference;
         IMigrationFactory  migrationFactory   = _migrationFactoryChooser.ChooseFactory(migrationReference);
         IDatabaseMigration migration          = migrationFactory.CreateMigration(migrationReference);
         step.DatabaseMigration = migration;
         _migrationInitializer.InitializeMigration(migration);
     }
     _log.Info("All migrations are initialized.");
     return(true);
 }
示例#13
0
 public static Type LookupMigration(Assembly assembly, MigrationReference migrationReference)
 {
     foreach (string alias in migrationReference.Aliases)
     {
         Type migrationType = assembly.GetType(alias);
         var  lol           = assembly.GetTypes();
         if (migrationType != null)
         {
             return(migrationType);
         }
     }
     throw new ArgumentException("Unable to locate Migration: " + migrationReference.Path);
 }
 public IMigrationFactory ChooseFactory(MigrationReference migrationReference)
 {
     string extension = Path.GetExtension(migrationReference.Path);
       if (extension.Equals(".cs"))
       {
     return _cSharpMigrationFactory;
       }
       if (extension.Equals(".boo"))
       {
     return _booMigrationFactory;
       }
       if (extension.Equals(".sql"))
       {
     return _sqlScriptMigrationFactory;
       }
       throw new ArgumentException(migrationReference.Path);
 }
示例#15
0
        public IMigrationFactory ChooseFactory(MigrationReference migrationReference)
        {
            string extension = Path.GetExtension(migrationReference.Path);

            if (extension.Equals(".cs"))
            {
                return(_cSharpMigrationFactory);
            }
            if (extension.Equals(".boo"))
            {
                return(_booMigrationFactory);
            }
            if (extension.Equals(".sql"))
            {
                return(_sqlScriptMigrationFactory);
            }
            throw new ArgumentException(migrationReference.Path);
        }
示例#16
0
 public bool IsApplicable(MigrationReference migrationReference)
 {
     bool isApplied = _applied.Contains(migrationReference.Version);
       if (isApplied)
       {
     if (migrationReference.Version > _desired)
     {
       return true;
     }
     return false;
       }
       else
       {
     if (migrationReference.Version <= _desired)
     {
       return true;
     }
     return false;
       }
 }
示例#17
0
        public bool IsApplicable(MigrationReference migrationReference)
        {
            bool isApplied = _applied.Contains(migrationReference.Version);

            if (isApplied)
            {
                if (migrationReference.Version > _desired)
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                if (migrationReference.Version <= _desired)
                {
                    return(true);
                }
                return(false);
            }
        }
示例#18
0
        protected override Type CompileMigration(MigrationReference migrationReference)
        {
            Dictionary <string, string> providerOptions = new Dictionary <string, string>();

            if (!String.IsNullOrEmpty(_configuration.CompilerVersion))
            {
                providerOptions["CompilerVersion"] = _configuration.CompilerVersion;
            }
            CodeDomProvider    provider   = new CSharpCodeProvider(providerOptions);
            CompilerParameters parameters = new CompilerParameters();

            parameters.GenerateExecutable = false;
            parameters.OutputAssembly     = Path.Combine(_workingDirectoryManager.WorkingDirectory,
                                                         Path.GetFileNameWithoutExtension(migrationReference.Path) + ".dll");
            parameters.ReferencedAssemblies.Add(typeof(IDatabaseMigration).Assembly.Location);
            parameters.ReferencedAssemblies.Add(typeof(SqlMoney).Assembly.Location);
            parameters.ReferencedAssemblies.Add(typeof(TimeZoneInfo).Assembly.Location);
            parameters.ReferencedAssemblies.Add(typeof(log4net.ILog).Assembly.Location);
            parameters.IncludeDebugInformation = true;
            foreach (string reference in _configuration.References)
            {
                parameters.ReferencedAssemblies.Add(reference);
            }
            _log.InfoFormat("Compiling {0}", migrationReference);
            CompilerResults cr = provider.CompileAssemblyFromFile(parameters, GetFiles(migrationReference.Path).ToArray());

            if (cr.Errors.Count > 0)
            {
                foreach (CompilerError error in cr.Errors)
                {
                    _log.ErrorFormat("{0}", error);
                }
                throw new InvalidOperationException();
            }
            if (cr.CompiledAssembly == null)
            {
                throw new InvalidOperationException();
            }
            return(MigrationHelpers.LookupMigration(cr.CompiledAssembly, migrationReference));
        }
示例#19
0
    public ICollection<MigrationReference> FindMigrations()
    {
      var migrations = new Dictionary<string, MigrationReference>();
      foreach (var match in FindFiles(_configuration.MigrationsDirectory))
      {
        var m = match.Match;
        var migration = new MigrationReference(Int64.Parse(m.Groups[1].Value), _namer.ToCamelCase(m.Groups[2].Value), match.Path, match.ConfigurationKey);

        if (migrations.ContainsKey(migration.ConfigurationKey + migration.Version))
        {
          throw new DuplicateMigrationVersionException("Duplicate Version " + migration.Version);
        }

        migrations.Add(migration.ConfigurationKey + migration.Version, migration);
      }
      var sortedMigrations = new List<MigrationReference>(migrations.Values);
      sortedMigrations.Sort((mr1, mr2) => mr1.Version.CompareTo(mr2.Version));

      if (sortedMigrations.Count == 0)
      {
        _log.InfoFormat("Found {0} migrations in '{1}'!", migrations.Count, _configuration.MigrationsDirectory);
      }
      return sortedMigrations;
    }
示例#20
0
 public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
 {
     return CreateMigrationInstance(migrationReference);
 }
示例#21
0
 public override void Setup()
 {
     base.Setup();
     _migrationPath      = @"C:\Migration.sql";
     _migrationReference = new MigrationReference(1, "", _migrationPath);
 }
示例#22
0
 public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
 {
     return(CreateMigrationInstance(migrationReference));
 }
 public IMigrationFactory ChooseFactory(MigrationReference migrationReference)
 {
     return factory;
 }
 public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
 {
     return (IDatabaseMigration)Activator.CreateInstance(migrationReference.Reference);
 }
 public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
 {
     return((IDatabaseMigration)Activator.CreateInstance(migrationReference.Reference));
 }
 private string _ReadMigrationFile(MigrationReference migrationReference)
 {
     return(_fileSystem.ReadAllText(migrationReference.Path));
 }
                public IDatabaseMigration CreateMigration(MigrationReference migrationReference)
                {
                    if (!kernel.HasComponent(migrationReference.Reference))
                    {
                        kernel.AddComponent(migrationReference.Reference.FullName,
                                            migrationReference.Reference, LifestyleType.Transient);
                    }

                    return (IDatabaseMigration)kernel.Resolve(migrationReference.Reference);
                }
 protected abstract Type CompileMigration(MigrationReference migrationReference);
 protected abstract Type CompileMigration(MigrationReference migrationReference);
 private string _ReadMigrationFile(MigrationReference migrationReference)
 {
     return _fileSystem.ReadAllText(migrationReference.Path);
 }
 public IMigrationFactory ChooseFactory(MigrationReference migrationReference)
 {
     return(factory);
 }