public ICommand GetCommand(IInputModel model)
		{
			var partName =
				_inputModelsAndValues.Where(row => row.Value.InputModelType == model.GetType()).Select(row => row.Key).
					FirstOrDefault();

			GuardPartNameRegistered(partName);

			var command = Activator.CreateInstance(_inputModelsAndValues[partName].CommandType) as ICommand;

			if (command == null)
			{
				throw new CannotCreateCommandException();
			}

			command = Mapper.Map(model, command, model.GetType(), command.GetType()) as ICommand;

			if (command == null)
			{
				throw new CannotMapCommandException();
			}

			command.Created = DateTime.Now;

			command.Identifier = Guid.NewGuid();

			return command;
		}
示例#2
0
		public InputModelFormatter(IInputModel inputModel)
		{
			_modelName = inputModel.GetType().Name;
			_commandName = inputModel.CommandType.Name;
			_properties = inputModel
							.GetType()
							.GetProperties()
							.Where(pi => pi.CanWrite)
							.Select(pi =>
							        	{
							        		var v = pi.GetValue(inputModel, null);
											return new Property
							        		       	{
							        		       		Name = pi.Name,
							        		       		Type = pi.PropertyType.Name,
							        		       		Value = (v == null) ? string.Empty : pi.GetValue(inputModel, null).ToString(),
														Choices = pi.PropertyType.IsEnum ? Enum.GetNames(pi.PropertyType) : null,
														MultiChoice = pi.PropertyType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0
							        		       	};
							        	})
							.ToList();
		}