示例#1
0
        public CodesResponse GetCode(CodesRequest request)
        {
            if (!_helper.IsDayYearValid(request.Day, request.Year))
            {
                throw new DayOrYearNotValidException();
            }

            var language = request.Language ?? Constants.DefaultLanguage;
            var script   = _helper.BuildScriptPath(request.Year, request.Day, language);

            if (!File.Exists(script))
            {
                throw new DayNotImplementedException();
            }

            return(new CodesResponse
            {
                Language = language,
                Content = File.ReadAllText(script)
            });
        }
示例#2
0
        public object GetResult(CodesRequest request)
        {
            try
            {
                return(_service.GetCode(request));
            }
            catch (AdventOfCodeException e)
            {
                HttpContext.Response.StatusCode = e.Code;
                return(new ProblemDetails {
                    Status = e.Code, Title = e.Title, Detail = e.Message
                });
            }
            catch (Exception e)
            {
                // logging

                HttpContext.Response.StatusCode = 500;
                return(new ProblemDetails {
                    Status = 500, Title = "Internal server error.", Detail = e.Message
                });
            }
        }