MET08THFTIRQS408M - v2.43.0 - Using EDA

Multiple Storage Paths and delete old way
This commit is contained in:
2022-06-07 11:13:11 -07:00
parent ad688483ed
commit 72a9f902bc
72 changed files with 3713 additions and 2018 deletions

View File

@ -0,0 +1,36 @@
using Microsoft.Extensions.Logging;
using System;
namespace Adaptation._Tests.Shared.Log;
public class ConsoleLogger : ILogger
{
public int EventId { get; set; }
private readonly string _Name;
private readonly LogLevel _LogLevel;
public ConsoleLogger(LogLevel logLevel, string name)
{
_Name = name;
EventId = 0;
_LogLevel = logLevel;
if (string.IsNullOrEmpty(_Name))
{ }
}
public IDisposable BeginScope<TState>(TState state) => null;
public bool IsEnabled(LogLevel logLevel) => logLevel >= _LogLevel;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (IsEnabled(logLevel) && (EventId == 0 || EventId == eventId.Id))
{
string message = formatter(state, null);
Console.WriteLine(message);
}
}
}

View File

@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
namespace Adaptation._Tests.Shared.Log;
public class ConsoleProvider : ILoggerProvider
{
private readonly LogLevel _LogLevel;
private readonly ConcurrentDictionary<string, ConsoleLogger> _Loggers;
public ConsoleProvider(LogLevel logLevel)
{
_LogLevel = logLevel;
_Loggers = new ConcurrentDictionary<string, ConsoleLogger>();
}
public ILogger CreateLogger(string categoryName) => _Loggers.GetOrAdd(categoryName, name => new ConsoleLogger(_LogLevel, name));
public void Dispose()
{
_Loggers.Clear();
GC.SuppressFinalize(this);
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.Extensions.Logging;
using System;
namespace Adaptation._Tests.Shared.Log;
public class DebugLogger : ILogger
{
public int EventId { get; set; }
private readonly string _Name;
private readonly LogLevel _LogLevel;
public DebugLogger(LogLevel logLevel, string name)
{
_Name = name;
EventId = 0;
_LogLevel = logLevel;
if (string.IsNullOrEmpty(_Name))
{ }
}
public IDisposable BeginScope<TState>(TState state) => null;
public bool IsEnabled(LogLevel logLevel) => logLevel >= _LogLevel;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (IsEnabled(logLevel) && (EventId == 0 || EventId == eventId.Id))
{
string message = formatter(state, null);
System.Diagnostics.Debug.Print(message);
}
}
}

View File

@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
namespace Adaptation._Tests.Shared.Log;
public class DebugProvider : ILoggerProvider
{
private readonly LogLevel _LogLevel;
private readonly ConcurrentDictionary<string, DebugLogger> _Loggers;
public DebugProvider(LogLevel logLevel)
{
_LogLevel = logLevel;
_Loggers = new ConcurrentDictionary<string, DebugLogger>();
}
public ILogger CreateLogger(string categoryName) => _Loggers.GetOrAdd(categoryName, name => new DebugLogger(_LogLevel, name));
public void Dispose()
{
_Loggers.Clear();
GC.SuppressFinalize(this);
}
}

View File

@ -0,0 +1,49 @@
using Microsoft.Extensions.Logging;
using System;
namespace Adaptation._Tests.Shared.Log;
public class FeedbackLogger : ILogger
{
public int EventId { get; set; }
private readonly string _Name;
private readonly LogLevel _LogLevel;
private readonly IFeedback _Feedback;
public FeedbackLogger(LogLevel logLevel, IFeedback feedback, string name)
{
_Feedback = feedback;
_Name = name;
EventId = 0;
_LogLevel = logLevel;
if (string.IsNullOrEmpty(_Name))
{ }
}
public IDisposable BeginScope<TState>(TState state) => null;
public bool IsEnabled(LogLevel logLevel) => logLevel >= _LogLevel;
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (IsEnabled(logLevel) && (EventId == 0 || EventId == eventId.Id))
{
string message = formatter(state, null);
int color = logLevel switch
{
LogLevel.Trace => -1,
LogLevel.Debug => -1,
LogLevel.Information => -16776961,
LogLevel.Warning => -65281,
LogLevel.Error => -65536,
LogLevel.Critical => -65536,
LogLevel.None => -1,
_ => throw new Exception(),
};
_Feedback.Print(message, color);
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
namespace Adaptation._Tests.Shared.Log;
public class FeedbackProvider : ILoggerProvider
{
private readonly LogLevel _LogLevel;
private readonly IFeedback _Feedback;
private readonly ConcurrentDictionary<string, FeedbackLogger> _Loggers;
public FeedbackProvider(LogLevel logLevel, IFeedback feedback)
{
_LogLevel = logLevel;
_Feedback = feedback;
_Loggers = new ConcurrentDictionary<string, FeedbackLogger>();
}
public ILogger CreateLogger(string categoryName) => _Loggers.GetOrAdd(categoryName, name => new FeedbackLogger(_LogLevel, _Feedback, name));
public void Dispose()
{
_Loggers.Clear();
GC.SuppressFinalize(this);
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Adaptation._Tests.Shared.Log;
public interface IFeedback
{
List<string> Messages { get; }
void Print(string message, int color);
}

View File

@ -0,0 +1,139 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
namespace Adaptation._Tests.Shared.Log;
public class Log
{
#pragma warning disable CA2254
#pragma warning disable IDE0060
private readonly ILogger _Logger;
public Log(ILogger logger) => _Logger = logger;
public void Black(object message) => _Logger.LogInformation(message.ToString());
public void Blue(object message) => _Logger.LogInformation(message.ToString());
public void Gray(object message) => _Logger.LogInformation(message.ToString());
public void Green(object message) => _Logger.LogInformation(message.ToString());
public void Magenta(string message, Exception exception) => _Logger.LogWarning(message, exception);
public void Red(string message, Exception exception) => _Logger.LogError(message, exception);
public void White(object message) => _Logger.LogInformation(message.ToString());
public void Yellow(string message, Exception exception) => _Logger.LogWarning(message, exception);
//
public void DoLog(LogLevel logLevel, EventId eventId, Exception exception, string message, params object[] args) => _Logger.Log(logLevel, eventId, exception, message, args);
public void DoLog(LogLevel logLevel, EventId eventId, string message, params object[] args) => _Logger.Log(logLevel, eventId, message, args);
public void DoLog(LogLevel logLevel, Exception exception, string message, params object[] args) => _Logger.Log(logLevel, exception, message, args);
public void DoLog(LogLevel logLevel, string message, params object[] args) => _Logger.Log(logLevel, message, args);
public void LogCritical(EventId eventId, Exception exception, string message, params object[] args) => _Logger.LogCritical(eventId, exception, message, args);
public void LogCritical(EventId eventId, string message, params object[] args) => _Logger.LogCritical(eventId, message, args);
public void LogCritical(Exception exception, string message, params object[] args) => _Logger.LogCritical(exception, message, args);
public void LogCritical(string message, params object[] args) => _Logger.LogCritical(message, args);
public void LogDebug(EventId eventId, Exception exception, string message, params object[] args) => _Logger.LogDebug(eventId, exception, message, args);
public void LogDebug(EventId eventId, string message, params object[] args) => _Logger.LogDebug(eventId, message, args);
public void LogDebug(Exception exception, string message, params object[] args) => _Logger.LogDebug(exception, message, args);
public void LogDebug(string message, params object[] args) => _Logger.LogDebug(message, args);
public void LogError(EventId eventId, Exception exception, string message, params object[] args) => _Logger.LogError(eventId, exception, message, args);
public void LogError(EventId eventId, string message, params object[] args) => _Logger.LogError(eventId, message, args);
public void LogError(Exception exception, string message, params object[] args) => _Logger.LogError(message, args);
public void LogError(string message, params object[] args) => _Logger.LogError(message, args);
public void LogInformation(EventId eventId, Exception exception, string message, params object[] args) => _Logger.LogInformation(eventId, exception, message, args);
public void LogInformation(EventId eventId, string message, params object[] args) => _Logger.LogInformation(eventId, message, args);
public void LogInformation(Exception exception, string message, params object[] args) => _Logger.LogInformation(exception, message, args);
public void LogInformation(string message, params object[] args) => _Logger.LogInformation(message, args);
public void LogTrace(EventId eventId, Exception exception, string message, params object[] args) => _Logger.LogTrace(eventId, exception, message, args);
public void LogTrace(EventId eventId, string message, params object[] args) => _Logger.LogTrace(eventId, message, args);
public void LogTrace(Exception exception, string message, params object[] args) => _Logger.LogTrace(exception, message, args);
public void LogTrace(string message, params object[] args) => _Logger.LogTrace(message, args);
public void LogWarning(EventId eventId, Exception exception, string message, params object[] args) => _Logger.LogWarning(eventId, exception, message, args);
public void LogWarning(EventId eventId, string message, params object[] args) => _Logger.LogWarning(eventId, message, args);
public void LogWarning(Exception exception, string message, params object[] args) => _Logger.LogWarning(exception, message, args);
public void LogWarning(string message, params object[] args) => _Logger.LogWarning(message, args);
//
public void Debug() => _Logger.LogDebug(string.Empty);
public void Debug(object message) => _Logger.LogDebug(message.ToString());
public void Debug(string message, Exception exception) => _Logger.LogDebug(exception, message);
public void DebugFormat(IFormatProvider provider, string format, params object[] args) => _Logger.LogDebug(string.Format(provider, format, args));
public void DebugFormat(string format, object arg0, object arg1, object arg2) => _Logger.LogDebug(string.Format(format, arg0, arg1, arg2));
public void DebugFormat(string format, object arg0, object arg1) => _Logger.LogDebug(string.Format(format, arg0, arg1));
public void DebugFormat(string format, object arg0) => _Logger.LogDebug(string.Format(format, arg0));
public void DebugFormat(string format, params object[] args) => _Logger.LogDebug(string.Format(format, args));
public void Error(object message) => _Logger.LogError(message.ToString());
public void Error(string message, Exception exception) => _Logger.LogError(exception, message.ToString());
public void ErrorFormat(IFormatProvider provider, string format, params object[] args) => _Logger.LogError(string.Format(provider, format, args));
public void ErrorFormat(string format, object arg0, object arg1, object arg2) => _Logger.LogError(string.Format(format, arg0, arg1, arg2));
public void ErrorFormat(string format, object arg0, object arg1) => _Logger.LogError(string.Format(format, arg0, arg1));
public void ErrorFormat(string format, object arg0) => _Logger.LogError(string.Format(format, arg0));
public void ErrorFormat(string format, params object[] args) => _Logger.LogError(string.Format(format, args));
public void Fatal(object message) => _Logger.LogCritical(message.ToString());
public void Fatal(string message, Exception exception) => _Logger.LogCritical(exception, message.ToString());
public void FatalFormat(IFormatProvider provider, string format, params object[] args) => _Logger.LogCritical(string.Format(provider, format, args));
public void FatalFormat(string format, object arg0, object arg1, object arg2) => _Logger.LogCritical(string.Format(format, arg0, arg1, arg2));
public void FatalFormat(string format, object arg0, object arg1) => _Logger.LogCritical(string.Format(format, arg0, arg1));
public void FatalFormat(string format, object arg0) => _Logger.LogCritical(string.Format(format, arg0));
public void FatalFormat(string format, params object[] args) => _Logger.LogCritical(string.Format(format, args));
public void Info(object message) => _Logger.LogInformation(message.ToString());
public void Info(string message, Exception exception) => _Logger.LogInformation(exception, message.ToString());
public void InfoFormat(IFormatProvider provider, string format, params object[] args) => _Logger.LogInformation(string.Format(provider, format, args));
public void InfoFormat(string format, object arg0, object arg1, object arg2) => _Logger.LogInformation(string.Format(format, arg0, arg1, arg2));
public void InfoFormat(string format, object arg0, object arg1) => _Logger.LogInformation(string.Format(format, arg0, arg1));
public void InfoFormat(string format, object arg0) => _Logger.LogInformation(string.Format(format, arg0));
public void InfoFormat(string format, params object[] args) => _Logger.LogInformation(string.Format(format, args));
public void Warn(object message) => _Logger.LogWarning(message.ToString());
public void Warn(string message, Exception exception) => _Logger.LogWarning(exception, message.ToString());
public void WarnFormat(IFormatProvider provider, string format, params object[] args) => _Logger.LogWarning(string.Format(provider, format, args));
public void WarnFormat(string format, object arg0, object arg1, object arg2) => _Logger.LogWarning(string.Format(format, arg0, arg1, arg2));
public void WarnFormat(string format, object arg0, object arg1) => _Logger.LogWarning(string.Format(format, arg0, arg1));
public void WarnFormat(string format, object arg0) => _Logger.LogWarning(string.Format(format, arg0));
public void WarnFormat(string format, params object[] args) => _Logger.LogWarning(string.Format(format, args));
public static string GetWorkingDirectory(string executingAssemblyName, string subDirectoryName)
{
string result = string.Empty;
string traceFile;
List<string> directories = new();
Environment.SpecialFolder[] specialFolders = new Environment.SpecialFolder[]
{
Environment.SpecialFolder.LocalApplicationData,
Environment.SpecialFolder.ApplicationData,
Environment.SpecialFolder.History,
Environment.SpecialFolder.CommonApplicationData,
Environment.SpecialFolder.InternetCache
};
foreach (Environment.SpecialFolder specialFolder in specialFolders)
directories.Add(Path.Combine(Environment.GetFolderPath(specialFolder), subDirectoryName, executingAssemblyName));
foreach (string directory in directories)
{
for (int i = 1; i < 3; i++)
{
if (i == 1)
result = directory;
else
result = string.Concat("D", directory[1..]);
try
{
if (!Directory.Exists(result))
_ = Directory.CreateDirectory(result);
traceFile = string.Concat(result, @"\", DateTime.Now.Ticks, ".txt");
File.WriteAllText(traceFile, traceFile);
File.Delete(traceFile);
break;
}
catch (Exception) { result = string.Empty; }
}
if (!string.IsNullOrEmpty(result))
break;
}
if (string.IsNullOrEmpty(result))
throw new Exception("Unable to set working directory!");
return result;
}
}