public static string DebugMessage(this Domain.Command.CommandResponse response) { if (VoatSettings.Instance.IsDevelopment) { if (response.Exception != null) { return(response.Exception.ToString()); } } return(response.Message); }
protected override async Task <CommandResponse <Submission> > ExecuteStage(CommandStage stage, CommandResponse <Submission> previous) { switch (stage) { case CommandStage.OnValidation: if (_userSubmission.Content.Length > 10000) { return(CommandResponse.FromStatus <Submission>(null, Status.Invalid, "Content can not exceed 10,000 characters")); } break; } return(await base.ExecuteStage(stage, previous)); }
protected override async Task <CommandResponse <Vote> > ExecuteStage(CommandStage stage, CommandResponse <Vote> previous) { switch (stage) { case CommandStage.OnExecuting: //perform validationn return non-success if not success break; } return(await base.ExecuteStage(stage, previous)); }
//So any command can invoke the rules engine //protected RulesEngine.RulesEngine<VoatRuleContext> rulesEngine = VoatRulesEngine.Instance; protected CommandResponse Map(RulesEngine.RuleOutcome outcome) { return(CommandResponse.FromStatus(outcome.Message, Status.Denied, outcome.ToString())); }
public override Task <T> Execute() { _commands.Add(this); return(Task.FromResult((T)CommandResponse.FromStatus(Status.Queued))); }
protected CommandResponse <T> Map <T>(RulesEngine.RuleOutcome outcome) { return(CommandResponse.FromStatus(default(T), Status.Denied, outcome.Message)); }
public static CommandResponse <M> Map <T, M>(CommandResponse <T> response, M mapped) { return(new CommandResponse <M>(mapped, response.Status, response.Message)); }
protected override async Task <CommandResponse <Models.Comment> > ExecuteStage(CommandStage stage, CommandResponse <Models.Comment> previous) { switch (stage) { case CommandStage.OnValidation: if (Content.Length > 10000) { return(CommandResponse.FromStatus <Models.Comment>(null, Status.Denied, "Comment can not exceed 10,000 characters")); } break; } return(CommandResponse.FromStatus <Models.Comment>(null, Status.Success)); }
protected override async Task <CommandResponse <VoteTracker> > ExecuteStage(CommandStage stage, CommandResponse <VoteTracker> previous) { switch (stage) { case CommandStage.OnExecuting: var q = new QueryVote(_voteID); var vote = await q.ExecuteAsync(); var notPassed = vote.Restrictions.FirstOrDefault(x => { var e = x.Evaluate(User); return(!e.Success); }); _restrictionsPassed = notPassed == null; break; case CommandStage.OnExecuted: if (previous.Success) { CacheHandler.Instance.Remove(CachingKey.VoteStatistics(_voteID)); } break; } return(await base.ExecuteStage(stage, previous)); }
protected override async Task <CommandResponse <Submission> > ExecuteStage(CommandStage stage, CommandResponse <Submission> previous) { switch (stage) { case CommandStage.OnValidation: var results = ValidationHandler.Validate(_userSubmission); if (!results.IsNullOrEmpty()) { return(CommandResponse.Invalid <Submission>(results)); } break; } return(await base.ExecuteStage(stage, previous)); }