public async Task <LogCalorieResult> LogCalorie(LogCalorieDto logDto) { var command = new LogCalorieCommand(logDto); var handler = _commands.Build(command); return(await handler.ExecuteAsync()); }
public async Task <LogWeightResult> LogWeight(LogWeightDto logDto) { var command = new LogWeightCommand(logDto); var handler = _commands.Build(command); return(await handler.ExecuteAsync()); }
/// <summary> /// Builds the specified command factory. /// </summary> /// <typeparam name="TCommand">The type of the command.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <typeparam name="TParameter">The type of the parameter.</typeparam> /// <param name="commandFactory">The command factory.</param> /// <param name="owner">The owner.</param> /// <param name="comandPropertyExpression">The comand property expression.</param> /// <param name="memberNameFunc">The member name func.</param> /// <param name="executeMethod">The execute method.</param> /// <param name="canExecuteMethod">The can execute method.</param> /// <returns> /// The build command. /// </returns> public static TCommand Build <TCommand, TOwner, TParameter>(this ICommandFactory commandFactory, TOwner owner, Expression <Func <ICommand> > comandPropertyExpression, Func <TParameter, string> memberNameFunc, Action <TParameter> executeMethod, Func <TParameter, bool> canExecuteMethod = null) where TCommand : class, ICommand { var commandName = PropertyUtil.ExtractPropertyName(comandPropertyExpression); var ruleCommandInfo = new RuleCommandInfo( owner, commandName, new PropertyChainContainsMemberRuleSelector <TParameter> (memberNameFunc)); return(canExecuteMethod != null? commandFactory.Build <TCommand, TOwner>(ruleCommandInfo, Activator.CreateInstance(typeof(TCommand), executeMethod, canExecuteMethod) as TCommand) : commandFactory.Build <TCommand, TOwner>(ruleCommandInfo, Activator.CreateInstance(typeof(TCommand), executeMethod) as TCommand)); }
/// <summary> /// Builds the specified command factory. /// </summary> /// <typeparam name="TCommand">The type of the command.</typeparam> /// <typeparam name="TOwner">The type of the owner.</typeparam> /// <param name="commandFactory">The command factory.</param> /// <param name="owner">The owner.</param> /// <param name="comandPropertyExpression">The comand property expression.</param> /// <param name="propertyExpressionForRulesToRun">The property expression for rules to run.</param> /// <param name="executeMethod">The execute method.</param> /// <param name="canExecuteMethod">The can execute method.</param> /// <returns> /// The built command. /// </returns> public static TCommand Build <TCommand, TOwner>(this ICommandFactory commandFactory, TOwner owner, Expression <Func <ICommand> > comandPropertyExpression, Expression <Func <object> > propertyExpressionForRulesToRun, Action executeMethod, Func <bool> canExecuteMethod = null) where TCommand : class, ICommand { var commandName = PropertyUtil.ExtractPropertyName(comandPropertyExpression); var propertyNameForRule = PropertyUtil.ExtractPropertyName(propertyExpressionForRulesToRun); var ruleCommandInfo = new RuleCommandInfo(owner, commandName, new PropertyChainContainsMemberRuleSelector <object>(propertyNameForRule)); return(canExecuteMethod != null? commandFactory.Build <TCommand, TOwner>(ruleCommandInfo, Activator.CreateInstance(typeof(TCommand), executeMethod, canExecuteMethod) as TCommand) : commandFactory.Build <TCommand, TOwner>(ruleCommandInfo, Activator.CreateInstance(typeof(TCommand), executeMethod) as TCommand)); }
public void Run(string[] args) { var options = _optionParser.ParseOptions(args); if (options != null) { _clientProtocol.BaseUrl = new Uri(options.NameNodeUri); _dataTransferProtocol.BaseUrl = new Uri(options.NameNodeUri); var command = _commandFactory.Build(options); _commandDispatcher.Dispatch(command); } }
public Robot Build(string robotStartingPositionInput, string robotCommandInput) { if (robotStartingPositionInput == string.Empty) { throw new ArgumentNullException("Robot start position is required"); } var robotStartingPosition = robotStartingPositionInput.Split(' '); var commands = commandFactory.Build(robotCommandInput); var position = new Position(int.Parse(robotStartingPosition.ElementAt(0)), int.Parse(robotStartingPosition.ElementAt(1)), (Direction)(Enum.Parse(typeof(Direction), robotStartingPosition.ElementAt(2)))); var robot = new Robot(position, commands); return(robot); }