using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BuzzGUI.Common
{
///
/// Defines the interface for a strategy of execution for the CommandBehaviorBinding
///
public interface IExecutionStrategy
{
///
/// Gets or sets the Behavior that we execute this strategy
///
CommandBehaviorBinding Behavior { get; set; }
///
/// Executes according to the strategy type
///
/// The parameter to be used in the execution
void Execute(object parameter);
}
///
/// Executes a command
///
public class CommandExecutionStrategy : IExecutionStrategy
{
#region IExecutionStrategy Members
///
/// Gets or sets the Behavior that we execute this strategy
///
public CommandBehaviorBinding Behavior { get; set; }
///
/// Executes the Command that is stored in the CommandProperty of the CommandExecution
///
/// The parameter for the command
public void Execute(object parameter)
{
if (Behavior == null)
throw new InvalidOperationException("Behavior property cannot be null when executing a strategy");
if (Behavior.Command.CanExecute(Behavior.CommandParameter))
Behavior.Command.Execute(Behavior.CommandParameter);
}
#endregion
}
///
/// executes a delegate
///
public class ActionExecutionStrategy : IExecutionStrategy
{
#region IExecutionStrategy Members
///
/// Gets or sets the Behavior that we execute this strategy
///
public CommandBehaviorBinding Behavior { get; set; }
///
/// Executes an Action delegate
///
/// The parameter to pass to the Action
public void Execute(object parameter)
{
Behavior.Action(parameter);
}
#endregion
}
}