public override async Task <IGenesisExecutionResult> Execute(GenesisContext genesis, string[] args)
        {
            var result = new BlankGenesisExecutionResult();

            var alc = new AssemblyLoadContext("DotNetAssembly", true);

            using var stream = File.OpenRead(Config.AssemblyPath);

            var asm = alc.LoadFromStream(stream);

            if (Config.OnlyGenesisDecorations)
            {
                foreach (var t in asm.DefinedTypes.Where(w => // pull objects with GenesisObject attribute
                                                         w.CustomAttributes.SingleOrDefault(ca => ca.AttributeType == typeof(GenesisObjectAttribute)) != null))
                {
                    InsertGraphFromType(genesis, t);
                }
            }
            else // use all public objects
            {
                foreach (var t in asm.DefinedTypes)
                {
                    InsertGraphFromType(genesis, t);
                }
            }

            return(await Task.FromResult(result));
        }
Beispiel #2
0
        public override async Task <IGenesisExecutionResult> Execute(GenesisContext genesis, string[] args)
        {
            var btr = new BlankGenesisExecutionResult();

            var exeName = args[1];

            //NOTE: Added that default help stuff for commands. Copy / Pasted 'gen' command here ;)

            var exe = GetExecutor(exeName);
            await exe.DisplayConfiguration();

            Text.Line();

            return(await Task.FromResult(btr));
        }
Beispiel #3
0
        public override async Task <IGenesisExecutionResult> Execute(GenesisContext genesis, string[] args)
        {
            var result = new BlankGenesisExecutionResult()
            {
                Success = true, Message = ""
            };

            Text.Line();
            Text.YellowLine("Scanning for Inputs:");
            await InputManager.InitializeInputsAsync(true);

            Text.Line();

            Text.YellowLine("Scanning for Outputs:");
            await OutputManager.InitializeGeneratorsAsync(true);

            Text.Line();

            Text.YellowLine("Scanning for General Executors: ");
            await GeneralManager.InitializeGeneratorsAsync(true);

            Text.Line();

            Console.ForegroundColor = (InputManager.Inputs.Count > 0) ? ConsoleColor.Green : ConsoleColor.Yellow;
            Text.White($@"{InputManager.Inputs.Count}");
            Text.WhiteLine($" Potential Input(s)");

            Console.ForegroundColor = (OutputManager.Outputs.Count > 0) ? ConsoleColor.Green : ConsoleColor.Yellow;
            Text.White($"{OutputManager.Outputs.Count}");
            Text.WhiteLine(" Possible Output(s)");

            Console.ForegroundColor = (GeneralManager.Current.Count > 0) ? ConsoleColor.Green : ConsoleColor.Yellow;
            Text.White($"{GeneralManager.Current.Count}");
            Text.WhiteLine(" General Executor(s)");

            Text.Line();
            Text.White("The "); Text.Green("green"); Text.WhiteLine(" text is how you reference an Executor. ");
            Text.Line();

            genesis.ScanCount++;

            return(await Task.FromResult(result));
        }
Beispiel #4
0
        /// <summary>
        /// Build a new command line app and relay the args to it
        /// </summary>
        /// <param name="args">string array of arguments</param>
        /// <returns><see cref="CommandLineApplication"/>fresh cla</returns>
        private static CommandLineApplication ExecuteContext(string[] args)
        {
            var app = new CommandLineApplication(true) //doesn't matter if we rebuild it every execution since we have a context
            {
                Description = "Generate stuff from other stuff",
                //TODO: Default help stuff?
                ExtendedHelpText = "Use Executors to do things in regard to objects and their schemas"
            };

            foreach (var cmd in CommandLoader.Commands)
            {
                app.Command(cmd.Name, cfg =>
                {
                    cfg.Description = cmd.Description;
                    cfg.HelpOption($"{cmd.HelpTemplate}");
                    cfg.Option("-?", "Display command details", CommandOptionType.SingleValue);
                    cfg.ShowInHelpText = true;
                    /* arguments and options */
                }, false) //false so it doesn't throw on unknown args
                .OnExecute(async() =>
                {
                    IGenesisExecutionResult result = null !;
                    try
                    {
                        result = await cmd.Execute(GenesisContext.Current, args);
                    }
                    catch (Exception exception)
                    {
                        result = new BlankGenesisExecutionResult();
                        Text.RedLine(exception.Message);
                    }
                    finally
                    {
                        Debug.WriteLine($"{cmd.Name}| {result.Success}");
                    }
                    return(result.Success ? 0 : -1); //does this even matter?
                });
            }

            return(app);
        }
Beispiel #5
0
        public override async Task <IGenesisExecutionResult> Execute(GenesisContext genesis, string[] args)
        {
            var r = new BlankGenesisExecutionResult();

            if (args.Length == 1)
            {
                Text.White("Specify something to execute. A ");
                Text.CliCommand("command");
                Text.White(" or ");
                Text.Yellow("chain");
                Text.WhiteLine(" to execute the chain");
                Text.Line();

                return(r);
            }

            var exe = GetExecutor(args[1]);

            if (exe != null) //executor name
            {
                await exe.Execute(genesis, args);

                return(new BlankGenesisExecutionResult()); //whatever for now
            }
            else if (args[1] == "chain")
            {
                var errorCount = 0;

                foreach (var e in genesis.Chain.Execute(args))
                {
                    if (!e.Success) //Executors have to return a result with true
                    {
                        errorCount++;
                    }
                }

                if (errorCount == 0)
                {
                    Text.SuccessGraffiti();
                    return(new OutputGenesisExecutionResult {
                        Success = true
                    });
                }

                if (errorCount < genesis.Chain.Count)
                {
                    Text.WarningGraffiti();
                    return(new OutputGenesisExecutionResult {
                        Success = false
                    });
                }

                if (errorCount == genesis.Chain.Count)
                {
                    Text.ErrorGraffiti();
                    return(new OutputGenesisExecutionResult {
                        Success = false
                    });
                }

                return(new BlankGenesisExecutionResult()); //whatever for now
            }
            else
            {
                var tmp = GetExecutor(args[1]);

                if (tmp == null)
                {
                    throw new InvalidOperationException("Invalid execution: " + args[0] + " " + args[1]);
                }

                return(await tmp.Execute(genesis, args));
            }
        }
Beispiel #6
0
        public override async Task <IGenesisExecutionResult> Execute(GenesisContext genesis, string[] args)
        {
            var result = new BlankGenesisExecutionResult();

            //TODO: Move help text to override in AddCommand
            if (args.Length == 1 || HelpWasRequested(args)) //just 'add' or 'add --help,-?'
            {
                Console.WriteLine("Usage:");
                Console.WriteLine($"\t{Name} <command>\t\tAdds an executor to the end of the Chain.");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine($"\t'{Name} ExecutorName'");
                Console.ResetColor();
                Console.WriteLine();

                if (OutputManager.Outputs.Count == 0 || InputManager.Inputs.Count == 0) //NO Executors found, this still needs combined
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("There are no inputs discovered yet. Run a ");
                    Text.CliCommand("scan");
                    Console.WriteLine(".");
                }
                else
                {
                    Console.WriteLine("Known Inputs:"); //TODO: Get rid of OutputExecutor / InputExecutor concept
                    foreach (var item in InputManager.Inputs)
                    {
                        Text.White("Input: "); Text.Green($@"{item.CommandText}"); Text.White(" From: "); Text.DarkCyanLine($"{item.GetType().Assembly.GetName().Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Known Current:"); //TODO: Get rid of OutputExecutor / InputExecutor concept
                    foreach (var item in OutputManager.Outputs)
                    {
                        Text.White("Output: "); Text.Green($@"{item.CommandText}"); Text.White(" From: "); Text.DarkCyanLine($"{item.GetType().Assembly.GetName().Name}");
                    }
                }
                result.Success = true;
            }
            else
            {
                Text.Line();

                var generator = OutputManager.Outputs.Find(g => g.CommandText.Trim().ToLower() == args[1].Trim().ToLower());
                if (generator != null)
                {
                    await genesis.Chain.Append(generator);

                    Text.CliCommand(generator.CommandText); Text.WhiteLine($@" was added to the Chain. There are {genesis.Chain.Count} now.");
                    Text.Line();
                    result.Success = true;
                    return(result);
                }

                var populator = InputManager.Inputs.Find(p => p.CommandText.Trim().ToLower() == args[1].Trim().ToLower()); //this is silly
                if (populator != null)
                {
                    await genesis.Chain.Append(populator);

                    Text.CliCommand(populator.CommandText); Text.WhiteLine($@" was added to the Chain. There are {genesis.Chain.Count} now.");
                    Text.Line();
                    result.Success = true;
                    return(result);
                }

                Text.White("'");
                Text.Red(args[1]);
                Text.WhiteLine("' is not a known input or output.");
                Text.Line();
            }

            return(await Task.FromResult(result));
        }