+ "text": "Commands\n\n\nCommands are the fundamental abstraction used to run custom logic.\n\n\nCreate a Command\n\n\nThe InEngine.Core package is required. Install it into your own Visual Studio project.\n\n\nPackage Manager\n\n\nInstall-Package InEngine.Core\n\n\n\n\nNuget CLI\n\n\nnuget install InEgine.Core\n\n\n\n\n.NET CLI\n\n\ndotnet add package InEngine.Core\n\n\n\n\nPaket CLI\n\n\npaket add InEngine.Core\n\n\n\n\nAdding a class that implements \nInEngine.Core.ICommand\n is the simplest way to create a command.\n\n\nusing System;\nusing InEngine.Core;\n\nnamespace MyCommandPlugin\n{\n public class MyCommand : ICommand\n {\n public CommandResult Run()\n {\n Console.WriteLine(\nHello, world!\n);\n return new CommandResult(true);\n }\n }\n}\n\n\n\n\nExtending the \nInEngine.Core.AbstractCommand\n class adds extra functionality, like a logger, a progress bar, and the ability to schedule the command using the scheduler.\nMinimally, the Run method should be overridden.\n\n\nusing System;\nusing InEngine.Core;\n\nnamespace MyCommandPlugin\n{\n public class MyCommand : ICommand\n {\n public override CommandResult Run()\n {\n Console.WriteLine(\nHello, world!\n);\n return new CommandResult(true);\n }\n }\n}\n\n\n\n\nRun a Command\n\n\nCreate a class that implements \nInEngine.Core.IOptions\n in the same assembly as the command class.\nAdd a VerbOptions attribute from the CommandLine namespace that defines the name of the command and optional help text.\nThe help text can be auto-generated from the attribute or manually specified in the GetUsage method. \n\n\nusing CommandLine;\nusing CommandLine.Text;\nusing InEngine.Core;\n\nnamespace MyCommandPlugin\n{\n public class MyOptions : IOptions\n {\n [VerbOption(\nmy-command\n, HelpText=\nMy example command.\n)]\n public MyCommand MyCommand { get; set; }\n\n [HelpVerbOption]\n public string GetUsage(string verb)\n {\n return HelpText.AutoBuild(this, verb);\n }\n }\n}\n\n\n\n\nDownload the InEngineCli tool that matches the version of the InEngine.Core package you included from the \nGitHub Releases\n page.\n\n\nCopy your project's DLLs into the same directory as InEngineCli.exe.\n\n\nRun your command...\n\n\nInEngineCli.exe -pMyCommandPlugin my-command\n\n\n\n\nDiscover Command Plugins\n\n\nRun InEngineCli.exe without any arguments to see a list of arguments.\n\n\n\n ___ _____ _ _ _ _____ _____ \n |_ _|_ __ | ____|_ __ __ _(_)_ __ ___ | \\ | | ____|_ _|\n | || '_ \\| _| | '_ \\ / _` | | '_ \\ / _ \\ | \\| | _| | | \n | || | | | |___| | | | (_| | | | | | __/_| |\\ | |___ | | \n |___|_| |_|_____|_| |_|\\__, |_|_| |_|\\___(_|_| \\_|_____| |_| \n |___/ \n\nUsage:\n -p[\nplugin_name\n] [\ncommand_name\n]\n\nPlugins:\n InEngine.Commands\n InEngine.Core\n\n\n\n\n\nDiscover Commands in a Plugin\n\n\nRun InEngineCli.exe with only the plugin specified.\n\n\nInEngineCli.exe -pInEngine.Core\n\n\n\n\nThe \nInEngine.Core\n library is itself a plugin that contains queue related commands. \nAs an example, this is the help output for the core plugin.\n\n\n\n ___ _____ _ _ _ _____ _____ \n |_ _|_ __ | ____|_ __ __ _(_)_ __ ___ | \\ | | ____|_ _|\n | || '_ \\| _| | '_ \\ / _` | | '_ \\ / _ \\ | \\| | _| | | \n | || | | | |___| | | | (_| | | | | | __/_| |\\ | |___ | | \n |___|_| |_|_____|_| |_|\\__, |_|_| |_|\\___(_|_| \\_|_____| |_| \n |___/ \n\nPlugin: InEngine.Core\n\nCommands:\n null A null operation command. Literally does nothing.\n echo Echo some text to the console. Useful for end-to-end testing.\n queue:publish Publish a command message to a queue.\n queue:consume Consume one or more command messages from the queue.\n queue:length Get the number of messages in the primary and secondary queues.\n queue:clear Clear the primary and secondary queues.\n\n\n\n\nPrint Help Text for a Plugin's Commands\n\n\nRun the command with the -h or --help arguments.\n\n\nInEngineCli.exe -pInEngine.Core queue:clear -h\n\n\n\n\nThe \nInEngine.Core\n plugin's command to clear the InEngine.NET's queues produces this help message. \n\n\nInEngine 3.x\nCopyright \u00a9 Ethan Hann 2017\n\n --processing-queue Clear the processing queue.\n\n --secondary Clear the secondary queue.\n\n\n\n\nWriting Output\n\n\nThe \nInEngine.Core.AbstractCommand\n class provides some helper functions to output text to the console: \n\n\nIWrite Newline();\nIWrite Info(string val);\nIWrite Warning(string val);\nIWrite Error(string val);\nIWrite Line(string val);\n\n\n\n\npublic override CommandResult Run()\n{\n Info(\nDisplay some information\n);\n}\n\n\n\n\nDisplay an error message, use the Error method.\n\n\nError(\nDisplay some information\n);\n\n\n\n\nDisplay a warning message, use the Warning method.\n\n\nError(\nDisplay some information\n);\n\n\n\n\nInfo, Error, and Warning messages are display in green, red, and yellow, respectively.\nIf you want to display an uncolored line, use the Line method. \nLine(\"This is a plain line.\");\n\n\nLogging\n\n\nThe \nInEngine.Core.AbstractCommand\n class provides a Logger property. It implements the \nNLog.ILogger\n interface.\n\n\npublic override CommandResult Run()\n{\n Logger.Trace(\nSample trace message\n);\n Logger.Debug(\nSample debug message\n);\n Logger.Info(\nSample informational message\n);\n Logger.Warn(\nSample warning message\n);\n Logger.Error(\nSample error message\n);\n Logger.Fatal(\nSample fatal error message\n);\n return new CommandResult(true);\n}\n\n\n\n\nSetup an \nNLog configuration\n file, something like this...\n\n\n?xml version=\n1.0\n encoding=\nutf-8\n ?\n\n\nnlog xmlns=\nhttp://www.nlog-project.org/schemas/NLog.xsd\n\n xmlns:xsi=\nhttp://www.w3.org/2001/XMLSchema-instance\n\n\n \ntargets\n\n \ntarget name=\nlogfile\n xsi:type=\nFile\n fileName=\nfile.txt\n /\n\n \ntarget name=\nconsole\n xsi:type=\nConsole\n /\n\n \n/targets\n\n\n \nrules\n\n \nlogger name=\n*\n minlevel=\nTrace\n writeTo=\nlogfile\n /\n\n \nlogger name=\n*\n minlevel=\nInfo\n writeTo=\nconsole\n /\n\n \n/rules\n\n\n/nlog\n\n\n\n\n\nProgress Bar\n\n\nThe \nInEngine.Core.AbstractCommand\n class provides a ProgressBar property. This is how it is used.\n\n\npublic override CommandResult Run()\n{\n // Define the ticks (aka steps) for the command...\n var maxTicks = 100000;\n SetProgressBarMaxTicks(maxTicks);\n\n // Do some work...\n for (var i = 0; i \n= maxTicks;i++)\n {\n // Update the command's progress\n UpdateProgress(i);\n }\n\n return new CommandResult(true);\n}",
0 commit comments