Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static int Main(string[] args)
        {
            var log = ConsoleLogWriter.CreateLog("main", LogLevel.Info, "${Message}");

            if (0 == args.Length)
            {
                log.Error("no dir given");
                return(-1);
            }
            var src = Environment.CurrentDirectory;
            var trg = args[0];

            if (1 < args.Length)
            {
                src = args[0];
                trg = args[1];
            }
            var syncer = new DirectorySynchronization(src, trg)
            {
                Log = log
            };

            try{
                syncer.Synchronize();
            }
            catch (Exception ex) {
                log.Error("error " + ex.Message, ex);
                return(-2);
            }
            return(0);
        }
        public void SyncThemas()
        {
            var sync = new DirectorySynchronization(@"C:\z3projects\assoi\local\Draft\themas\.old\thema", @"C:\mnt\testthemas")
            {
                Log = ConsoleLogWriter.CreateLog("main", customFormat: "${Message}")
            };

            sync.Synchronize();
        }
Esempio n. 3
0
 /// <summary>
 /// Выполняет весь цикл, включая обращение к БД
 /// </summary>
 public void Execute()
 {
     _context.Log = _context.Log ?? ConsoleLogWriter.CreateLog("main", customFormat: "${Message}");
     if (_context.DiffPairs == null)
     {
         _context.Log.Info("require diff checking");
         if (!string.IsNullOrWhiteSpace(_context.SqlConnectionString) && string.IsNullOrWhiteSpace(_context.GitBaseRevision))
         {
             _context.Log.Info("start revision determining");
             new SqlSourceRevisionRetriever(_context).Determine();
             _context.Log.Info("base revision detected as " + _context.GitBaseRevision);
         }
         else
         {
             _context.Log.Info("sql server not set up - work for script gen only");
         }
         new DiffPairGenerator(_context).Generate();
         _context.Log.Info("difference pairs prepared evaluated");
     }
     new DataTableDiffGenerator(_context).Generate();
     _context.Log.Info("difference tables generated: " + _context.Tables.Count() + " tables");
     if (_context.Tables.Any())
     {
         new SqlDiffGenerator(_context).Generate();
         _context.Log.Info("sql script prepared");
         if (_context.NoApply)
         {
             _context.Log.Info("Применение изменений к БД отключено");
         }
         else
         {
             if (!string.IsNullOrWhiteSpace(_context.SqlConnectionString))
             {
                 new SqlUpdateApplyer(_context).Update();
                 _context.Log.Info("sql database updated");
             }
             else
             {
                 _context.Log.Info("sql not set up - no real apply to server");
             }
         }
     }
     else
     {
         _context.Log.Info("Нет значимых изменений");
     }
 }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        public static int Main(string[] args)
        {
            var log = ConsoleLogWriter.CreateLog("main");

            try{
                var parameters = new DataDiffConsoleParameters();
                parameters.Initialize(args);
                log = parameters.Log;
                var executor = new DataDiffConsololeExecutor();
                executor.Execute(parameters);
                return(0);
            }
            catch (Exception ex) {
                log.Fatal(ex.ToString(), ex);
                return(-1);
            }
            finally{
                log.Synchronize();
            }
        }
Esempio n. 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public DiffPairGenerator(TableDiffGeneratorContext context)
 {
     this._context = context;
     if (null == _context.Log)
     {
         _context.Log = ConsoleLogWriter.CreateLog("main", customFormat: "${Message}", level: LogLevel.Trace);
     }
     if (null != _context.PreparedContext)
     {
         if (string.IsNullOrWhiteSpace(_context.ProjectDirectory))
         {
             throw new Exception("ProjectDirectory is required");
         }
         if (string.IsNullOrWhiteSpace(_context.GitBranch))
         {
             _context.GitBranch = "master";
         }
         if (string.IsNullOrWhiteSpace(_context.RootDirectory))
         {
             _context.RootDirectory = Path.GetTempFileName();
         }
         if (string.IsNullOrWhiteSpace(_context.GitUrl))
         {
             if (!Directory.Exists(Path.Combine(_context.RootDirectory, ".git")))
             {
                 throw new Exception("no valid repo directory, nor git URL was given");
             }
         }
         if (string.IsNullOrWhiteSpace(_context.GitUpdateRevision))
         {
             _context.GitUpdateRevision = "HEAD";
         }
     }
     if (string.IsNullOrWhiteSpace(_context.BSharpPrototype))
     {
         _context.BSharpPrototype = "db-meta";
     }
 }
Esempio n. 6
0
        private static IUserLog SetupLog(IDictionary <string, string> adict)
        {
            var level = LogLevel.Info;

            if (adict.ContainsKey("loglevel"))
            {
                level = (LogLevel)Enum.Parse(typeof(LogLevel), adict["loglevel"], true);
            }
            if (adict.ContainsKey("log-level"))
            {
                level = (LogLevel)Enum.Parse(typeof(LogLevel), adict["log-level"], true);
            }
            //disable logging for console-mode
            if (adict.ContainsKey("console-mode"))
            {
                level = LogLevel.Fatal;
            }
            var log = ConsoleLogWriter.CreateLog("main", customFormat: "${Message}", level: level);

            log.Info("log level " + level);

            return(log);
        }
Esempio n. 7
0
        /// <summary>
        /// Стандартный шаблон выполнения консольных приложений в Qorpent
        /// </summary>
        /// <typeparam name="TArgs"></typeparam>
        /// <param name="args"></param>
        /// <param name="executor"></param>
        /// <param name="shadowByDefault">Признак использования ShadowRun по умолчанию</param>
        /// <returns></returns>
        public static int Execute <TArgs>(string[] args, Func <TArgs, int> executor, bool shadowByDefault = false) where TArgs : ConsoleApplicationParameters, new()
        {
            if (args.Contains("--debug"))
            {
                Debugger.Launch();
            }
            var log = ConsoleLogWriter.CreateLog();

            try{
                var parameters = new TArgs();
                parameters.ShadowByDefault = shadowByDefault;
                parameters.Initialize(args);
                log = parameters.Log;
                if ((shadowByDefault || parameters.Shadow) && !parameters.NoShadow)
                {
                    var shadower = new ShadowRun {
                        Parameters = parameters,
                        Log        = log
                    };
                    if (!shadower.EnsureShadow())
                    {
                        return(-3);                        //shadow restart
                    }
                }
                return(executor(parameters));
            }
            catch (Exception ex) {
                log.Fatal(ex.ToString(), ex);
                return(-1);
            }
            finally{
                if (null != log)
                {
                    log.Synchronize();
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        ///     Отложенный конструктор, логика подготовки
        /// </summary>
        public virtual ConsoleApplicationParameters Initialize(params string[] arguments)
        {
            if (_initialized)
            {
                return(this);
            }
            _initialized = true;
            SourceArgs   = arguments;
            var helper = new ConsoleArgumentHelper();

            helper.Apply(arguments, this);
            if (!string.IsNullOrWhiteSpace(ShadowEvidence))
            {
                EnvironmentInfo.ShadowEvidence = ShadowEvidence;
            }
            Log = ConsoleLogWriter.CreateLog("main", LogLevel.Info, LogFormat);
            if (!string.IsNullOrWhiteSpace(WorkingDirectory))
            {
                var workingDirectory = Path.GetFullPath(WorkingDirectory);
                if (!Directory.Exists(workingDirectory))
                {
                    Directory.CreateDirectory(workingDirectory);
                }
                Environment.CurrentDirectory  = workingDirectory;
                EnvironmentInfo.RootDirectory = Environment.CurrentDirectory;
            }
            if (TreatAnonymousAsBSharpProjectReference && !string.IsNullOrWhiteSpace(Arg1) && IsReal)
            {
                try {
                    LoadFromBSharp();              // загружаем параметры из B#
                    LogFormat = LogFormat.Replace("@{", "${");
                    helper.Apply(arguments, this); //а потом перегружаем из аргументов (чтобы консоль перекрывала)
                }
                catch (Exception ex) {
                    Log.Fatal(ex.Message, ex, this);
                    throw;
                }
            }
            if (!string.IsNullOrWhiteSpace(RepositoryPath))
            {
                EnvironmentInfo.LocalRepositoryDirectory = RepositoryPath;
            }
            if (!string.IsNullOrWhiteSpace(ShadowEvidence))
            {
                EnvironmentInfo.ShadowEvidence = ShadowEvidence;
            }

            if (!string.IsNullOrWhiteSpace(ManifestPath))
            {
                if (File.Exists(ManifestPath))
                {
                    EnvironmentInfo.ManifestPath = ManifestPath;
                }
                else
                {
                    EnvironmentInfo.ConfigDirectory = ManifestPath;
                }
            }
            if (string.IsNullOrWhiteSpace(LogFormat))
            {
                LogFormat = "${Time} ${Message}";
            }
            if (LogLevel == LogLevel.None)
            {
                LogLevel = LogLevel.Info;
            }
            Log.Level = LogLevel;
            if (Debug)
            {
                Log.Debug("debugger launched");
            }
            InternalInitialize(arguments);

            InternalCheckValid();


            DebugPrintArguments();
            return(this);
        }