65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using NLog;
|
|
using Server.Git;
|
|
|
|
namespace Server.System
|
|
{
|
|
public class GItWebhook
|
|
{
|
|
private static readonly NLog.ILogger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
public static Thread thread;
|
|
|
|
private static AbstractGit git;
|
|
public static ErrorResp successResp;
|
|
|
|
public static string Process(HttpContext context)
|
|
{
|
|
string Response;
|
|
try
|
|
{
|
|
string eaDelivery = context.Request.Headers["X-Gitea-Delivery"];
|
|
|
|
logger.Info($"SaveVersion : {eaDelivery}");
|
|
|
|
Response = successResp.ToJson();
|
|
|
|
//무작위 공격을 대비한 1차적인 방어조치
|
|
if (eaDelivery == "" || eaDelivery.Length < 15)
|
|
return Response;
|
|
|
|
if (thread.ThreadState == ThreadState.Stopped)
|
|
{
|
|
logger.Info("new excel update");
|
|
thread = new Thread(git.Init);
|
|
thread.Start();
|
|
}
|
|
else if (thread.ThreadState == ThreadState.WaitSleepJoin || thread.ThreadState == ThreadState.Running)
|
|
{
|
|
logger.Info("new excel restart");
|
|
git.isRestart = true;
|
|
}
|
|
}
|
|
catch (RuntimeException ex)
|
|
{
|
|
ErrorResp error = new ErrorResp(ex);
|
|
Response = error.ToJson();
|
|
logger.Error("GetErrorResponse : " + Response);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorResp error = new ErrorResp();
|
|
Response = error.ToJson();
|
|
logger.Error("GetErrorResponse : " + ex.ToString());
|
|
}
|
|
return Response;
|
|
|
|
}
|
|
|
|
public static void Init()
|
|
{
|
|
git = new XlsxToJson();
|
|
thread = new Thread(git.Init);
|
|
}
|
|
}
|
|
}
|