Example #1
0
        public async Task <IActionResult> Flag([FromBody] CheckerTaskMessage ctm)
        {
            // TODO merge .RequestAborted with timer
            using var scope = this.logger.BeginEnoScope(ctm);
            this.logger.LogDebug(ctm.ToString());
            try
            {
                if (ctm.Method == CheckerTaskMethod.putflag)
                {
                    await this.checker.HandlePutFlag(ctm, this.HttpContext.RequestAborted);
                }
                else if (ctm.Method == CheckerTaskMethod.getflag)
                {
                    await this.checker.HandleGetFlag(ctm, this.HttpContext.RequestAborted);
                }
                else if (ctm.Method == CheckerTaskMethod.putnoise)
                {
                    await this.checker.HandlePutNoise(ctm, this.HttpContext.RequestAborted);
                }
                else if (ctm.Method == CheckerTaskMethod.getnoise)
                {
                    await this.checker.HandleGetNoise(ctm, this.HttpContext.RequestAborted);
                }
                else if (ctm.Method == CheckerTaskMethod.havoc)
                {
                    await this.checker.HandleHavoc(ctm, this.HttpContext.RequestAborted);
                }
                else
                {
                    throw new Exception("invalid method");
                }

                this.logger.LogInformation($"Task {ctm.TaskId} succeeded");
                return(this.Json(new CheckerResultMessage(CheckerResult.OK, null, null)));
            }
            catch (OperationCanceledException)
            {
                this.logger.LogWarning($"Task {ctm.TaskId} was cancelled");
                return(this.Json(new CheckerResultMessage(CheckerResult.OFFLINE, null, null)));
            }
            catch (MumbleException e)
            {
                this.logger.LogWarning($"Task {ctm.TaskId} has failed: {e.ToFancyString()}");
                return(this.Json(new CheckerResultMessage(CheckerResult.MUMBLE, e.Message, null)));
            }
            catch (OfflineException e)
            {
                this.logger.LogWarning($"Task {ctm.TaskId} has failed: {e.ToFancyString()}");
                return(this.Json(new CheckerResultMessage(CheckerResult.OFFLINE, e.Message, null)));
            }
            catch (Exception e)
            {
                this.logger.LogError($"Task {ctm.TaskId} has failed: {e.ToFancyString()}");
                return(this.Json(new CheckerResultMessage(CheckerResult.INTERNAL_ERROR, null, null)));
            }
        }
 public IActionResult Flag([FromBody] CheckerTaskMessage ctm)
 {
     Logger.LogDebug(ctm.ToString());
     return(Ok("{ \"result\": \"OK\" }"));
 }