Custom Handler Library compatibility

原帖地址:http://devnet.kentico.com/Knowledge-Base/API-and-Internals/Custom-Handler-Library-compatibility.aspx



This article addresses differences between the old method of defining custom event handlers using Custom Event Handler Libraries, and the new method of using the App_Code class and the extent of the backward compatibility.
Since Kentico CMS v6, a new method of defining Custom Event Handlers has been introduced, a complete description can be found in the  event handlers article .

The old method of using a Custom Event Handler Library project has since been rendered obsolete but basic backwards compatibility has been preserved. The most noticeable difference is that some events may not trigger the handlers they used to, as they are no longer associated with them. For example, saving a document will no longer trigger methods in CustomDataHandler, but only those in the CustomTreeNodeHandler. This is due to a different event association.

An old Custom Event Handler is now called when a related new event handler has been triggered. For example OnBeforeInsert in the CustomTreeNodeHandler will only trigger when DocumentEvents.Insert.Before event has been triggered. This table contains a complete list of all event associations:

Library HandlerApp_Code Handler
  
CustomTreeNodeHandler.OnBeforeInsertDocumentEvents.Insert.Before
CustomTreeNodeHandler.OnAfterInsertDocumentEvents.Insertfter 
CustomTreeNodeHandler.OnBeforeInsertDocumentEvents.InsertLink.Before
CustomTreeNodeHandler.OnAfterInsertDocumentEvents.InsertLink.After
CustomTreeNodeHandler.OnBeforeInsertNewCultureVersionDocumentEvents.InsertNewCulture.Before
CustomTreeNodeHandler.OnAfterInsertNewCultureVersionDocumentEvents.InsertNewCulture.After
CustomTreeNodeHandler.OnBeforeUpdateDocumentEvents.Update.Before
CustomTreeNodeHandler.OnAfterUpdateDocumentEvents.Update.After
CustomTreeNodeHandler.OnBeforeDeleteDocumentEvents.Delete.Before
CustomTreeNodeHandler.OnAfterDeleteDocumentEvents.Delete.After
CustomTreeNodeHandler.OnBeforeCopyDocumentEvents.Copy.Before
CustomTreeNodeHandler.OnAfterCopyDocumentEvents.Copy.After
CustomTreeNodeHandler.OnBeforeMoveDocumentEvents.Move.Before
CustomTreeNodeHandler.OnAfterMoveDocumentEvents.Move.After
  
CustomDataHandler.OnBeforeInsertObjectEvents.Insert.Before
CustomDataHandler.OnAfterInsertObjectEvents.Insert.After
CustomDataHandler.OnBeforeUpdateObjectEvents.Update.Before
CustomDataHandler.OnAfterUpdateObjectEvents.Update.After
CustomDataHandler.OnBeforeDeleteObjectEvents.Delete.Before
CustomDataHandler.OnBeforeDeleteObjectEvents.Delete.After
CustomDataHandler.OnAfterDeleteObjectEvents.GetContent.Execute
CustomDataHandler.OnGetContentDocumentEvents.GetContent.Execute
  
CustomSecurityHandler.OnAuthenticationSecurityEvents.Authenticate.Execute
CustomSecurityHandler.OnClassNameAuthorizationSecurityEvents.AuthorizeClass.Execute
CustomSecurityHandler.OnResourceAuthorizationSecurityEvents.AuthorizeResource.Execute
CustomSecurityHandler.OnUIElementAuthorizationSecurityEvents.AuthorizeUIElement.Execute
CustomSecurityHandler.OnFilterDataSetByPermissionsDocumentEvents.FilterDataSetByPermissions.Execute
CustomSecurityHandler.OnTreeNodeAuthorizationDocumentEvents.AuthorizeDocument.Execute
  
CustomExceptionHandler.OnExceptionSystemEvents.Exception.Execute
  
CustomWorkflowHandler.OnBeforeApproveWorkflowEvents.Approve.Before
CustomWorkflowHandler.OnAfterApproveWorkflowEvents.Approve.After
CustomWorkflowHandler.OnBeforeCheckInWorkflowEvents.CheckIn.Before
CustomWorkflowHandler.OnAfterCheckInWorkflowEvents.CheckIn.After
CustomWorkflowHandler.OnBeforeCheckOutWorkflowEvents.CheckOut.Before
CustomWorkflowHandler.OnAfterCheckOutWorkflowEvents.CheckOut.After
CustomWorkflowHandler.OnBeforePublishWorkflowEvents.Publish.Before
CustomWorkflowHandler.OnAfterPublishWorkflowEvents.Publish.After
CustomWorkflowHandler.OnBeforeRejectWorkflowEvents.Reject.Before
CustomWorkflowHandler.OnAfterRejectWorkflowEvents.Reject.After

It is not recommended to use the old custom handler libraries and try to re-implement them as Custom Global Event Handlers in App_Code as soon as possible. The handler libraries are only supported for backwards compatibility and may be removed completely in future Kentico versions.

In general, you should encounter no problems moving your code from the Custom Handler Library to the App_Code handler class, however there are some differences which need to be addressed by your code.  The most significant change had been made to the event arguments passed to the handler. In the Event Handler Library, the arguments were anonymous objects which had to be typecast as IDataClass in order to be used. The new handlers receive strongly typed argument <Handler type>EventArgs e containing either TreeNode e.Node or BaseInfo e.Object with all data related to the object tied to the event. Even though the typecasting of these properties is no longer necessary to access contained information, it is possible to typecast both of them as IDataContainer, as an alternative to the IDataClass. However this is not a recommended practice and should be avoided when possible. You can find more detailed description of which handler class accepts which EventArgs class in the article linked above.
- jd-



See also:  
Event Handlers Overview
Obsolete Event Handlers
Data Handler
Exception Handler
Security Handler
TreeNode Handler
Workflow Handler

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值