/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void ExecuteCommands(IEnumerable<ICommandMapping> mappings, CommandPayload payload = null)
		{
			foreach (ICommandMapping mapping in mappings) 
			{
				ExecuteCommand(mapping, payload);
			}
		}
		public void ExecuteCommand(ICommandMapping mapping, CommandPayload payload = null)
		{
			bool hasPayload = payload !=null && payload.HasPayload();
			bool injectionEnabled = hasPayload && mapping.PayloadInjectionEnabled;
			object command = null;

			if (injectionEnabled)
				MapPayload(payload);
				
			if (mapping.Guards.Count == 0 || Guards.Approve(_injector, mapping.Guards))
			{
				Type commandClass = mapping.CommandClass;
				if (mapping.FireOnce && _removeMapping != null)
					_removeMapping (mapping);
				command = _injector.GetOrCreateNewInstance(commandClass);
				if (mapping.Hooks.Count > 0)
				{
					_injector.Map(commandClass).ToValue(command);
					Hooks.Apply(_injector, mapping.Hooks);
					_injector.Unmap(commandClass);
				}
			}

			if (injectionEnabled)
				UnmapPayload(payload);

			if (command != null && mapping.ExecuteMethod != null) 
			{
				MethodInfo executeMethod = command.GetType().GetMethod (mapping.ExecuteMethod);
				object result = (hasPayload && executeMethod.GetParameters ().Length > 0)
					? executeMethod.Invoke (command, payload.Values.ToArray ())
					: executeMethod.Invoke (command, null);
				if (_handleResult != null)
					_handleResult.Invoke (result, command, mapping);
			}
		}	
		private void UnmapPayload(CommandPayload payload)
		{
			int i = (int)payload.length;
			while (i-- > 0)
			{
				_injector.Unmap(payload.Classes [i]);
			}
		}
		/*============================================================================*/
		/* Private Functions                                                          */
		/*============================================================================*/

		private void MapPayload(CommandPayload payload)
		{
			int i = (int)payload.length;
			while (i-- > 0)
			{
				_injector.Map (payload.Classes [i]).ToValue (payload.Values [i]);
			}
		}
		/*============================================================================*/
		/* Private Functions                                                          */
		/*============================================================================*/

		private CommandPayload createConfig(List<object> values = null, List<Type> classes = null)
		{
			return subject = new CommandPayload(values, classes);
		}
Пример #6
0
 public void Execute(robotlegs.bender.extensions.commandCenter.api.CommandPayload payload = null)
 {
     _executor.ExecuteCommands(_mappings.GetList(), payload);
 }