Created dotnet2.0 Builder Image and Added /v2/specialized Endpoint to dotnet2.0 Envrionment (#1001)

This commit is contained in:
Paras Patidar
2019-05-15 16:35:55 +08:00
committed by Ta-Ching Chen
parent 56fa8fe766
commit 4632269314
35 changed files with 1973 additions and 5 deletions
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Builder.Utility
{
public static class BuilderExtensions
{
public static string GetrelevantPathAsPerOS(this string curruntPath)
{
if (BuilderHelper.Instance.builderSettings.RunningOnwindows)
{
return curruntPath;
}
else
{
return curruntPath.Replace("\\","/");
}
}
}
}
@@ -0,0 +1,180 @@
using Builder.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace Builder.Utility
{
public sealed class BuilderHelper
{
private static readonly Lazy<BuilderHelper> lazy =
new Lazy<BuilderHelper>(() => new BuilderHelper());
public string _logFileName = string.Empty;
public static BuilderHelper Instance { get { return lazy.Value; } }
private static Logger _logger = new Logger("Initial.log");
private BuilderSettings _builderSettings = null;
public BuilderSettings builderSettings
{
get
{
if (_builderSettings == null)
{
string builderSettingsjson = GetBuilderSettingsJson();
_builderSettings = ObjectConverter.Instance.GetBuilderSettingsFromJson(builderSettingsjson);
}
return _builderSettings;
}
set
{
builderSettings = value;
}
}
public Logger logger
{
get
{
return _logger;
}
set
{
_logger = value;
}
}
static BuilderHelper()
{
}
private BuilderHelper()
{
}
private string GetBuilderSettingsJson()
{
var baselocation = AppDomain.CurrentDomain.BaseDirectory;
var FileLocation = baselocation + "builderSettings.json";
return File.ReadAllText(FileLocation);
}
public List<IncludeNuget> GetNugettoInclude(string directoryPath)
{
List<IncludeNuget> includeNugets = new List<IncludeNuget>();
string includeNugetsFilePath = Path.Combine(directoryPath, this.builderSettings.NugetSpecsFile);
if (File.Exists(includeNugetsFilePath))
{
Regex _pkgName = new Regex(this.builderSettings.NugetPackageRegEx,
RegexOptions.Compiled);
string filetext = File.ReadAllText(includeNugetsFilePath);
var _pkgMatchCollection = _pkgName.Matches(filetext);
foreach (Match match in _pkgMatchCollection)
{
if(!string.IsNullOrWhiteSpace(match.Value))
{
string package = match.Groups["package"]?.Value?.Trim();
string version = match.Groups["version"]?.Value?.Trim();
this.logger.Log($"adding {package} | {version} to includeNugets collection");
includeNugets.Add(
new IncludeNuget()
{
packageName = package,
version = version
}
);
}
}
}
return includeNugets;
}
public List<ExcludeDll> GetDllstoExclude(string directoryPath)
{
List<ExcludeDll> excludeDlls = new List<ExcludeDll>();
string excludeDllsFilePath = Path.Combine(directoryPath, this.builderSettings.DllExcludeFile);
if (File.Exists(excludeDllsFilePath))
{
//xyzPackage:abc.dll
Regex _exclude = new Regex(this.builderSettings.ExcludeDllRegEx,
RegexOptions.Compiled);
string filetext = File.ReadAllText(excludeDllsFilePath);
var _excludeMatchCollection = _exclude.Matches(filetext);
foreach (Match match in _excludeMatchCollection)
{
if (!string.IsNullOrWhiteSpace(match.Value))
{
string _package = match.Groups["package"]?.Value?.Trim();
string _dllName = match.Groups["dll"]?.Value?.Trim();
this.logger.Log($"adding {_package} | {_dllName} to excludeDlls collection");
excludeDlls.Add(
new ExcludeDll()
{
packageName = _package,
dllName = _dllName
}
);
}
}
}
return excludeDlls;
}
public string DeepException(Exception ex)
{
string responce = string.Empty;
responce = " Exception : LEVEL 1: " + Environment.NewLine + ex.Message;
if (ex.InnerException != null)
{
responce = responce + Environment.NewLine + "LEVEL 2:" + Environment.NewLine + ex.InnerException.Message;
if (ex.InnerException.InnerException != null)
{
responce =responce + Environment.NewLine + "LEVEL 3:" + Environment.NewLine + ex.InnerException.InnerException.Message;
if (ex.InnerException.InnerException.InnerException != null)
{
responce = responce + Environment.NewLine + "LEVEL 4:" + Environment.NewLine + ex.InnerException.InnerException.InnerException.Message;
if (ex.InnerException.InnerException.InnerException.InnerException != null)
{
responce = responce + Environment.NewLine + "LEVEL 5:" + Environment.NewLine + ex.InnerException.InnerException.InnerException.InnerException.Message;
}
}
}
}
if(ex.StackTrace!=null)
{
responce = responce + "|| STACK :"+ ex.StackTrace;
}
return responce;
}
public void WriteTofile(string filenameWithPath , string content)
{
using (StreamWriter sw = new StreamWriter(filenameWithPath, false))
{
sw.AutoFlush = true;
sw.Write(content);
}
}
}
}
@@ -0,0 +1,111 @@
using log4net;
using NuGet.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace Builder.Utility
{
public class Logger : NuGet.Common.ILogger
{
private ILog _ILog { get; set; }
public Logger(string logpath)
{
//read the log4net config and create logger instance form log4net
XmlDocument ConfigLoader = new XmlDocument();
ConfigLoader.Load(File.OpenRead("log4net.config"));
var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(),
typeof(log4net.Repository.Hierarchy.Hierarchy));
log4net.Config.XmlConfigurator.Configure(repo, ConfigLoader["log4net"]);
var appender = ((log4net.Appender.FileAppender)repo.GetAppenders().Where(x => x.Name == "RollingLogFileAppender").FirstOrDefault());
appender.File = logpath;// $"directoryPath/{DateTime.Now.ToString("yyyy_MM_dd")}_{Guid.NewGuid().ToString()}_.log";
appender.ActivateOptions();
_ILog = LogManager.GetLogger(typeof(Logger));
}
public void Log(string message,bool logToConsoleAsWell=false)
{
if(logToConsoleAsWell)
Console.WriteLine(message);
_ILog.Info(message);
}
public void Log(LogLevel level, string data)
{
//Console.WriteLine(data);
_ILog.Info(data);
}
public void Log(ILogMessage message)
{
//Console.WriteLine(message);
_ILog.Info(message.Message);
}
public Task LogAsync(LogLevel level, string data)
{
//Console.WriteLine(data);
_ILog.Info(data);
return null;
}
public Task LogAsync(ILogMessage message)
{
//Console.WriteLine(message);
_ILog.Info(message.Message);
return null;
}
public void LogDebug(string data)
{
//Console.WriteLine(data);
_ILog.Debug(data);
}
public void LogError(string data)
{
//Console.WriteLine(data);
_ILog.Error(data);
}
public void LogInformation(string data)
{
//Console.WriteLine(data);
_ILog.Info(data);
}
public void LogInformationSummary(string data)
{
//Console.WriteLine(data);
_ILog.Info(data);
}
public void LogMinimal(string data)
{
//Console.WriteLine(data);
_ILog.Info(data);
}
public void LogVerbose(string data)
{
//Console.WriteLine(data);
_ILog.Debug(data);
}
public void LogWarning(string data)
{
//Console.WriteLine(data);
_ILog.Warn(data);
}
}
}
@@ -0,0 +1,31 @@
using Builder.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Builder.Utility
{
public sealed class ObjectConverter
{
private static readonly Lazy<ObjectConverter> lazy =
new Lazy<ObjectConverter>(() => new ObjectConverter());
public static ObjectConverter Instance { get { return lazy.Value; } }
private ObjectConverter()
{
}
public BuilderSettings GetBuilderSettingsFromJson(string json)
{
return JsonConvert.DeserializeObject<BuilderSettings>(json);
}
}
}