HandlerCollection Class

Represents a task's handler collection.

Definition

Namespace: Firefly.Box.Advanced
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public class HandlerCollection : IEnumerable
Inheritance
Object    HandlerCollection
Implements
IEnumerable

Remarks

Handlers are added and created by this object, in UIController and BusinessProcess. These handler can change the default behaviours of Commands.

Example

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.
C#
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,");


        }
    }
}

Properties

Count Gets the number of handlers in this collection

Methods

Add(Command)Creates a {0} and adds it to the handlers collection
Add(Keys)Creates a {0} and adds it to the handlers collection
Add(Command, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Command, ControlBase)Creates a {0} and adds it to the handlers collection
Add(Command, PredicateControlBase)Creates a {0} and adds it to the handlers collection
Add(Command, String)Creates a {0} and adds it to the handlers collection
Add(Keys, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Keys, ControlBase)Creates a {0} and adds it to the handlers collection
Add(Keys, PredicateControlBase)Creates a {0} and adds it to the handlers collection
Add(Keys, String)Creates a {0} and adds it to the handlers collection
Add(Command, ControlBase, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Command, PredicateControlBase, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Command, String, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Keys, ControlBase, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Keys, PredicateControlBase, HandlerScope)Creates a {0} and adds it to the handlers collection
Add(Keys, String, HandlerScope)Creates a {0} and adds it to the handlers collection
AddT(String) 
AddT(ComColumnT, String) 
AddT(String, HandlerScope) 
AddT(ComColumnT, String, HandlerScope) 
AddDatabaseErrorHandler(DatabaseErrorType) 
AddDatabaseErrorHandler(DatabaseErrorType, HandlerScope) Adds a DatabaseErrorHandler
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetEnumeratorReturns an enumerator that iterates through a collection.
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
ToStringReturns a string that represents the current object.
(Inherited from Object)

Extension Methods

ShouldBeArray
(Defined by Should)

See Also