How To create application events |
This article explains how to create and subscribe to application events.
These make inter-application communication easy for developers.
There are other ways to make two application communicate. For example, applications data and UI can be connected using our relation system without any line of code. |
To trigger an application event, you have to call the method "TriggerEvent" on a PFApplication object.
Example: on the object class (Document.Custom.cs in the Objects folder), we trigger an event for all applications each time a document has been saved.
protected override void OnInitialized() { base.OnInitialized(); this.AfterSave += Document_AfterSave; } void Document_AfterSave(object sender, PFItem_OperationEventArgs e) { //Initialize event settings PFApplicationEvent myEvent = new PFApplicationEvent { Name = "DocumentSaved", Scope = PFApplicationEventScope.AllApplications }; //Add custom parameters myEvent.Parameters.Add("Message", String.Format("The document {0} has been saved.", this.__Title)); myEvent.Parameters.Add("Document", this); //Trigger event this.ParentApplication.TriggerEvent(myEvent); }
The scope determines which applications will receive the event and can be chosen among the following values:
Open your Visual Studio project.
In the Objects\Application folder, open the Application_X_Events class.
In this class, override the "Application_EventTriggered" method:
public override void Application_EventTriggered(PFApplication sourceApplication, string eventName, Dictionary<string, object> parameters) { base.Application_EventTriggered(sourceApplication, eventName, parameters); switch(eventName) { case "DocumentSaved": Document document = parameters.TryGetValue("Document") as Document; String message = parameters.TryGetValue("Message") as String; //Handle event here. break; default: break; } }
Other events can be overridden in the application events class: