Command Line Tool For NopCommerce
nopCommerce is a universal eCommerce platform fitting every merchant’s needs: it powers both corporate and small business sites all over the world, companies selling physical and digital goods. nopCommerce is a transparent and well-structured solution, it combines best features of open-source and commercial software.
nopCommerce is the leading ASP.NET based open-source eCommerce platform. It is a solution with comprehensive features that is applicable for all types of users from new online businesses, who are going to grow fast, to the most demanding eCommerce experts.
From a developer point of view ,NopCommerce is composed of three layers
- Library Core, Data, Services
- Presentation Web Front and Admin site
- Plugins
Use a simple Operation System metaphor here ,the library is the underline OS core, Presentation layer is Windows system, plugins are the applications for Windows.
So NopCommand is like the Terminal App for MacOS or PowerShell for Windows.
Get the Source of NopCommand
You can get the source code of NopCommand at Github NopCommand.
The NopCommand currently build with NopCommerce 3.9. Create a Tool directory under src directory of NopCommerce solution ,and then copy NopCommand from Github to the tool directory.
Then you can compile and execute NopCommand.
Get the Executable
If you don't want to compile ,just unzip Exe.zip from the source, and then copy the settings.txt from App_Data of your NopCommerce site. Settings.txt contains of database connection string.
Run NopCommand
In command line, type NopCommand.exe. you will see NopCommand Prompt
Welcome to NopCommand for NopCommerce 3.90
NopCommand> |
The default command syntax is [CommandCategory.]Command [Parameters]
There are three types of command currently supported by NopCommand
- Generic Data Command, which is the default command category, which means you don't need to type DataCommands as a prefix
- Service Commands, these commands are the majority command category, they are corresponding to the Service interfaces defined in Nop.Services.
- Help and Exit Command.Help list all the commands supported, Help [CommandCategory] list all commands for that command category.
Note: Command are case sensitive.
Examples
- Help
Help TopicCommands
NopCommand returns
[
"GetTopicById",
"GetTopicBySystemName",
"GetAllTopics"
]
2. DataCommands ReadTable
ReadTable Category 1
Since DataCommands is the default command category, you don't need input DataCommands.ReadTable Category 1
NopCommand returns
[
{
"Name": "Computers",
"Description": null,
"CategoryTemplateId": 1,
"MetaKeywords": null,
"MetaDescription": null,
"MetaTitle": null,
"ParentCategoryId": 0,
"PictureId": 1,
"PageSize": 6,
"AllowCustomersToSelectPageSize": true,
"PageSizeOptions": "6, 3, 9",
"PriceRanges": null,
"ShowOnHomePage": false,
"IncludeInTopMenu": true,
"SubjectToAcl": false,
"LimitedToStores": false,
"Published": true,
"Deleted": false,
"DisplayOrder": 1,
"CreatedOnUtc": "2017-06-28T12:06:31.143",
"UpdatedOnUtc": "2017-06-28T12:06:31.143",
"AppliedDiscounts": [],
"Id": 1
}
]
3. CategoryCommands
We can get the same result use CategoryCommands
CategoryCommands.GetCategoryById 1
Command Code Generator
When I write the code of Service Commands, I found the code is a bit repetitive, the return types of all services defined in Nop.Serivces has 4 patterns.
- IPagedList<T> return a paged list of domain objects.
- IList<T> return a list of domain objects.
- T return a single domain object.
- Primitive ,return primitive or string value.
So it's worth writing a code generator to write these code for me. Class CommandCodeGenerator is for this purpose. it defines four code templates. and generate over 90% of code for these command classes.
For simplicity and safety purpose, only read command for each Service interface currently supported in NopCommand.
You can extend this class to support other service methods to generate all the command code
Github Source https://github.com/guidebee/NopCommand