2021-06-04 12:57:43 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-17 16:20:34 +00:00
|
|
|
|
public static string GetStaticDebugString()
|
2021-06-04 12:57:43 +00:00
|
|
|
|
{
|
|
|
|
|
var ChangeLogFilePath = Path.Combine(basePath, DataName);
|
|
|
|
|
var ResultNameFilePath = Path.Combine(basePath, ResultName);
|
|
|
|
|
|
2021-06-18 12:32:58 +00:00
|
|
|
|
if (File.Exists(ResultNameFilePath))
|
2021-06-04 12:57:43 +00:00
|
|
|
|
{
|
2021-06-10 14:12:30 +00:00
|
|
|
|
if (File.ReadAllText(ResultNameFilePath, Encoding.Default) != "")
|
|
|
|
|
{
|
|
|
|
|
return File.ReadAllText(ResultNameFilePath);
|
|
|
|
|
}
|
2021-06-04 12:57:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 11:22:13 +00:00
|
|
|
|
if (!File.Exists(ChangeLogFilePath)) {
|
|
|
|
|
return "changelog.xml doesn't exist";
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 10:03:03 +00:00
|
|
|
|
var ChangeLogPatternFilePath = Path.Combine(basePath, TemplateName);
|
2021-06-04 12:57:43 +00:00
|
|
|
|
|
2021-06-18 10:03:03 +00:00
|
|
|
|
var xmlLog = new XmlDocument();
|
|
|
|
|
xmlLog.Load(ChangeLogFilePath);
|
2021-06-04 12:57:43 +00:00
|
|
|
|
|
2021-06-18 10:03:03 +00:00
|
|
|
|
var logs = xmlLog.SelectNodes("//lastBuiltRevision");
|
|
|
|
|
if (logs == null) return "";
|
|
|
|
|
var nodes = logs.Cast<XmlNode>().ToList();
|
2021-06-04 12:57:43 +00:00
|
|
|
|
|
2021-06-18 10:03:03 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var fileContent = File.ReadAllText(ChangeLogPatternFilePath, Encoding.Default);
|
2021-06-04 12:57:43 +00:00
|
|
|
|
|
2021-06-18 10:03:03 +00:00
|
|
|
|
var lastCommitIDNode = nodes.LastOrDefault();
|
|
|
|
|
var branchNameNode = lastCommitIDNode;
|
2021-06-04 12:57:43 +00:00
|
|
|
|
|
2021-06-18 10:03:03 +00:00
|
|
|
|
if (lastCommitIDNode != null)
|
|
|
|
|
{
|
|
|
|
|
var lastCommitID = lastCommitIDNode.SelectSingleNode("SHA1");
|
|
|
|
|
if (lastCommitID != null)
|
2021-06-17 16:20:34 +00:00
|
|
|
|
{
|
2021-06-18 10:03:03 +00:00
|
|
|
|
fileContent = fileContent.Replace("{RevisionLast}", lastCommitID.InnerText);
|
2021-06-17 16:20:34 +00:00
|
|
|
|
}
|
2021-06-18 10:03:03 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fileContent = fileContent.Replace("{RevisionLast}", "");
|
|
|
|
|
}
|
|
|
|
|
if (branchNameNode != null)
|
|
|
|
|
{
|
|
|
|
|
var branchName = branchNameNode.SelectSingleNode(".//name");
|
|
|
|
|
if (branchName != null)
|
2021-06-17 16:20:34 +00:00
|
|
|
|
{
|
2021-06-18 10:03:03 +00:00
|
|
|
|
fileContent = fileContent.Replace("{BranchName}", branchName.InnerText);
|
2021-06-17 16:20:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-18 10:03:03 +00:00
|
|
|
|
else
|
2021-06-04 12:57:43 +00:00
|
|
|
|
{
|
2021-06-18 10:03:03 +00:00
|
|
|
|
fileContent = fileContent.Replace("{BranchName}", "");
|
2021-06-04 12:57:43 +00:00
|
|
|
|
}
|
2021-06-18 10:03:03 +00:00
|
|
|
|
|
|
|
|
|
File.WriteAllText(ResultNameFilePath, fileContent);
|
|
|
|
|
|
|
|
|
|
return fileContent;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
LogManager.GetLogger("ASC.DebugInfo").Error("DebugInfo", e);
|
2021-06-18 11:42:31 +00:00
|
|
|
|
return "e.Message: " + e.Message;
|
2021-06-04 12:57:43 +00:00
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsServiceLogItem(string log)
|
|
|
|
|
{
|
|
|
|
|
return Regex.IsMatch(log, "(^Merged)|(^Sql)", RegexOptions.IgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
}
|