refactor: Relocate BinFileSaver to CutList.Core with report generation
Move BinFileSaver from CutList/Services to CutList.Core namespace for reuse by MCP server. Add GenerateReport() method that returns formatted text instead of only writing to file. Refactor to use TextWriter base class for flexibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
using CutList.Core;
|
|
||||||
using CutList.Core.Formatting;
|
using CutList.Core.Formatting;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace CutList.Services
|
namespace CutList.Core
|
||||||
{
|
{
|
||||||
public class BinFileSaver
|
public class BinFileSaver
|
||||||
{
|
{
|
||||||
@@ -22,7 +21,24 @@ namespace CutList.Services
|
|||||||
using (var writer = new StreamWriter(file))
|
using (var writer = new StreamWriter(file))
|
||||||
{
|
{
|
||||||
writer.AutoFlush = true;
|
writer.AutoFlush = true;
|
||||||
|
WriteToWriter(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OpenFileAfterSave)
|
||||||
|
{
|
||||||
|
OpenFile(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GenerateReport()
|
||||||
|
{
|
||||||
|
using var writer = new StringWriter();
|
||||||
|
WriteToWriter(writer);
|
||||||
|
return writer.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteToWriter(TextWriter writer)
|
||||||
|
{
|
||||||
PaddingWidthOfItemLength = _bins
|
PaddingWidthOfItemLength = _bins
|
||||||
.SelectMany(b => b.Items)
|
.SelectMany(b => b.Items)
|
||||||
.Select(i => FormatHelper.ConvertToMixedFraction(i.Length).Length)
|
.Select(i => FormatHelper.ConvertToMixedFraction(i.Length).Length)
|
||||||
@@ -40,12 +56,6 @@ namespace CutList.Services
|
|||||||
WriteFinalSummary(writer);
|
WriteFinalSummary(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OpenFileAfterSave)
|
|
||||||
{
|
|
||||||
OpenFile(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OpenFile(string file)
|
private void OpenFile(string file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -58,7 +68,7 @@ namespace CutList.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteHeader(StreamWriter writer)
|
private void WriteHeader(TextWriter writer)
|
||||||
{
|
{
|
||||||
var totalBars = _bins.Count();
|
var totalBars = _bins.Count();
|
||||||
var totalItems = _bins.Sum(b => b.Items.Count);
|
var totalItems = _bins.Sum(b => b.Items.Count);
|
||||||
@@ -70,7 +80,7 @@ namespace CutList.Services
|
|||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteBinSummary(StreamWriter writer, Bin bin, int id)
|
private void WriteBinSummary(TextWriter writer, Bin bin, int id)
|
||||||
{
|
{
|
||||||
var stockLength = FormatHelper.ConvertToMixedFraction(bin.Length);
|
var stockLength = FormatHelper.ConvertToMixedFraction(bin.Length);
|
||||||
var dropLength = FormatHelper.ConvertToMixedFraction(bin.RemainingLength);
|
var dropLength = FormatHelper.ConvertToMixedFraction(bin.RemainingLength);
|
||||||
@@ -87,7 +97,7 @@ namespace CutList.Services
|
|||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteBinItems(StreamWriter writer, Bin bin)
|
private void WriteBinItems(TextWriter writer, Bin bin)
|
||||||
{
|
{
|
||||||
var groups = bin.Items
|
var groups = bin.Items
|
||||||
.GroupBy(i => new { i.Name, i.Length })
|
.GroupBy(i => new { i.Name, i.Length })
|
||||||
@@ -109,7 +119,7 @@ namespace CutList.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteFinalSummary(StreamWriter writer)
|
private void WriteFinalSummary(TextWriter writer)
|
||||||
{
|
{
|
||||||
var totalBars = _bins.Count();
|
var totalBars = _bins.Count();
|
||||||
var totalItems = _bins.Sum(b => b.Items.Count);
|
var totalItems = _bins.Sum(b => b.Items.Count);
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using CutList.Core;
|
using CutList.Core;
|
||||||
using CutList.Services;
|
|
||||||
|
|
||||||
namespace CutList.Forms
|
namespace CutList.Forms
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user