示例#1
0
        private static IEnumerable<MongoScript> GetScriptLog(MongoUrlBuilder mongoUrlBuilder, CmdLine cmdLine)
        {
            var client = CreateMongoClient(mongoUrlBuilder);

            try
            {
                client.GetServer().Connect();
                var db = client.GetServer().GetDatabase(mongoUrlBuilder.DatabaseName);
                var scriptLog = new MongoDbScriptEnumerator(db, cmdLine.LogCollection);
                return scriptLog.AllScripts();
            }
            finally
            {
                client.GetServer().Disconnect();
            }
        }
示例#2
0
        private static void Synchronize(MongoScriptRunner scriptRunner, IUserInteraction userInteraction, CmdLine cmdLine,
            MongoUrlBuilder mongoUrlBuilder)
        {
            var client = CreateMongoClient(mongoUrlBuilder);
            var filter = new CategoryMatcher();

            try
            {
                System.Console.Out.WriteLine("Running scripts from {0} on database {1}", cmdLine.SourceDir, mongoUrlBuilder.DatabaseName);

                var synchronizer = new ScriptSynchronizer(client.GetServer().GetDatabase(mongoUrlBuilder.DatabaseName), cmdLine.LogCollection, scriptRunner, userInteraction);
                var sourceScripts = new FileScriptEnumerator(cmdLine.SourceDir)
                    .AllScripts()
                    .Where(script => filter.IsMatch(script.Name, cmdLine.Environment))
                    .ToArray();
                var scriptLog = GetScriptLog(mongoUrlBuilder, cmdLine).ToArray();
                bool wasAborted = synchronizer.Synchronize(scriptLog, sourceScripts);
                if (wasAborted)
                {
                    System.Console.Out.WriteLine("Aborting...");
                    Environment.Exit(0);
                }
            }
            finally
            {
                client.GetServer().Disconnect();
            }
        }