public ActionResult Index() { var req = Request.Body; var json = new StreamReader(req).ReadToEnd(); Update update = JsonConvert.DeserializeObject <Update>(json); IAction action; if (update.Message == null) { return(Content("OK")); } switch (update.Message.Command) { //TODO: add user concerned by vote here case Models.Commands.VoteBan: action = new VoteBanAction(update.Message, update.Message.Param); break; case Models.Commands.VoteMute: action = new VoteMuteAction(update.Message, update.Message.Param); break; case Models.Commands.VoteNoSticker: action = new VoteNoStickerAction(update.Message, update.Message.Param); break; case Models.Commands.VoteRelease: action = new VoteReleaseAction(update.Message, update.Message.Param); break; case Models.Commands.SetTitle: action = new SetTitleAction(update.Message); break; default: action = new NoneAction(); break; } action.execute(); return(Content("OK")); }
private void ParseUrlAction(XElement urlAction, UrlRewriteRuleBuilder builder, bool stopProcessing) { var actionType = ParseEnum(urlAction, RewriteTags.Type, ActionType.None); UrlAction action; switch (actionType) { case ActionType.None: action = new NoneAction(stopProcessing ? RuleResult.SkipRemainingRules : RuleResult.ContinueRules); break; case ActionType.Rewrite: case ActionType.Redirect: var url = string.Empty; if (urlAction.Attribute(RewriteTags.Url) != null) { url = urlAction.Attribute(RewriteTags.Url).Value; if (string.IsNullOrEmpty(url)) { throw new InvalidUrlRewriteFormatException(urlAction, "Url attribute cannot contain an empty string"); } } var urlPattern = _inputParser.ParseInputString(url, builder.UriMatchPart); var appendQuery = ParseBool(urlAction, RewriteTags.AppendQueryString, defaultValue: true); if (actionType == ActionType.Rewrite) { action = new RewriteAction(stopProcessing ? RuleResult.SkipRemainingRules : RuleResult.ContinueRules, urlPattern, appendQuery); } else { var redirectType = ParseEnum(urlAction, RewriteTags.RedirectType, RedirectType.Permanent); action = new RedirectAction((int)redirectType, urlPattern, appendQuery); } break; case ActionType.AbortRequest: action = new AbortAction(); break; case ActionType.CustomResponse: int statusCode; if (!int.TryParse(urlAction.Attribute(RewriteTags.StatusCode)?.Value, out statusCode)) { throw new InvalidUrlRewriteFormatException(urlAction, "A valid status code is required"); } if (statusCode < 200 || statusCode > 999) { throw new NotSupportedException("Status codes must be between 200 and 999 (inclusive)"); } if (!string.IsNullOrEmpty(urlAction.Attribute(RewriteTags.SubStatusCode)?.Value)) { throw new NotSupportedException("Substatus codes are not supported"); } var statusReason = urlAction.Attribute(RewriteTags.StatusReason)?.Value; var statusDescription = urlAction.Attribute(RewriteTags.StatusDescription)?.Value; action = new CustomResponseAction(statusCode) { StatusReason = statusReason, StatusDescription = statusDescription }; break; default: throw new NotSupportedException($"The action type {actionType} wasn't recognized"); } builder.AddUrlAction(action); }