UIControllerInvoke(String, Object) Method

Invokes a customCommandKey that will be handled by an Handler.

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public void Invoke(
	string customCommandKey,
	params Object[] untypedArgs
)

Parameters

customCommandKey  String
The key that will be used to locate the CustomCommand to invoke.
untypedArgs  Object
Arguments to be sent to the Handler that will handle the invoked customCommandKey

Remarks

When the Handler method is called, the framework will iterate the Handlers property collection until it will find an Handler that matches the customCommandKey.
If no matching Handler was found, or if the Handled property was set to true, the framework will iterate the calling task's Handlers property collection and so on.
The deference between Raise and Invoke, is that Raise will queue the customCommandKey, and process it the next time the framework is idle, while Invoke will process it immediately
When invoking a {0} (for example {1}) or a Key Combination, only the relevant Handlers will execute, but the command it self will not. In order to run the command itself use .

Example

Raising and handling of events in a UI
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
This example uses automatic tools to generate parts of the user interface. Those tools can be found in the example of the documentation of Form
C#
using System.Drawing;
using System.Windows.Forms;
using Firefly.Box;

namespace TestFirefly.Box.Documentation
{
    public class DemoRaiseDelete
    {
        public void RaiseDelete()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();

            var uic = new UIController
            {
                From = jobs,
                View = UITools.GenerateFormWithGridFor("Display Jobs",
                                                       "Click the Delete button to delete the current row",
                                                       jobs.Id,
                                                       jobs.Description,
                                                       jobs.MinLevel,
                                                       jobs.MaxLevel)
            };

            var deleteButton = new Button
            {
                Text = "Delete",
            };
            UITools.AddControlsToForm(uic.View, deleteButton);

            //raise the delete command by the button
            deleteButton.Click += (a, b) => uic.Raise(Command.DeleteRow);
            uic.Run();
        }
        public void HandlingDelete()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();

            var uic = new UIController
            {
                From = jobs,
                View = UITools.GenerateFormWithGridFor("Display Jobs",
                                                       "Click the delete button, and see how the custom handler for the delete command"+
                                                       " takes affect",
                                                       jobs.Id,
                                                       jobs.Description,
                                                       jobs.MinLevel,
                                                       jobs.MaxLevel)
            };

            var deleteButton = new Button
            {
                Text = "Delete",
            };
            UITools.AddControlsToForm(uic.View, deleteButton);

            //raise the delete command by the button
            deleteButton.Click += (a, b) => uic.Raise(Command.DeleteRow);

            uic.Handlers.Add(Command.DeleteRow).Invokes += e =>
            {
                if (MessageBox.Show(
                        "Are you sure you want to delete this row",
                        "Confirm Delete",
                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                    e.Handled = false;
            };
            uic.Run();
        }
    }
}

See Also