There are some tasks (commands) that require maximum automation and minimum user interaction. In general, such conditions are satisfied by a console application that allows a user to specify the command, set parameters and start execution. Of course, all this should be implemented as an organic part of a XAF application, i.e. command is a function of the application, it is coded in the XAF module. Xafari framework proposes an architecture to implement commands and supplies RunCmd.exe console application to execute commands. The framework provides a number of implemented commands: to import (export) data, to create report etc.

This post describes how to apply this mechanism.

Create XAF WindowsFormApplication, name it RunCmdExample. Add BO business class to the RunCmdExample Module project. The following code demonstrates this.

Set Security System as you can see in the application screenshots:

run cmd security system settings

Set LogonParametersType to the "DevExpress.ExpressApp.Security.ChangePasswordOnLogonParameters".

Add a new XAF Module to the solution, name it CommandModule. Since CommandModule is used exclusively for RunCmd.exe, is better to remove extra folders and files. In this example, the commands are implemented in a separate module, but it is not necessary and you can implement command in any application module.

Add RunCmdExample Module to the CommandModule. You can do it in the code or use designer. If you wish to add an extra module in the code, use the following code snippet:

Add reference to the Xafari.dll assembly and set CopyLocal property to "True".

Now we can implement two commands. Add two command classes to CommandModule: it is SecurityInformation and DataInformation. SecurityInformation command will display a list of users or roles. SecurityInformation command will display determined columns of BO type from the database.

The following code snippet defines SecurityInformation and DataInformation classes:

The CommandModule must support ICommandEnumerator interface to specify commands for the Run Cmd utility. Otherwise, Run Cmd will not "know" about the implemented commands. Add the following code to the CommandModule:

For ease of use in the future, add RunCmd.exe and RunCmd.exe.config files to the CommandModule project directory. Xafari installer places these files in the "…\Xafari Framework \Tools\RunCmd\" directory.
RunCmd.exe.config settings must match the settings of the global application.

RunCmdExample solution contains a ready-to-use config file, you can download it and examine together with the solution.

The presence of the <system.diagnostics> block allows logging the execution process.

When working with Run Cmd, it is very convenient to use .bat-file. Add Run.bat file to the project and place following text in it:

The example above demonstrates different ways to set commands: to type in the command line and to load from file.

dinfo.txt file contains:

These commands retrieve information from the database at the specified column. The image illustrates the result of these commands.

command line utility result

cinfo.txt file contains:

The image illustrates the result of SInfo commands.

run cmd command result

Before running the utility, you must build CommandsModule, build and run the application to populate the database.

Load solution: RunCmdExample.