ModuleControllerRaise(Command, Object) Method

Raises a command that will be handled by an Handler.

Definition

Namespace: Firefly.Box.Advanced
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public void Raise(
	Command command,
	params Object[] untypedArgs
)

Parameters

command  Command
The Command to be invoked
untypedArgs  Object
Arguments to be sent to the Handler that will handle the invoked command

Remarks

When the Handler method is called, the command is queued, and the next time the framework is idle (usually in the calling UIController) the framework will iterate the Handlers property collection until it will find an Handler that matches the command.
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 command, and process it the next time the framework is idle, while Invoke will process it immediately

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