Skip to main content

Command and event execution control

ExtensionPoints suppresses multiple events from occurring when the API is operated while a command or event is being executed. This avoids firing and processing events in unexpected situations during command processing, leading to performance degradation and functional bugs. In standard extension development that does not use the ExtensionPoints library, the model edit event will be fired even if the model is edited with the API.

For example, assume the following case. Suppose you develop a function that creates models all at once.

public class AddUseCasesCommand: CommandHandlerBase
{
protected override void OnExecute (ICommandContext c, ICommandParams p)
{
for (var i = 0; i <10; i ++)
{
var useCaseModel = CurrentModel.AddNewModel ("UseCases", "UseCase");

//set the field
useCaseModel.SetField ("Name", $ "MyUseCase {i}");
useCaseModel.SetField ("Description", "MyUseCase");
useCaseModel.SetField ("SomeField", "xxx");
}
}
}

Also, suppose that you register an event handler when editing a field of a model in order to implement something that corrects some data when the user edits the model. There are cases where you do not want to handle model change events when you create a model.

public class UseCaseModelFieldChangedEvent: ModelsFieldChangedEventHandlerBase
{
protected override void OnHandle (IEventContext c, ModelFieldChangedEventParams p)
{
//...
}
}

In this case, ExtensionPoints suppresses the new event from firing even if the model is changed in the OnExecute of the command and the OnHandle method of the event. If you want to perform common initialization with commands and events, define a dedicated class and consolidate the behavior there. A good approach is to define the model behavior and attributes as a class, for example:

public class UseCaseModel
{
private IModel m_Model;

public UseCaseModel (IModel m)
{
m_Model = m;
}

public void Initialize (int i = 0)
{
m_Model.SetField ("Name", $ "MyUseCase {i}");
m_Model.SetField ("Description", "MyUseCase");
m_Model.SetField ("SomeField", "xxx");
}

public void SomeMethod ()
{
m_Model.SetField (...);
}
}

public class AddUseCasesCommand: CommandHandlerBase
{
protected override void OnExecute (ICommandContext c, ICommandParams p)
{
for (var i = 0; i <10; i ++)
{
var m = CurrentModel.AddNewModel ("UseCases", "UseCase");
var useCaseModel = new UseCaseModel (m);

//set the field
useCaseModel.Initialize (i);
}
}
}
important

Note that this suppression mechanism only works inside the same extension. Please note that we do not suppress events across extensions.