[This is preliminary documentation and is subject to change.]

Represents the method that will be invoked by the Handler

Namespace:  Firefly.Box.Advanced
Assembly:  Firefly.Box (in Firefly.Box.dll) Version: 3.4.23.6473 (3.4.23.6473)

Syntax

C#
public delegate void HandlerInvokeHandler(
	HandlerInvokeEventArgs e
)
Visual Basic (Declaration)
Public Delegate Sub HandlerInvokeHandler ( _
	e As HandlerInvokeEventArgs _
)
Visual C++
public delegate void HandlerInvokeHandler(
	HandlerInvokeEventArgs^ e
)

Parameters

e
Type: Firefly.Box.Advanced..::.HandlerInvokeEventArgs
The event args for this delegate

Examples

This example demonstrates the usage of HandlerScopeDemo
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using Firefly.Box.Advanced;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class HandlerScopeDemo
    {
        [Test]
        public void HandlerWithCurrentTaskOnlyScope()
        {
            var bp = new BusinessProcess();
            var command = new CustomCommand();
            bool hmoduleened = false;
            var handler = bp.Handlers.Add(command);
            handler.Invokes += e => hmoduleened = true;
            handler.Scope = HandlerScope.CurrentTaskOnly;
            bp.ForFirstRow(() =>
            {
                var childBp = new BusinessProcess();
                childBp.ForFirstRow(() =>
                {
                    childBp.Invoke(command);
                    hmoduleened.ShouldBe(false);//The handler did not execute, because the invoke was done
                    //by childBP and not by the bp, and the scope is CurrentTaskOnly
                });
                bp.Invoke(command);//This time the handler is executed, 
                //as the  invoking BusinessProcess Is the same as the handling BusinessProcess
                hmoduleened.ShouldBe(true);
            });
        }
        [Test]
        public void HandlerWithCurrentContextScope()
        {
            var bp = new BusinessProcess();
            var command = new CustomCommand();
            bool hmoduleened = false;
            var handler = bp.Handlers.Add(command);
            handler.Invokes += e => hmoduleened = true;
            handler.Scope = HandlerScope.CurrentContext;
            bp.ForFirstRow(() =>
            {
                var childBp = new BusinessProcess();
                childBp.ForFirstRow(() =>
                {
                    childBp.Invoke(command);
                    hmoduleened.ShouldBe(true);
                });
            });
        }
        [Test]
        public void HandlerWithUnhandledCustomCommandScope()
        {//This is a demonstration of an extreme situation, with two modules and many deferent scopes
            var module1 = new ModuleController();
            var module1Bp1 = new BusinessProcess()
            {
                Module = module1
            };
            var module1Bp2 = new BusinessProcess()
            {
                Module = module1
            };
            var module2 = new ModuleController();
            var module2Bp1 = new BusinessProcess
            {
                Module = module2
            };
            var module2Bp2 = new BusinessProcess
            {
                Module = module2
            };
            var command = new CustomCommand();
            string handlingSequence = "";

            #region define handlers for all modules and tasks
            {//module1
                var handler = module1.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentContext;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module1CurrentContext,";
                };

            }
            {//module2
                var handler = module2.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentContext;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module2CurrentContext,";
                };
            }
            {
                var handler = module2.Handlers.Add(command);
                handler.Scope = HandlerScope.UnhandledCustomCommandInModule;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module2UnhandledCustomCommand,";
                };
            }
            {//module1Bp1
                var handler = module1Bp1.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentContext;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module1Bp1CurrentContext,";
                };
            }
            {
                var handler = module1Bp1.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentTaskOnly;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module1Bp1CurrentTaskOnly,";
                };
            }
            {//module1Bp2
                var handler = module1Bp2.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentContext;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module1Bp2CurrentContext,";
                };
            }
            {
                var handler = module1Bp2.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentTaskOnly;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module1Bp2CurrentTaskOnly,";
                };
            }
            {//module2Bp1
                var handler = module2Bp1.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentContext;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module2Bp1CurrentContext,";
                };
            }
            {
                var handler = module2Bp1.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentTaskOnly;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module2Bp1CurrentTaskOnly,";
                };
            }
            {//module2Bp2
                var handler = module2Bp2.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentContext;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module2Bp2CurrentContext,";
                };
            }
            {
                var handler = module2Bp2.Handlers.Add(command);
                handler.Scope = HandlerScope.CurrentTaskOnly;
                handler.Invokes += e =>
                {
                    e.Handled = false;
                    handlingSequence += "module2Bp2CurrentTaskOnly,";
                };
            }
            #endregion

            module1Bp1.ForFirstRow(() =>
                module1Bp2.ForFirstRow(() =>
                    module2Bp1.ForFirstRow(() =>
                        module2Bp2.ForFirstRow(() =>
                            module2Bp2.Invoke(command)
                            ))));
            handlingSequence.ShouldBe(
                                      "module2Bp2CurrentContext," +
                                      "module2Bp2CurrentTaskOnly," +
                                      "module2Bp1CurrentContext," +
                                      "module2CurrentContext," +
                                      "module1Bp2CurrentContext," +
                                      "module1Bp1CurrentContext," +
                                      "module1CurrentContext," +
                                      "module2UnhandledCustomCommand,");


        }
    }
}

See Also