Changes

Created page with "In {{UBIK}} 4, there is a mechanism for the automatic detection of changes by other {{UBIK}} processes, which provide notifications for their changes. == Configuration == The..."
In {{UBIK}} 4, there is a mechanism for the automatic detection of changes by other {{UBIK}} processes, which provide notifications for their changes.
== Configuration ==
The UBIKContent web service can be configured{{Version/ServerSince|4.9.0}} to react to such notifications by updating its cache; mostly the [[User_Groups_and_Rights|user group cache used for rights evaluation]].
<br/>Change detection can be configured in the [[Configuration_Files/AppSettings.config|application settings of the UBIKContent web service]].{{Version/ServerSince|4.9.0}}
== Customizing ==
There are multiple possibilities to react to change detections via customizing.
=== Overriding the event handler of an instance ===
<source lang="csharp">
protected virtual void OnBeforeUpdateByChangeNotification()
{
// Called before an already cached instance will be reloaded from the database because of a change notification.
}

protected virtual void OnAfterUpdateByChangeNotification()
{
// Called after an instance was reloaded from the database because of a change notification.
}
</source>
=== Attaching a new event handler to the UBIKEventManager ===
<source lang="csharp">
// In Plugin code or custom code library, or anywhere else:

UBIK.Kernel.UbikEventManager eventMan = Environment.GetEventManager();
eventMan.InstanceAfterUpdateByChangeNotification += EventMan_InstanceAfterUpdateByChangeNotification;
eventMan.InstanceBeforeUpdateByChangeNotification += EventMan_InstanceBeforeUpdateByChangeNotification;
// Don't forget to unregister from the events when the handlers are not needed anymore, to avoid a memory leak:
// eventMan.InstanceAfterUpdateByChangeNotification -= EventMan_InstanceAfterUpdateByChangeNotification;
// eventMan.InstanceBeforeUpdateByChangeNotification -= EventMan_InstanceBeforeUpdateByChangeNotification;

// ...

private void EventMan_InstanceBeforeUpdateByChangeNotification(BaseClass sender)
{
// Act before imminent reload, for example:
// InvalidateState(sender);
}

private void EventMan_InstanceAfterUpdateByChangeNotification(BaseClass sender)
{
// React to change, for example:
// UpdateCache(sender);
}
</source>
== See also ==
* [[Configuration_Files/AppSettings.config]]
* [[User_Groups_and_Rights]]

[[Category:Coding|Change Detection via Change Notifications]]
[[Category:Web service|Change Detection via Change Notifications]]
[[Category:Studio|Change Detection via Change Notifications]]
1,765
edits