CustomCommand(Command) Constructor

Initializes a new instance of the CustomCommand class.

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public CustomCommand(
	Command trigger
)

Parameters

trigger  Command
The trigger that will invoke this CustomCommand

Example

The example demonstrates the deferent overloads of the CustomCommand constructor and it's usage
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 Firefly.Box.Testing;
using NUnit.Framework;
using Firefly.Box;

namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class CustomCommandDemo
    {
        [Test]
        public void UsageOfCustomCommand()
        {
            var bp = new BusinessProcess();
            var command = new CustomCommand();
            bool happened = false;
            bp.Handlers.Add(command).Invokes += e => happened = true;
            bp.ForFirstRow(() =>
            {
                happened.ShouldBe(false);
                bp.Invoke(command);
                happened.ShouldBe(true);
            });
        }

        [Test]
        public void UsageOfCustomCommandWithKeyInvokedFromOtherApplication()
        {
            //this is an example of an extreme and non common situation
            var app1 = new ModuleController();
            var app2 = new ModuleController();
            bool happened = false;
            var command = new CustomCommand { Name = "command", Key = "command key", AllowInvokeByKey = CustomCommandAllowInvokeByKey.Always };

            var bp = new BusinessProcess()
                         {
                             Module = app1
                         };

            bp.Handlers.Add(command).Invokes += e => happened = true;
            bp.ForFirstRow(() =>
            {
                var bp2 = new BusinessProcess()
                              {
                                  Module = app2,
                              };
                happened.ShouldBe(false);
                bp2.ForFirstRow(() => bp2.Invoke("command key"));
                happened.ShouldBe(true);
            });
        }
        [Test]
        public void UsageOfCustomCommandWithKeyThatCantBeInvokedFromOtherApplication()
        {
            //this is an example of an extreme and non common situation
            ModuleController app1 = new ModuleController();
            ModuleController app2 = new ModuleController();
            Bool happened = false;
            CustomCommand command = new CustomCommand { Name = "command", Key = "command key", AllowInvokeByKey = CustomCommandAllowInvokeByKey.FromSameModuleOnly };

            BusinessProcess bp = new BusinessProcess();
            bp.Module = app1;
            bp.Handlers.Add(command).Invokes += delegate { happened = true; };
            bp.ForFirstRow(delegate
            {
                BusinessProcess bp2 = new BusinessProcess();
                bp2.Module = app2;
                happened.ShouldBe(false);
                bp2.ForFirstRow(delegate { bp2.Invoke("command key"); });
                happened.ShouldBe(false);
            });
        }
    }
}

See Also