Ejemplo n.º 1
0
 /// <summary>
 /// Writes the header information.
 /// </summary>
 private void WriteHeader(CodeGenExecutorArgs args)
 {
     Logger.Default.Info(App.Description);
     Logger.Default.Info(null);
     LogCodeGenExecutionArgs(args);
     Logger.Default.Info(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Logs (writes) the <see cref="CodeGenExecutorArgs"/>.
        /// </summary>
        /// <param name="args">The <see cref="CodeGenExecutorArgs"/>.</param>
        /// <param name="paramsOnly">Indicates whether to log on the parameters collection only.</param>
        public static void LogCodeGenExecutionArgs(CodeGenExecutorArgs args, bool paramsOnly = false)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            if (!paramsOnly)
            {
                Logger.Default.Info($"  Config = {args.ConfigFile?.Name}");
                if (args.ScriptFile == null)
                {
                    Logger.Default.Info("  Script = (none)");
                }
                else
                {
                    Logger.Default.Info($"  Script = {(args.ScriptFile.Exists ? args.ScriptFile?.FullName : args.ScriptFile?.Name)}");
                }

                Logger.Default.Info($"  Template = {args.TemplatePath?.FullName}");
                Logger.Default.Info($"  Output = {args.OutputPath?.FullName}");
                Logger.Default.Info($"  Expect No Changes = {args.ExpectNoChange}");
            }

            Logger.Default.Info($"  Params{(args.Parameters.Count == 0 ? " = none" : ":")}");

            foreach (var p in args.Parameters)
            {
                Console.WriteLine($"    {p.Key} = {p.Value}");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates <see cref="ExecutionManager"/> and coordinates the run (overall execution).
        /// </summary>
        private async Task <int> RunRunAwayAsync() /* Inspired by https://www.youtube.com/watch?v=ikMiQZF-mAY */
        {
            var args = new CodeGenExecutorArgs(_assembliesOpt.HasValue() ? ((AssemblyValidator)_assembliesOpt.Validators.First()).Assemblies : _assemblies, CreateParamDict(_paramsOpt))
            {
                ConfigFile     = new FileInfo(_configArg.Value),
                ScriptFile     = new FileInfo(_scriptOpt.Value()),
                TemplatePath   = _templateOpt.HasValue() ? new DirectoryInfo(_templateOpt.Value()) : null,
                OutputPath     = new DirectoryInfo(_outputOpt.HasValue() ? _outputOpt.Value() : Environment.CurrentDirectory),
                ExpectNoChange = _expectNoChange.HasValue(),
            };

            WriteHeader(args);

            using (var em = ExecutionManager.Create(() => new CodeGenExecutor(args)))
            {
                if (args.ExpectNoChange)
                {
                    em.ExceptionHandling = ExceptionHandling.Stop;
                }

                var sw = Stopwatch.StartNew();

                await em.RunAsync().ConfigureAwait(false);

                sw.Stop();
                WriteFooter(sw);

                if (args.ExpectNoChange && (em.HadExecutionException || em.LastExecutor?.Result == ExecutorResult.Unsuccessful))
                {
                    return(-1);
                }
            }
            return(0);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Writes the header information.
 /// </summary>
 private void WriteHeader(CodeGenExecutorArgs args)
 {
     _logger.LogInformation(App.Description);
     _logger.LogInformation(string.Empty);
     LogCodeGenExecutionArgs(args);
     _logger.LogInformation(string.Empty);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Coordinates the run (overall execution).
        /// </summary>
        private async Task <int> RunRunAwayAsync() /* Inspired by https://www.youtube.com/watch?v=ikMiQZF-mAY */
        {
            var args = new CodeGenExecutorArgs(_logger, _assembliesOpt.HasValue() ? ((AssemblyValidator)_assembliesOpt.Validators.First()).Assemblies : _assemblies, CreateParamDict(_paramsOpt))
            {
                ConfigFile     = new FileInfo(_configArg.Value),
                ScriptFile     = new FileInfo(_scriptOpt.Value()),
                TemplatePath   = _templateOpt.HasValue() ? new DirectoryInfo(_templateOpt.Value()) : null,
                OutputPath     = new DirectoryInfo(_outputOpt.HasValue() ? _outputOpt.Value() : Environment.CurrentDirectory),
                ExpectNoChange = _expectNoChange.HasValue()
            };

            WriteHeader(args);

            var cge = new CodeGenExecutor(args);
            var sw  = Stopwatch.StartNew();

            var result = await cge.RunAsync().ConfigureAwait(false);

            sw.Stop();
            WriteFooter(sw);
            return(result ? 0 : -1);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates <see cref="ExecutionManager"/> and coordinates the run (overall execution).
        /// </summary>
        private async Task <int> RunRunAwayAsync() /* Inspired by https://www.youtube.com/watch?v=ikMiQZF-mAY */
        {
            var args = new CodeGenExecutorArgs(_assembliesOpt.HasValue() ? ((AssemblyValidator)_assembliesOpt.Validators.First()).Assemblies : _assemblies, CreateParamDict(_paramsOpt))
            {
                ConfigFile   = new FileInfo(_configArg.Value),
                ScriptFile   = new FileInfo(_scriptOpt.Value()),
                TemplatePath = _templateOpt.HasValue() ? new DirectoryInfo(_templateOpt.Value()) : null,
                OutputPath   = new DirectoryInfo(_outputOpt.HasValue() ? _outputOpt.Value() : Environment.CurrentDirectory),
            };

            WriteHeader(args);

            using (var em = ExecutionManager.Create(() => new CodeGenExecutor(args)))
            {
                var sw = Stopwatch.StartNew();

                await em.RunAsync().ConfigureAwait(false);

                sw.Stop();
                WriteFooter(sw);
            }
            return(0);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CodeGenExecutor"/> class.
 /// </summary>
 /// <param name="args">The <see cref="CodeGenExecutorArgs"/>.</param>
 public CodeGenExecutor(CodeGenExecutorArgs args)
 {
     _args = Check.NotNull(args, nameof(args));
 }