internal string CreateConfigurationFile(string projectPath, string repoName, string migrationFolder, MigrationToUse migrationType)
        {
            var projectNamespace = new ProjectEvalutionHelper().RootNameSpace(projectPath);
            var className = repoName + "Configuration";

            var migrationFolderLocation = GetMigrationFolderLocation(projectPath, migrationFolder);
            if (!Directory.Exists(migrationFolderLocation))
            {
                Directory.CreateDirectory(migrationFolderLocation);
            }

            var fileBuilder = new StringBuilder();
            fileBuilder.AppendLine("using NHibernateRepo.Configuration;");
            fileBuilder.AppendLine("using NHibernateRepo.Migrations;");
            fileBuilder.AppendLine("");
            fileBuilder.AppendLine(string.Format("namespace {0}.{1}", projectNamespace, migrationFolder));
            fileBuilder.AppendLine("{");
            fileBuilder.AppendLine("    public class " + className + " : RepoMigrationConfigurationBase<" + repoName + ">");
            fileBuilder.AppendLine("    {");
            fileBuilder.AppendLine("        public " + repoName + "Configuration()");
            fileBuilder.AppendLine("        {");
            fileBuilder.AppendLine("            Enabled = true;");
            fileBuilder.AppendLine("            MigrationType = MigrationToUse." + migrationType + ";");
            fileBuilder.AppendLine("            RootMigrationFolder = @\"Migrations\\" + repoName + "Migrations\";");
            fileBuilder.AppendLine("        }");
            fileBuilder.AppendLine("    }");
            fileBuilder.AppendLine("}");

            var path = Path.Combine(CreateFileLocationPath(projectPath, className, migrationFolder));
            File.WriteAllText(path, fileBuilder.ToString());
            return path;
        }
        /// <summary>
        /// Finds all migration Types / Classes from the given project.
        /// </summary>
        /// <param name="projectPath"></param>
        /// <param name="repoType"></param>
        /// <returns></returns>
        internal static Type[] FindAllMigrations(string projectPath, Type repoType)
        {
            var loadedProject = new ProjectEvalutionHelper().LoadEvalutionProject(projectPath);

            var baseType = typeof(BaseMigration<>).MakeGenericType(repoType);
            return loadedProject
                .GetTypes()
                .Where(baseType.IsAssignableFrom)
                .ToArray();
        }
        public string CreateFile(CreationCriteria criteria)
        {
            var projectNamespace = new ProjectEvalutionHelper().RootNameSpace(criteria.ProjectFileLocation);
            var migrationFileInfo = GenerateFileLocation(criteria);

            if (!Directory.Exists(migrationFileInfo.Folder))
            {
                Directory.CreateDirectory(migrationFileInfo.Folder);
            }

            //if it already exists delete it.. it should not at this point. this is a just incase.
            if (File.Exists(migrationFileInfo.FullFilePath))
            {
                File.Delete(migrationFileInfo.FullFilePath);
            }

            _schemaUpdater.Execute(_logScript, false);

            var fileBuilder = new StringBuilder();
            fileBuilder.AppendLine("using NHibernateRepo.Migrations;");
            fileBuilder.AppendLine("using System;");
            fileBuilder.AppendLine("");
            fileBuilder.AppendLine(string.Format("namespace {0}.{1}", projectNamespace, criteria.MigrationPath.Replace("\\", ".").Replace("-", ".")));
            fileBuilder.AppendLine("{");
            fileBuilder.AppendLine("    public class " + migrationFileInfo.ClassName + " : BaseMigration<" + criteria.RepoName + ">");
            fileBuilder.AppendLine("    {");
            fileBuilder.AppendLine("        public override void Execute()");
            fileBuilder.AppendLine("        {");

            foreach (var script in Scripts)
            {
                fileBuilder.AppendLine("            ");
                fileBuilder.AppendLine("            ExecuteSql(@\"" + script +"\");");
            }

            fileBuilder.AppendLine("            ");
            fileBuilder.AppendLine("        }");
            fileBuilder.AppendLine("    }");
            fileBuilder.AppendLine("}");

            File.WriteAllText(migrationFileInfo.FullFilePath, fileBuilder.ToString());
            return migrationFileInfo.FullFilePath;
        }
        /// <summary>
        /// Tries to find the implementation of the base repo object from the given project.  
        /// Will return NULL if more than one is found.  The name can be passed in if the repo name is known, (required if multiple repos in same project).
        /// </summary>
        /// <param name="projectPath"></param>
        /// <param name="optionalRepoName"></param>
        /// <returns></returns>
        internal static RepoSearchResult FindSingleRepo(string projectPath, string optionalRepoName)
        {
            LoggerBase.Log(string.Format("Starting to find single Repo: '{0}, {1}", optionalRepoName, projectPath), isDebugMessage: true);

            var loadedProject = new ProjectEvalutionHelper().LoadEvalutionProject(projectPath);

            LoggerBase.Log("LoadedProject: " + loadedProject.FullName, isDebugMessage: true);

            var repoTypes = new Type[0];
            try
            {
                 repoTypes = loadedProject
                        .GetTypes()
                        .Where(t =>
                            t.IsSubclassOf(typeof(BaseRepo))
                            && !t.IsGenericType
                        )
                        .ToArray();
            }
            catch (ReflectionTypeLoadException ex)
            {
                LoggerBase.Log("Error whilst getting all classes that inherit from baserepo within loadedproject");

                Exception[] loaderExceptions = ex.LoaderExceptions;
                LoggerBase.Log("Logger exceptions:", isDebugMessage: true);
                foreach (var exception in loaderExceptions)
                {
                    LoggerBase.Log(exception, isDebugMessage: true);
                }

                LoggerBase.Log(ex, isDebugMessage: true);
                throw;
            }

            if (!string.IsNullOrWhiteSpace(optionalRepoName))
            {
                var repos = repoTypes.Where(r => r.Name.Equals(optionalRepoName, StringComparison.InvariantCultureIgnoreCase)).ToArray();
                if (!repos.Any())
                {
                    LoggerBase.Log("No repo class found with name: " + optionalRepoName);
                    return null;
                }

                if (repos.Count() > 1)
                {
                    LoggerBase.Log("More than one repo with same name found, please ensure repo is uniquely named in repo project.");
                    return null;
                }

                return new RepoSearchResult(loadedProject, repos.Single());
            }

            if (!repoTypes.Any())
            {
                LoggerBase.Log("No repo class found");
                return null;
            }

            if (repoTypes.Count() > 1)
            {
                LoggerBase.Log("More than one repo found, please specify which repo to use.");
                return null;
            }

            return new RepoSearchResult(loadedProject, repoTypes.Single());
        }
        /// <summary>
        /// Tries to find configuration Type.
        /// If none or multiple found NULL will be returned.
        /// </summary>
        /// <param name="projectPath"></param>
        /// <param name="repoType"></param>
        /// <param name="multipleFound"></param>
        /// <returns></returns>
        internal static Type FindSingleConfiguration(string projectPath, Type repoType, out bool multipleFound)
        {
            multipleFound = false;

            var loadedProject = new ProjectEvalutionHelper().LoadEvalutionProject(projectPath);

            var baseType = typeof (RepoMigrationConfigurationBase<>).MakeGenericType(repoType);
            var configTypes = loadedProject
                .GetTypes()
                .Where(baseType.IsAssignableFrom)
                .ToArray();

            //if none found then we will end up creating one.
            if (!configTypes.Any())
            {
                return null;
            }

            if (configTypes.Length == 1)
            {
                return configTypes.Single();
            }

            multipleFound = true;
            return null;
        }