|
|
|
@ -1,26 +1,64 @@
|
|
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace AOC2021.Models
|
|
|
|
|
{
|
|
|
|
|
public abstract class AOCDay : IAOCService
|
|
|
|
|
{
|
|
|
|
|
protected AOCRequest _request;
|
|
|
|
|
protected ILogger<AOCDay> _logger;
|
|
|
|
|
protected AOCResponse _response;
|
|
|
|
|
protected ILogger _logger;
|
|
|
|
|
private List<string> _debugMessages;
|
|
|
|
|
|
|
|
|
|
public AOCDay()
|
|
|
|
|
{
|
|
|
|
|
this._response = new AOCResponse()
|
|
|
|
|
{
|
|
|
|
|
Status = false
|
|
|
|
|
};
|
|
|
|
|
this._debugMessages = new List<string>();
|
|
|
|
|
}
|
|
|
|
|
public AOCResponse ExecuteDay(AOCRequest request)
|
|
|
|
|
{
|
|
|
|
|
_request = request;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (request.Version)
|
|
|
|
|
{
|
|
|
|
|
case AOCVersion.A:
|
|
|
|
|
return ExecutePartA();
|
|
|
|
|
this._response = ExecutePartA();
|
|
|
|
|
break;
|
|
|
|
|
case AOCVersion.B:
|
|
|
|
|
return ExecutePartB();
|
|
|
|
|
this._response = ExecutePartB();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this._response.Status = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
this._response.Answer = e.Message;
|
|
|
|
|
this._response.Status = false;
|
|
|
|
|
this._response.StackTrace = e.StackTrace;
|
|
|
|
|
}
|
|
|
|
|
return new AOCResponse() { Answer = "AOCDay failed to get a response", Status = false };
|
|
|
|
|
this._response.Debug = this._debugMessages;
|
|
|
|
|
return this._response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract AOCResponse ExecutePartA();
|
|
|
|
|
protected abstract AOCResponse ExecutePartB();
|
|
|
|
|
|
|
|
|
|
public void SetLogger(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Log(string message, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
if (!this._request.IgnoreLogMessages)
|
|
|
|
|
_logger.LogInformation(message, args);
|
|
|
|
|
_debugMessages.Add(string.Format(message, args));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|