Table log Entry was added

This commit is contained in:
Evgeny Redikultsev
2024-01-27 13:39:48 +05:00
parent 236c7928a0
commit a9ffd8b903
39 changed files with 675 additions and 64 deletions

View File

@@ -19,7 +19,7 @@ namespace StructureHelper.Models.Calculators
public IResult Result => result;
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public IShiftTraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public void Run()
{

View File

@@ -27,6 +27,9 @@
<Compile Update="Windows\CalculationWindows\ProgressViews\ShowProgressView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\CalculationWindows\ProgressViews\TraceDocumentView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Windows\Errors\ErrorMessage.xaml.cs">
<SubType>Code</SubType>
</Compile>
@@ -89,6 +92,9 @@
<Page Update="Windows\CalculationWindows\ProgressViews\ShowProgressView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\CalculationWindows\ProgressViews\TraceDocumentView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Windows\Errors\ErrorMessage.xaml">
<SubType>Designer</SubType>
</Page>

View File

@@ -36,7 +36,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
public int StepCount => ValidTupleList.Count();
public ITraceLogger? TraceLogger { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public CrackDiagramLogic(IEnumerable<IForcesTupleResult> tupleList, IEnumerable<INdmPrimitive> ndmPrimitives)
{

View File

@@ -41,7 +41,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
public Action<int> SetProgress { get; set; }
public bool Result { get; set; }
public ITraceLogger? TraceLogger { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public InteractionDiagramLogic(LimitCurveInputData inputData)
{

View File

@@ -28,7 +28,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
public Action<int> SetProgress { get; set; }
public bool Result { get; set; }
public ITraceLogger? TraceLogger { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public void WorkerDoWork(object sender, DoWorkEventArgs e)
{

View File

@@ -7,7 +7,7 @@
xmlns:fc="clr-namespace:StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews"
d:DataContext ="{d:DesignInstance local:LimitCurveCalculatorViewModel}"
mc:Ignorable="d"
Title="Limit Curve Calculator" Height="390" Width="400" MinHeight="300" MinWidth="400" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
Title="Interaction Diagram Calculator" Height="390" Width="400" MinHeight="300" MinWidth="400" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>

View File

@@ -0,0 +1,205 @@
using StructureHelper.Infrastructure;
using StructureHelper.Windows.AddMaterialWindow;
using StructureHelper.Windows.ViewModels.Errors;
using StructureHelper.Windows.ViewModels.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Loggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace StructureHelper.Windows.CalculationWindows.ProgressViews
{
public class TraceDocumentVM : ViewModelBase
{
IEnumerable<ITraceLoggerEntry> loggerEntries;
IEnumerable<ITraceLoggerEntry> selectedLoggerEntries;
FlowDocument document;
private ICommand rebuildCommand;
private ICommand printDocumentCommand;
private int maxPriority;
private int tabGap;
public FlowDocumentReader DocumentReader { get; set; }
public int MaxPriority
{
get => maxPriority; set
{
var oldValue = maxPriority;
try
{
maxPriority = Math.Max(value, 0);
OnPropertyChanged(nameof(MaxPriority));
}
catch (Exception)
{
maxPriority = oldValue;
}
}
}
public int TabGap
{
get => tabGap; set
{
var oldValue = tabGap;
try
{
tabGap = Math.Max(value, 0);
OnPropertyChanged(nameof(TabGap));
}
catch (Exception)
{
tabGap = oldValue;
}
}
}
public TraceDocumentVM(IEnumerable<ITraceLoggerEntry> loggerEntries)
{
this.loggerEntries = loggerEntries;
maxPriority = 350;
tabGap = 50;
}
public ICommand RebuildCommand =>
rebuildCommand ??= new RelayCommand(o =>
{
Show();
});
public ICommand PrintDocumentCommand =>
printDocumentCommand ??= new RelayCommand(o =>
{
SafetyProcessor.RunSafeProcess(DocumentReader.Print, "Error of printing document");
});
public void Show()
{
Prepare();
ShowPrepared();
}
public void Prepare()
{
document = new();
selectedLoggerEntries = loggerEntries.Where(x => x.Priority <= MaxPriority);
foreach (var item in selectedLoggerEntries)
{
ProcessLoggerEntries(item);
}
}
private void ProcessLoggerEntries(ITraceLoggerEntry item)
{
if (item is StringLoggerEntry stringEntry)
{
ProcessStringEntry(stringEntry);
}
else if (item is TableLoggerEntry tableEntry)
{
ProcessTableEntry(tableEntry);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(item));
}
}
private void ProcessTableEntry(TableLoggerEntry tableEntry)
{
var rows = tableEntry.Table.GetAllRows();
int rowCount = rows.Count();
int columnCount = tableEntry.Table.RowSize;
var table = new Table();
for (int x = 0; x < columnCount; x++)
{
var tableColumn = new TableColumn();
tableColumn.Width = new GridLength(150);
table.Columns.Add(tableColumn);
}
foreach (var row in rows)
{
var newRow = new TableRow();
foreach (var cell in row.Elements)
{
TableCell tableCell;
if (cell is null)
{
tableCell = new TableCell(new Paragraph(new Run(string.Empty)));
}
else
{
if (cell is StringLoggerEntry stringEntry)
{
tableCell = new TableCell(GetParagraphByStringEntry(stringEntry));
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(cell));
}
}
newRow.Cells.Add(tableCell);
}
table.RowGroups.Add(new TableRowGroup());
table.RowGroups[0].Rows.Add(newRow);
}
document.Blocks.Add(table);
}
private void ProcessStringEntry(StringLoggerEntry stringEntry)
{
var paragraph = GetParagraphByStringEntry(stringEntry);
document.Blocks.Add(paragraph);
}
private Paragraph GetParagraphByStringEntry(StringLoggerEntry stringEntry)
{
var paragraph = new Paragraph(new Run(stringEntry.Message));
paragraph.Margin = new Thickness(stringEntry.Priority / tabGap);
if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Fatal))
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Red;
paragraph.Foreground = Brushes.Black;
paragraph.FontStyle = FontStyles.Italic;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Error))
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Pink;
paragraph.Foreground = Brushes.Black;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Warning))
{
paragraph.FontSize = 14;
paragraph.Background = Brushes.Yellow;
paragraph.Foreground = Brushes.Black;
}
else if (stringEntry.Priority <= LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Debug))
{
paragraph.FontSize = 12;
paragraph.Foreground = Brushes.Black;
}
else
{
paragraph.FontSize = 8;
paragraph.Foreground = Brushes.Gray;
}
return paragraph;
}
public void ShowPrepared()
{
DocumentReader.Document = document;
}
}
}

View File

@@ -0,0 +1,27 @@
<Window x:Class="StructureHelper.Windows.CalculationWindows.ProgressViews.TraceDocumentView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StructureHelper.Windows.CalculationWindows.ProgressViews"
d:DataContext="{d:DesignInstance local:TraceDocumentVM}"
mc:Ignorable="d"
Title="Trace Document Viewer" Height="450" Width="800" MinHeight="400" MinWidth="600" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="90"/>
</Grid.ColumnDefinitions>
<FlowDocumentReader Name="DocumentReader" ViewingMode="Scroll"/>
<StackPanel Grid.Column="1">
<GroupBox Header="Tab gap">
<TextBox Text="{Binding TabGap, ValidatesOnExceptions=True}" />
</GroupBox>
<GroupBox Header="Max priority">
<TextBox Text="{Binding MaxPriority, ValidatesOnExceptions=True}" />
</GroupBox>
<Button Margin="3" Content="Rebuild" ToolTip="Rebuild document" Command="{Binding RebuildCommand}"/>
<Button Margin="3" Content="Print" ToolTip="Print document" Command="{Binding PrintDocumentCommand}"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,34 @@
using StructureHelperCommon.Models.Loggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace StructureHelper.Windows.CalculationWindows.ProgressViews
{
/// <summary>
/// Логика взаимодействия для TraceDocumentView.xaml
/// </summary>
public partial class TraceDocumentView : Window
{
TraceDocumentVM viewModel;
public TraceDocumentView(TraceDocumentVM viewModel)
{
InitializeComponent();
this.viewModel = viewModel;
this.DataContext = this.viewModel;
this.viewModel.DocumentReader = this.DocumentReader;
this.viewModel.Show();
}
public TraceDocumentView(IEnumerable<ITraceLoggerEntry> loggerEntries) : this(new TraceDocumentVM(loggerEntries)) { }
}
}

View File

@@ -2,6 +2,7 @@
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews.ForceResultLogic;
using StructureHelper.Windows.CalculationWindows.ProgressViews;
using StructureHelper.Windows.ViewModels.Calculations.Calculators;
using StructureHelper.Windows.ViewModels.Errors;
using StructureHelperCommon.Infrastructures.Exceptions;
@@ -35,7 +36,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
NewItem = new ForceCalculator()
{
Name = "New force calculator",
TraceLogger = new TraceLogger(),
TraceLogger = new ShiftTraceLogger(),
};
}
else if (parameterType == CalculatorTypes.LimitCurveCalculator)
@@ -45,7 +46,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
Name = "New interaction diagram calculator",
InputData = inputData,
TraceLogger = new TraceLogger(),
TraceLogger = new ShiftTraceLogger(),
};
}
else
@@ -132,11 +133,16 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
private void RunCalculator()
{
if (SelectedItem is LimitCurvesCalculator)
if (SelectedItem is LimitCurvesCalculator calculator)
{
var calculator = SelectedItem as LimitCurvesCalculator;
if (calculator.TraceLogger is not null) { calculator.TraceLogger.TraceLoggerEntries.Clear(); }
var inputData = calculator.InputData;
ShowInteractionDiagramByInputData(calculator);
if (calculator.TraceLogger is not null)
{
var wnd = new TraceDocumentView(calculator.TraceLogger.TraceLoggerEntries);
wnd.ShowDialog();
}
}
else
{