Trace logger calls were adde in limit curve calculator
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -19,6 +20,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public FindParameterCalculator()
|
||||
{
|
||||
@@ -58,6 +60,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
int iterationNum = 0;
|
||||
while (step > precision)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Iteration number {iterationNum}", TraceLoggerStatuses.Debug);
|
||||
if (predicate(current) == true)
|
||||
{
|
||||
end = current;
|
||||
@@ -66,8 +69,8 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
start = current;
|
||||
}
|
||||
|
||||
current = (start + end) / 2;
|
||||
TraceLogger?.AddMessage($"Current value {current}", TraceLoggerStatuses.Debug);
|
||||
step = (end - start) / 2;
|
||||
iterationNum++;
|
||||
|
||||
@@ -78,11 +81,12 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
|
||||
if (iterationNum > maxIterationCount)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Recuired precision was not achieved, current step {step}, required precision {precision}", TraceLoggerStatuses.Error);
|
||||
result.Description = "Parameter was not found succefully: \n";
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": violation of iteration count");
|
||||
}
|
||||
}
|
||||
|
||||
TraceLogger?.AddMessage($"Parameter value {current} was obtained");
|
||||
result.Parameter = current;
|
||||
result.Description = "Parameter was found succefully";
|
||||
result.IsValid = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,6 +12,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public interface ICalculator : ICloneable
|
||||
{
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Method for calculating
|
||||
|
||||
13
StructureHelperCommon/Models/Loggers/ILogger.cs
Normal file
13
StructureHelperCommon/Models/Loggers/ILogger.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
void Fatal(string message);
|
||||
}
|
||||
}
|
||||
14
StructureHelperCommon/Models/Loggers/ITraceLogger.cs
Normal file
14
StructureHelperCommon/Models/Loggers/ITraceLogger.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface ITraceLogger
|
||||
{
|
||||
List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info);
|
||||
}
|
||||
}
|
||||
14
StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs
Normal file
14
StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface ITraceLoggerEntry
|
||||
{
|
||||
DateTime TimeStamp { get;}
|
||||
int Priority { get; set; }
|
||||
}
|
||||
}
|
||||
20
StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs
Normal file
20
StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class StringLoggerEntry : ITraceLoggerEntry
|
||||
{
|
||||
public DateTime TimeStamp { get;}
|
||||
public string Message { get; set; }
|
||||
public int Priority { get; set; }
|
||||
|
||||
public StringLoggerEntry()
|
||||
{
|
||||
TimeStamp = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
57
StructureHelperCommon/Models/Loggers/TraceLogger.cs
Normal file
57
StructureHelperCommon/Models/Loggers/TraceLogger.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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()
|
||||
{
|
||||
TraceLoggerEntries = new();
|
||||
}
|
||||
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info)
|
||||
{
|
||||
TraceLoggerEntries.Add(new StringLoggerEntry()
|
||||
{
|
||||
Message = message,
|
||||
Priority = GetPriorityByStatus(status)
|
||||
});
|
||||
}
|
||||
public void AddMessage(string message, int priority)
|
||||
{
|
||||
TraceLoggerEntries.Add(new StringLoggerEntry()
|
||||
{
|
||||
Message = message,
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs
Normal file
18
StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public enum TraceLoggerStatuses
|
||||
{
|
||||
Fatal,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Service,
|
||||
Debug
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,6 +21,7 @@ namespace StructureHelperCommon.Models.Soils
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public AnchorCalculator(SoilAnchor soilAnchor, IAnchorSoilProperties anchorSoilProperties)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user