Nuget Package:
PM> Install-Package HBD.App.Shell
HBD.App.Shell
This post, I Will share the other Workspace source code for Console Shell application as well. This one will provides the core foundation for the console application. That allows building a loosely coupled, module-able and maintainable application.
How does it work?
This Shell application had been developed based on HBD.Mef library that will automatic load all modules in the defined folder at run time. This application is suitable for those who want to develop a batch job that will be triggered by the scheduler and execute the particular plugin based on the input parameters.
Quick Start
1. Add New Module
- Open Visual Studio and create a new Class Library project example project name is Job.Module.
- Install the latest version of HBD.App.Shell from Nuget.
- Add a new class named Job1 and inherited from HBD.Mef.ConsoleApp.ConsoleModuleBase and then implement 2 abstract methods (Initialize and Run(params string[] args)) as below. Remember to add the ModuleExport attribute into your Job1 class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[PluginExport("Job1", typeof(Job1))] [PartCreationPolicy(CreationPolicy.Shared)] public class Job1 : ConsoleModuleBase { public override void Initialize() { } public override void Run(params string[] args) { Console.WriteLine($"{this.GetType().Name} was ran with parameters '{string.Join(",", args)}'"); Console.Read(); this.Logger.Info(message); } } |
The function of this job is writing a message to the console and log file.
2. Setup Publish Shell folder.
- Copy folder [Solution Directory]\packages\HBD.App.Shell\tools\App.Shell to [Solution Directory]\Publish\App.Shell
3. Update project’s properties.
- Right click on the project select Properties
- Add below code into Post-build event
1 2 3 4 |
if not exist "$(SolutionDir)Publish\App.Shell\Modules\$(ProjectName)" mkdir "$(SolutionDir)Publish\App.Shell\Modules\$(ProjectName)" xcopy "$(TargetDir)*.*" "$(SolutionDir)Publish\App.Shell\Modules\$(ProjectName)" /s /y /r |
- Set Start external program under Debug to Publish\App.Shell\HBD.App.Shell.exe
- And set Working directory to Publish\App.Shell folder.
- And then set the Command line arguments is -job1 param1 param2 param3.
- Add Module config and Debug your module.
- Add a new Module_Job_Demo.json file with the following content.
1 2 3 4 5 6 7 8 9 10 11 |
//this file name convention is Module_[Your project Name] { "Name": "Demo Job Module", "Description": "This is demo job module for App Shell", "Version": "1.0.0-beta1", "IsEnabled": true, //or false //The list of assemblies that you want to be exposed to the EMF. "AssemplyFiles": [ "Job.Module.dll" ] } |
- Set Build action of this config file as below
- Run your module, the Shell application will display as below.
How to run multi jobs with parameters
As the Command line arguments above you will see the first parameter is the JobName and then follow by the parameters for that job. If you want to execute multi-job you can pass the Command-line arguments following this format: -JobName1 param1 param2 param3 -JobName2 param1 param2 param3
This is a screenshot when executing multi jobs.
If the Environment is Debug the console window will keep open unstil you press a enter key.
Source code
You can download the Job.Module source code here in Github – Job.Module
And the source code of HBD.App.Shell in here Github – HBD.App.Shell
Hope, this Shell will help you to develop a plugin-able application faster and easier. Your feedback and ideas are much appreciated. Please feel free to drop me an email with your opinion.