Create C# class with Visual Studio
- Open your project in Visual Studio
- Select your project and click on
- Add -> New Item...
- Select Visual C# Items -> Class
- Rename your class here with EwUsersCommandX
Click OK.
Create a new Command
For create a new command derive your EwUsersCommandX class with the EwCommandX interface.
public class EwUsersCommandX : EwCommandX
{
After that you must override 4 functions.
The Second step is to:
- give a unique name of the command.
- give a description of the command.
- give a flag instruction (see help for more information).
{
return "HelloWorld";
}
public string getDescription(out
EwErrorCode errorCode)
{
return "An Hello World Message";
}
{
}
The next step is to code the goal of your command.
public EwErrorCode execute(EwCommandContextX commandContextX)
{
if (mEwApplicationX == null)
return ewErrorCode;
EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode);
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewDialogTask ==
null))
return ewErrorCode;
ewDialogTask.setContent("Hello World.");
ewDialogTask.addButton("Ok", 1);
ewDialogTask.show(out ewErrorCode);
return ewErrorCode;
}
Here is a C# example of implementation:
using System.Runtime.InteropServices;
using EwAPI;
namespace UsersCommand
{
[ComVisible(true)]
public class EwUsersCommandX : EwCommandX
{
{
return "HelloWorld";
}
public string getDescription(out
EwErrorCode errorCode)
{
return "An Hello World Message";
}
{
}
public EwErrorCode execute(EwCommandContextX commandContextX)
{
if (mEwApplicationX == null)
return ewErrorCode;
EwDialogTaskX ewDialogTask = mEwApplicationX.
getEwDialogTask(out ewErrorCode);
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewDialogTask ==
null))
return ewErrorCode;
ewDialogTask.addButton("Ok", 1);
ewDialogTask.show(out ewErrorCode);
return ewErrorCode;
}
public void test()
{
}
}
}
How to use a new Command
Now it's time to add the new command to
public void addCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
EwUsersCommandX ewCommand = new EwUsersCommandX();
ewErrorCode = ewCommandManager.
addCommand(ewCommand);
}
And to test it.
To knowing the list of parameters of the last command
public void getParameterList()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
int iSize = vArray.Length;
for(int i = 0; i < iSize; i++)
{
string strParam = vArray[i];
}
}
And to remove the command
public void removeCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
}
Here is a C# example of use:
using System;
using System.Runtime.InteropServices;
using EwAPI;
namespace UsersCommand
{
public class EwUserCommandManagerX
{
public void addCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
EwUsersCommandX ewCommand = new EwUsersCommandX();
ewErrorCode = ewCommandManager.
addCommand(ewCommand);
}
public void removeCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
}
public void getParameterList()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
int iSize = vArray.Length;
for(int i = 0; i < iSize; i++)
{
string strParam = vArray[i];
}
}
}
}
- Note
- mEwApplicationX: application object previously created.