コード例 #1
0
ファイル: Utility.cs プロジェクト: zeeshananjum/n2cms
        /// <summary>Invokes an event and and executes an action unless the event is cancelled.</summary>
        /// <param name="preHandlers">The event handler to signal.</param>
        /// <param name="item">The item affected by 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>
        public static void InvokeEvent(EventHandler <CancellableItemEventArgs> preHandlers, ContentItem item, object sender, Action <ContentItem> finalAction, EventHandler <ItemEventArgs> postHandlers)
        {
            if (preHandlers != null && (VersionsTriggersEvents || !item.VersionOf.HasValue))
            {
                CancellableItemEventArgs args = new CancellableItemEventArgs(item, finalAction);

                preHandlers.Invoke(sender, args);

                if (!args.Cancel)
                {
                    args.FinalAction(args.AffectedItem);
                    if (postHandlers != null)
                    {
                        postHandlers(sender, args);
                    }
                }
            }
            else
            {
                finalAction(item);

                if (postHandlers != null)
                {
                    postHandlers(sender, new ItemEventArgs(item));
                }
            }
        }
コード例 #2
0
ファイル: Utility.cs プロジェクト: wrohrbach/n2cms
        /// <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="item">The item affected by 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>
        public static void InvokeEvent(EventHandler <CancellableItemEventArgs> handler, ContentItem item, object sender, Action <ContentItem> finalAction)
        {
            if (handler != null && (VersionsTriggersEvents || item.VersionOf == null))
            {
                CancellableItemEventArgs args = new CancellableItemEventArgs(item, finalAction);

                handler.Invoke(sender, args);

                if (!args.Cancel)
                {
                    args.FinalAction(args.AffectedItem);
                }
            }
            else
            {
                finalAction(item);
            }
        }