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

Initializes a new instance of the CustomCommand class.

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

Syntax

C#
public CustomCommand(
	Command trigger
)
Visual Basic (Declaration)
Public Sub New ( _
	trigger As Command _
)
Visual C++
public:
CustomCommand(
	Command^ trigger
)

Parameters

trigger
Type: Firefly.Box..::.Command
The trigger that will invoke this CustomCommand

Examples

The example demonstrates the deferent overloads of the 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.
CopyC#
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 CustomCommandDemonstration
    {
        [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