-
Notifications
You must be signed in to change notification settings - Fork 0
Events
SoftFluent CodeModeler generates two classes per model defined entities. The first class corresponds to the entity class, and the second one is a class implementing (among other interfaces) IList and ICollection in order to manipulate sets of this entity class.
CodeModeler creates events on both classes. Regarding the entity class, CodeModeler provides three events:
-
EntityAction
-
KeyChanged
-
PropertyChanged
Unlike the entity class, the collection class provides five events by default:
-
AddingNew
-
CollectionChanged
-
INotifyCollectionChanged.CollectionChanged
-
ListChanged
-
PropertyChanged
Provided events are classic .NET events: to consume them, the developer needs to create a handler delegate, and identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event-handler method is called whenever the event occurs, unless you remove the delegate.
The EntityAction event is an event raised at each main possible action of an entity. Those actions can be:
-
Deleting
-
Deleted
-
Saving
-
Saved
-
CopyTo
-
ReadRecord
-
ReadRecordOnSave
-
Validating
-
Validated
-
Custom
-
Attached
-
CopyFrom
This event has a strongly typed event argument named EntityActionEventArgs which derives from the System.EventArg class. This EntityActionEventArgs contains an Action property which is an enumeration indicating which action the entity is currently processing. This is a way for developers to trigger extra actions (e.g. tracing, logging, updating UI while an entity is being validated, etc.) on a specific entity action.
The KeyChanged event is raised whenever the entity key property was modified.
Both modifying the entity key by the key property itself (the Id property for instance), and by the standard EntityKey property will trigger this event.
A strongly typed event argument KeyChangedEventArg<Tk>, with Tk being the key type, is passed as a parameter. The developer can use this event argument to retrieve the previous key.
The standard .NET PropertyChanged event is available due to the implementation of the System.ComponentModel.INotifyPropertyChanged by all CodeModeler-generated entities classes.
This event is raised whenever a property of the current entity changed. Nevertheless, the way the property changed event is raised can be customized depending on the specified tracking options of a property. Indeed, the property changed event is very important in UI developments, and developers might want to change its raising behavior of it. In order to customize this event behavior there's an XML attribute named trackingModes which is available on property nodes. Five tracking flags are supported and can be combined to generate the desired behavior:
- ModelRaiseChanged: This is part of the default value. This value indicates that we want to raise the PropertyChanged event in the set property.
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Name"));
}
}
- CheckChanged: Checks if the value changed before setting it.
public string Name
{
get
{
return this._name;
}
set
{
if ((System.Collections.Generic.EqualityComparer<string>.Default.Equals(value, this._name) == true))
{
return;
}
this._name = value;
}
}
- ModelHistory: Stores on save or on read, the previous value in a shadow property by calling the CommitShadow method.
public virtual void CommitShadow()
{
this.@__nameShadow = this._name;
}
public virtual void RollbackShadow()
{
this._name = this.@__nameShadow;
}
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
}
}
public string NameShadow
{
get
{
return this.@__nameShadow;
}
}
- ChangeState: Changes the entity state as well as setting the new property value (the default value uses this setting).
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
this.EntityState = CodeModeler.Runtime.EntityState.Modified;
}
}
- Default: Uses the default value which is a combination of the ChangeState and the ModelRaiseChanged modes.
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
this.EntityState = CodeModeler.Runtime.EntityState.Modified;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Name"));
}
}
- Introduction
- Architect Guide
- Concepts
- Using Visual Studio
- Overview
- Creating a CodeModeler Project
- Visual Environment
- Project Hierarchy
- Design Surface
- Customizing Design Surfaces
- Ribbon Bar
- Property Grid
- Member Format Expressions
- Model Grid
- Method Editor
- View Editor
- Instance Editor and Grid
- Resources Editor
- Inferred Model Viewer
- Building
- Project Physical Layout
- Source Control Support
- Generating
- Aspect Oriented Design (AOD)
- Developer Guide
- The Business Object Model (BOM)
- CodeModeler Query Language (CMQL)
- Starting Guide - Tutorial
- Upgrade From CFE