Beispiel #1
0
        public int Execute(IMetaGenerator metaTypeGenerator, InvocationContext context)
        {
            var result = ExitCode.Success;

            _assemblyProvider.PluginAssembly = metaTypeGenerator.GetType().Assembly;

            try
            {
                _timeKeeper.MeasureTime(metaTypeGenerator.Register, "Registration");

                if (VerifyTools())
                {
                    _userInputProvider.AskUser(UserArguments(context));

                    _timeKeeper.MeasureTime(metaTypeGenerator.Prepare, "Prepartion");
                    _timeKeeper.MeasureTime(metaTypeGenerator.Generate, "Generation");
                    _timeKeeper.MeasureTime(metaTypeGenerator.TearDown, "Tear down");
                }
                else
                {
                    result = ExitCode.ToolMissing;
                }

                _timeKeeper.Print();
            }
            catch (Exception exception)
            {
                _exceptionFormatter.FormatException(exception);
                result = ExitCode.ExceptionOccured;
            }

            return(result);
        }
        private IMetaGenerator RegisterPluginVariables(IMetaGenerator generator)
        {
            _executingPluginAssemblyProvider.PluginAssembly = generator.GetType().Assembly;

            generator.Register();

            return(generator);
        }
        private Command CreateGeneratorCommands(IMetaGenerator generator)
        {
            var command = new Command(generator.Name, generator.Description)
            {
                Handler = CommandHandler.Create <InvocationContext>(context => { HandleContext(context, generator); }),
            };

            _userInputProvider.GetUserInputDescriptions().ForEach(variable => command.AddOption(CreateOption(variable)));

            return(command);
        }
        private Funcky.Monads.Option <Command> CreateCommandInLifeTimeScope(IMetaGenerator generator)
        {
            using var scope = _programScope.BeginLifetimeScope();

            try
            {
                var result = scope
                             .Resolve <IGeneratorCommandBuilder>()
                             .Build(generator.Name);

                return(Funcky.Monads.Option.Some(result));
            }
            catch (Exception exception)
            {
                scope
                .Resolve <IExceptionFormatter>()
                .FormatException(exception);

                return(Funcky.Monads.Option <Command> .None());
            }
        }
Beispiel #5
0
 private void AddMetaGenerator(IMetaGenerator metaGenerator)
 {
     _metaGenerators[metaGenerator.GeneratedType] = metaGenerator;
 }
 private void HandleContext(InvocationContext context, IMetaGenerator generator)
 {
     context.ResultCode = _pluginSelection.StartPlugin(context, generator.Name);
 }