/// <summary>Invokes an event and and executes an action unless the event is cancelled.</summary> /// <param name="handler">The event handler to signal.</param> /// <param name="source">The item affected by this operation.</param> /// <param name="destination">The destination of this operation.</param> /// <param name="sender">The source of the event.</param> /// <param name="finalAction">The default action to execute if the event didn't signal cancel.</param> /// <returns>The result of the action (if any).</returns> public static ContentItem InvokeEvent(EventHandler <CancellableDestinationEventArgs> handler, object sender, ContentItem source, ContentItem destination, Func <ContentItem, ContentItem, ContentItem> finalAction, EventHandler <DestinationEventArgs> postHandler) { if (handler != null && (VersionsTriggersEvents || !source.VersionOf.HasValue)) { CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(source, destination, finalAction); handler.Invoke(sender, args); if (args.Cancel) { return(null); } args.AffectedItem = args.FinalAction(args.AffectedItem, args.Destination); if (postHandler != null) { postHandler(sender, args); } return(args.AffectedItem); } var result2 = finalAction(source, destination); if (postHandler != null) { postHandler(sender, new DestinationEventArgs(result2, destination)); } return(result2); }
/// <summary>Invokes an event and and executes an action unless the event is cancelled.</summary> /// <param name="handler">The event handler to signal.</param> /// <param name="source">The item affected by this operation.</param> /// <param name="destination">The destination of this operation.</param> /// <param name="sender">The source of the event.</param> /// <param name="finalAction">The default action to execute if the event didn't signal cancel.</param> /// <returns>The result of the action (if any).</returns> public static ContentItem InvokeEvent(EventHandler <CancellableDestinationEventArgs> handler, object sender, ContentItem source, ContentItem destination, Func <ContentItem, ContentItem, ContentItem> finalAction) { if (handler != null && (VersionsTriggersEvents || source.VersionOf == null)) { CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(source, destination, finalAction); handler.Invoke(sender, args); if (args.Cancel) { return(null); } return(args.FinalAction(args.AffectedItem, args.Destination)); } return(finalAction(source, destination)); }