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

@@ -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)) { }
}
}