Add /revision.

This commit is contained in:
Irina Tiulneva 2021-06-04 15:57:43 +03:00
parent 720c864d73
commit 4c97d2cadc
5 changed files with 162 additions and 0 deletions

119
Web/App_Code/DebugInfo.cs Normal file
View File

@ -0,0 +1,119 @@
using log4net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
public class DebugInfo
{
private static string basePath;
private static bool isInit;
private static object obj = new object();
public static string DebugString { get; private set; }
public static string BranchName { get; private set; }
public const string TemplateName = "change.log";
public const string DataName = "changelog.xml";
public const string ResultName = "changelog.txt";
public static void Init()
{
if (isInit) return;
lock (obj)
{
if (isInit) return;
try
{
basePath = HttpContext.Current.Server.MapPath("~/");
DebugString = GetStaticDebugString();
isInit = true;
}
catch (Exception)
{
}
}
}
private static string GetStaticDebugString()
{
var ChangeLogFilePath = Path.Combine(basePath, DataName);
var ResultNameFilePath = Path.Combine(basePath, ResultName);
if (!File.Exists(ChangeLogFilePath) && File.Exists(ResultNameFilePath))
{
return File.ReadAllText(ResultNameFilePath);
}
var ChangeLogPatternFilePath = Path.Combine(basePath, TemplateName);
var xmlLog = new XmlDocument();
xmlLog.Load(ChangeLogFilePath);
var logs = xmlLog.SelectNodes("//lastBuiltRevision");
if (logs == null) return "";
var nodes = logs.Cast<XmlNode>().ToList();
try
{
var fileContent = File.ReadAllText(ChangeLogPatternFilePath, Encoding.Default);
var lastCommitIDNode = nodes.LastOrDefault();
var branchNameNode = lastCommitIDNode;
if (lastCommitIDNode != null)
{
var lastCommitID = lastCommitIDNode.SelectSingleNode("SHA1");
if (lastCommitID != null)
{
fileContent = fileContent.Replace("{RevisionLast}", lastCommitID.InnerText);
}
}
else
{
fileContent = fileContent.Replace("{RevisionLast}", "");
}
if (branchNameNode != null)
{
var branchName = branchNameNode.SelectSingleNode(".//name");
if (branchName != null)
{
fileContent = fileContent.Replace("{BranchName}", branchName.InnerText);
}
}
else
{
fileContent = fileContent.Replace("{BranchName}", "");
}
File.WriteAllText(ResultNameFilePath, fileContent);
if (File.Exists(ChangeLogFilePath))
{
File.Delete(ChangeLogFilePath);
}
return fileContent;
}
catch (Exception e)
{
LogManager.GetLogger("ASC.DebugInfo").Error("DebugInfo", e);
}
return "";
}
private static bool IsServiceLogItem(string log)
{
return Regex.IsMatch(log, "(^Merged)|(^Sql)", RegexOptions.IgnoreCase);
}
}

View File

@ -20,6 +20,7 @@ public class Global : HttpApplication
void Application_Start(object sender, EventArgs e)
{
XmlConfigurator.Configure();
DebugInfo.Init();
}
void Application_End(object sender, EventArgs e)

View File

@ -0,0 +1,22 @@
using System;
using System.Linq;
using System.Web;
using System.IO;
namespace TeamLab.HttpHandlers
{
public class RevisionHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
var DebugString = DebugInfo.DebugString;
string result = DebugString;
context.Response.Write(result);
}
}
}

1
Web/change.log Normal file
View File

@ -0,0 +1 @@
{RevisionLast} {BranchName}

View File

@ -78,11 +78,28 @@
<pages pageBaseType="BasePage" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
<httpHandlers>
<add verb="*" path="*.less" type="dotless.Core.LessCssHttpHandler, dotless.Core" validate="false" />
<add verb="GET" path="/revision" type="TeamLab.HttpHandlers.RevisionHandler, __Code" />
</httpHandlers>
<httpModules>
<add name="HttpContextDispose" type="ASC.Common.Web.DisposableHttpContextHttpModule, ASC.Common"/>
</httpModules>
</system.web>
<log4net>
<logger name="ASC">
<appender-ref ref="Site" />
<level value="ALL" />
</logger>
<appender name="Site" type="log4net.Appender.RollingFileAppender">
<file value="..\Logs\Helpcenter.Site.log" />
<encoding value="utf-8" />
<rollingstyle value="Size" />
<maxsizerollbackups value="10" />
<maximumfilesize value="50MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level [%thread] %logger - %message%newline" />
</layout>
</appender>
</log4net>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<rewrite>
@ -1557,9 +1574,11 @@
<remove name="AjaxPoster"/>
<remove name="AdminAjaxPoster"/>
<remove name="BannerPoster"/>
<remove name="Revision" />
<remove name="less" />
<add verb="POST,GET" name="AjaxPoster" path="post.ashx" type="TeamLab.HttpHandlers.PosterHandler, __Code"/>
<add verb="POST,GET" name="AdminAjaxPoster" path="adminpost.ashx" type="TeamLab.HttpHandlers.PosterAdminHandler, __Code"/>
<add verb="GET" name="Revision" path="revision" type="TeamLab.HttpHandlers.RevisionHandler, __Code" />
<add verb="*" name="BannerPoster" path="*/banner.png" type="TeamLab.HttpHandlers.BannerHandler, __Code"/>
<add name="less" verb="*" path="*.less" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</handlers>