Table log Entry was added
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Models.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public static class TraceLoggerTableByPointsFactory
|
||||
{
|
||||
public static TableLoggerEntry GetTableByPoint2D(IPoint2D point2D)
|
||||
{
|
||||
var table = new TableLoggerEntry(2);
|
||||
table.Table.AddRow(GetHeaderRow());
|
||||
table.Table.AddRow(GetPointRow(point2D));
|
||||
return table;
|
||||
}
|
||||
public static TableLoggerEntry GetTableByPoint2D(IEnumerable<IPoint2D> points)
|
||||
{
|
||||
var table = new TableLoggerEntry(2);
|
||||
table.Table.AddRow(GetHeaderRow());
|
||||
foreach (var item in points)
|
||||
{
|
||||
table.Table.AddRow(GetPointRow(item));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
private static ShTableRow<ITraceLoggerEntry> GetHeaderRow()
|
||||
{
|
||||
var headerRow = new ShTableRow<ITraceLoggerEntry>(2);
|
||||
headerRow.Elements[0] = new StringLoggerEntry()
|
||||
{
|
||||
Message = "X",
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
headerRow.Elements[1] = new StringLoggerEntry()
|
||||
{
|
||||
Message = "Y",
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
return headerRow;
|
||||
}
|
||||
private static ShTableRow<ITraceLoggerEntry> GetPointRow(IPoint2D point2D)
|
||||
{
|
||||
var pointRow = new ShTableRow<ITraceLoggerEntry>(2);
|
||||
pointRow.Elements[0] = new StringLoggerEntry()
|
||||
{
|
||||
Message = Convert.ToString(point2D.X),
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
pointRow.Elements[1] = new StringLoggerEntry()
|
||||
{
|
||||
Message = Convert.ToString(point2D.Y),
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
return pointRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
StructureHelperCommon/Models/Loggers/IShiftTraceLogger.cs
Normal file
16
StructureHelperCommon/Models/Loggers/IShiftTraceLogger.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface IShiftTraceLogger : ITraceLogger
|
||||
{
|
||||
ITraceLogger Logger { get; set; }
|
||||
int ShiftPriority { get; set; }
|
||||
void AddEntry(ITraceLoggerEntry loggerEntry);
|
||||
IShiftTraceLogger GetSimilarTraceLogger(int shftPriority = 0);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ namespace StructureHelperCommon.Models.Loggers
|
||||
public interface ITraceLogger
|
||||
{
|
||||
List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info);
|
||||
void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info, int shiftPriority = 0);
|
||||
void AddMessage(string message, int priority);
|
||||
}
|
||||
}
|
||||
|
||||
33
StructureHelperCommon/Models/Loggers/LoggerService.cs
Normal file
33
StructureHelperCommon/Models/Loggers/LoggerService.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public static class LoggerService
|
||||
{
|
||||
const int fatal = 0;
|
||||
const int error = 100;
|
||||
const int warning = 200;
|
||||
const int info = 300;
|
||||
const int service = 400;
|
||||
const int debug = 500;
|
||||
public static int GetPriorityByStatus(TraceLoggerStatuses status)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { return fatal; }
|
||||
else if (status == TraceLoggerStatuses.Error) { return error; }
|
||||
else if (status == TraceLoggerStatuses.Warning) { return warning; }
|
||||
else if (status == TraceLoggerStatuses.Info) { return info; }
|
||||
else if (status == TraceLoggerStatuses.Service) { return service; }
|
||||
else if (status == TraceLoggerStatuses.Debug) { return debug; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs
Normal file
55
StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class ShiftTraceLogger : IShiftTraceLogger
|
||||
{
|
||||
public ITraceLogger Logger { get; set; }
|
||||
public int ShiftPriority { get; set; }
|
||||
|
||||
public List<ITraceLoggerEntry> TraceLoggerEntries => Logger.TraceLoggerEntries;
|
||||
public ShiftTraceLogger(ITraceLogger logger)
|
||||
{
|
||||
Logger = logger;
|
||||
}
|
||||
public ShiftTraceLogger() : this(new TraceLogger()) { }
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info, int shiftPrioriry = 0)
|
||||
{
|
||||
// if status in (fatal, error, warning) they must be kept as they are
|
||||
if (status <= TraceLoggerStatuses.Warning)
|
||||
{
|
||||
Logger.AddMessage(message, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
var priority = LoggerService.GetPriorityByStatus(status) + shiftPrioriry;
|
||||
this.AddMessage(message, priority);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMessage(string message, int priority)
|
||||
{
|
||||
priority += ShiftPriority;
|
||||
Logger.AddMessage(message, priority);
|
||||
}
|
||||
|
||||
public IShiftTraceLogger GetSimilarTraceLogger(int shiftPriority = 0)
|
||||
{
|
||||
var newLogger = new ShiftTraceLogger(Logger)
|
||||
{
|
||||
ShiftPriority = shiftPriority
|
||||
};
|
||||
return newLogger;
|
||||
}
|
||||
|
||||
public void AddEntry(ITraceLoggerEntry loggerEntry)
|
||||
{
|
||||
loggerEntry.Priority += ShiftPriority;
|
||||
Logger.TraceLoggerEntries.Add(loggerEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
StructureHelperCommon/Models/Loggers/TableLoggerEntry.cs
Normal file
27
StructureHelperCommon/Models/Loggers/TableLoggerEntry.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using StructureHelperCommon.Models.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class TableLoggerEntry : ITraceLoggerEntry
|
||||
{
|
||||
private ListTable<ITraceLoggerEntry> table;
|
||||
public ListTable<ITraceLoggerEntry> Table {get => table;}
|
||||
public DateTime TimeStamp { get; }
|
||||
|
||||
public int Priority { get; set; }
|
||||
public TableLoggerEntry(int rowSize)
|
||||
{
|
||||
if (rowSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
|
||||
}
|
||||
table = new(rowSize);
|
||||
TimeStamp = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class TraceLogger : ITraceLogger
|
||||
{
|
||||
const int fatal = 0;
|
||||
const int error = 1000;
|
||||
const int warning = 200;
|
||||
const int info = 300;
|
||||
const int service = 400;
|
||||
const int debug = 500;
|
||||
|
||||
{
|
||||
public List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
|
||||
public TraceLogger()
|
||||
@@ -23,12 +17,15 @@ namespace StructureHelperCommon.Models.Loggers
|
||||
TraceLoggerEntries = new();
|
||||
}
|
||||
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info)
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info, int shiftPrioriry = 0)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { message = $"Fatal error! {message}"; }
|
||||
if (status == TraceLoggerStatuses.Error) { message = $"Error! {message}"; }
|
||||
if (status == TraceLoggerStatuses.Warning) { message = $"Warning! {message}"; }
|
||||
TraceLoggerEntries.Add(new StringLoggerEntry()
|
||||
{
|
||||
Message = message,
|
||||
Priority = GetPriorityByStatus(status)
|
||||
Priority = LoggerService.GetPriorityByStatus(status)
|
||||
});
|
||||
}
|
||||
public void AddMessage(string message, int priority)
|
||||
@@ -39,19 +36,5 @@ namespace StructureHelperCommon.Models.Loggers
|
||||
Priority = priority
|
||||
});
|
||||
}
|
||||
|
||||
public static int GetPriorityByStatus(TraceLoggerStatuses status)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { return fatal; }
|
||||
else if (status == TraceLoggerStatuses.Error) { return error; }
|
||||
else if (status == TraceLoggerStatuses.Warning) { return warning; }
|
||||
else if (status == TraceLoggerStatuses.Info) { return info; }
|
||||
else if (status == TraceLoggerStatuses.Service) { return service; }
|
||||
else if (status == TraceLoggerStatuses.Debug) { return debug; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user