Handling events is similar to adding a button click on a page. Each event executor creates a copy of the content being executed. For the complete list of the In-Process event arguments please see In-Process API Event Arguments.
Each content can contain its own set of events. To find out what events are available please see the In-Process API Documentation.
The samples below assume the event handler is created in the Initialize() method of an IPlugin type.
Before Create
This sample shows how to write an event log before a blog post is created.
public void Initialize() { Apis.Get<Blogs>().Events.BeforeCreate += new BlogBeforeCreateEventHandler(BlogEvent_BeforeCreate); } private void BlogEvent_BeforeCreate(BlogBeforeCreateEventArgs blog) { var message = string.Format("{0} with {1} ID, is going to be created.", blog.Name, blog.Id); var options = new EventLogEntryWriteOptions { Category = "Samples" }; Apis.Get<EventLog>().Write(message, options); }
After Create
This sample shows how to write an event log after a blog post was created.
public void Initialize() { Apis.Get<Blogs>().Events.AfterCreate += new BlogAfterCreateEventHandler(BlogEvent_AfterCreate); } private void BlogEvent_AfterCreate(BlogAfterCreateEventArgs blog) { var message = string.Format("{0} with {1} ID, was created.", blog.Name, blog.Id); var options = new EventLogEntryWriteOptions { Category = "Samples" }; Apis.Get<EventLog>().Write(message, options); }
Before Update
This sample shows how to write an event log before a blog post is updated.
public void Initialize() { Apis.Get<Blogs>().Events.BeforeUpdate += new BlogBeforeUpdateEventHandler(BlogEvent_BeforeUpdate); } private void BlogEvent_BeforeUpdate(BlogBeforeUpdateEventArgs blog) { var message = string.Format("{0} with {1} ID, is going to be updated.", blog.Name, blog.Id); var options = new EventLogEntryWriteOptions { Category = "Samples" }; Apis.Get<EventLog>().Write(message, options); }
After Update
This sample shows how to write an event log after a blog post was updated.
public void Initialize() { Apis.Get<Blogs>().Events.AfterUpdate += new BlogAfterUpdateEventHandler(BlogEvent_AfterUpdate); } private void BlogEvent_AfterUpdate(BlogAfterUpdateEventArgs blog) { var message = string.Format("{0} with {1} ID, was updated.", blog.Name, blog.Id); var options = new EventLogEntryWriteOptions { Category = "Samples" }; Apis.Get<EventLog>().Write(message, options); }
Before Delete
This sample shows how to write an event log before a blog post is deleted.
public void Initialize() { Apis.Get<Blogs>().Events.BeforeDelete += new BlogBeforeDeleteEventHandler(BlogEvent_BeforeDelete); } private void BlogEvent_BeforeDelete(BlogBeforeDeleteEventArgs blog) { var message = string.Format("{0} with {1} ID, will be deleted.", blog.Name, blog.Id); var options = new EventLogEntryWriteOptions { Category = "Samples" }; Apis.Get<EventLog>().Write(message, options); }
After Delete
This sample shows how to write an event log after a blog post is deleted.
public void Initialize() { Apis.Get<Blogs>().Events.AfterDelete += new BlogAfterDeleteEventHandler(BlogEvent_AfterDelete); } private void BlogEvent_AfterDelete(BlogAfterDeleteEventArgs blog) { var message = string.Format("{0} with {1} ID, was deleted.", blog.Name, blog.Id); var options = new EventLogEntryWriteOptions { Category = "Samples" }; Apis.Get<EventLog>().Write(message, options); }