Compare commits

...

4 Commits

Author SHA1 Message Date
AJ
b92e3a6af2 Refactor Reader classes: Extract common parsing logic to StringParsingHelper
Created StringParsingHelper utility class (107 lines) to consolidate repetitive parsing:
- ParseInt32, ParseDouble, ParsePercent methods with error handling
- TryParseKeyValue methods for extracting values from key=value strings
- ExtractAfterPrefix for removing fixed prefixes

Benefits:
- Eliminated duplicate parsing code across ReportReader and PlateReader
- Consistent error handling and debug logging
- Cleaner, more maintainable parsing methods
- Reduced PlateReader from 338 lines to 277 lines (18% reduction)
- Reduced ReportReader from 378 lines to 339 lines (10% reduction)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-08 23:35:53 -04:00
AJ
7c39e89347 Refactor PepDB.cs: Consolidate repetitive Entity Framework configuration
Reduced file from 481 lines to 108 lines (77.5% reduction) by:
- Created ConfigureStringProperties helper method to eliminate repetitive IsUnicode(false) calls
- Organized entity configurations into dedicated methods per entity type
- Maintained all original functionality while improving maintainability

Benefits:
- Easier to add new properties or entities
- Better code organization and readability
- Follows DRY principle
- Type-safe using lambda expressions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-08 23:29:31 -04:00
AJ
8fb1f35396 Changed target framework to version 4.8 2023-03-02 19:57:55 -05:00
AJ
ca978a1dcc Made objects serializable so they work with winforms UI 2023-03-02 19:56:19 -05:00
17 changed files with 258 additions and 609 deletions

View File

@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PepLib.Dxf</RootNamespace> <RootNamespace>PepLib.Dxf</RootNamespace>
<AssemblyName>PepLib.Dxf</AssemblyName> <AssemblyName>PepLib.Dxf</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup> </startup>
</configuration> </configuration>

View File

@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PepLib.UI</RootNamespace> <RootNamespace>PepLib.UI</RootNamespace>
<AssemblyName>PepLib.UI</AssemblyName> <AssemblyName>PepLib.UI</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile /> <TargetFrameworkProfile />

View File

@@ -19,7 +19,7 @@ namespace PepLib.UI.Properties {
// class via a tool like ResGen or Visual Studio. // class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen // To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project. // with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {

View File

@@ -12,7 +12,7 @@ namespace PepLib.UI.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 17
VisualStudioVersion = 15.0.28307.329 VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepLib", "PepLib\PepLib.csproj", "{22360453-B878-49FA-A5DC-0D9C577DE902}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PepLib", "PepLib\PepLib.csproj", "{22360453-B878-49FA-A5DC-0D9C577DE902}"
EndProject EndProject

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity; using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
namespace PepLib.Data namespace PepLib.Data
{ {
@@ -21,461 +23,86 @@ namespace PepLib.Data
protected override void OnModelCreating(DbModelBuilder modelBuilder) protected override void OnModelCreating(DbModelBuilder modelBuilder)
{ {
modelBuilder.Entity<Drawing>() ConfigureDrawingEntity(modelBuilder);
.Property(e => e.Name) ConfigureNestDetailEntity(modelBuilder);
.IsUnicode(false); ConfigureNestDrawingEntity(modelBuilder);
ConfigureNestHeaderEntity(modelBuilder);
modelBuilder.Entity<Drawing>() ConfigurePlateDetailEntity(modelBuilder);
.Property(e => e.CustID) ConfigurePlateHeaderEntity(modelBuilder);
.IsUnicode(false); }
modelBuilder.Entity<Drawing>() private void ConfigureDrawingEntity(DbModelBuilder modelBuilder)
.Property(e => e.Revision) {
.IsUnicode(false); ConfigureStringProperties(modelBuilder.Entity<Drawing>(),
e => e.Name, e => e.CustID, e => e.Revision, e => e.Path, e => e.File,
modelBuilder.Entity<Drawing>() e => e.InUseBy, e => e.Status, e => e.StatusModifiedBy, e => e.Description,
.Property(e => e.Path) e => e.Customer, e => e.Comment, e => e.Notes, e => e.Material, e => e.MatGrade,
.IsUnicode(false); e => e.Programmer, e => e.CreatedBy, e => e.Type, e => e.Errors, e => e.Hardness,
e => e.Specification, e => e.UserDefined1, e => e.UserDefined2, e => e.UserDefined3,
modelBuilder.Entity<Drawing>() e => e.UserDefined4, e => e.UserDefined5, e => e.UserDefined6, e => e.Application,
.Property(e => e.File) e => e.SourceFile, e => e.CadScaled, e => e.ModifiedBy);
.IsUnicode(false); }
modelBuilder.Entity<Drawing>() private void ConfigureNestDetailEntity(DbModelBuilder modelBuilder)
.Property(e => e.InUseBy) {
.IsUnicode(false); ConfigureStringProperties(modelBuilder.Entity<NestDetail>(),
e => e.NestName, e => e.Drawing, e => e.CustID, e => e.DwgRevision,
modelBuilder.Entity<Drawing>() e => e.CustomerNo, e => e.CustomerName, e => e.ModifiedBy);
.Property(e => e.Status) }
.IsUnicode(false);
private void ConfigureNestDrawingEntity(DbModelBuilder modelBuilder)
modelBuilder.Entity<Drawing>() {
.Property(e => e.StatusModifiedBy) var entity = modelBuilder.Entity<NestDrawing>();
.IsUnicode(false);
ConfigureStringProperties(entity,
modelBuilder.Entity<Drawing>() e => e.NestName, e => e.Drawing, e => e.CustID, e => e.DwgRevision,
.Property(e => e.Description) e => e.DwgDesc, e => e.ImageFile, e => e.UserDefined1, e => e.UserDefined2,
.IsUnicode(false); e => e.UserDefined3, e => e.UserDefined4, e => e.UserDefined5, e => e.UserDefined6,
e => e.Description, e => e.ModifiedBy);
modelBuilder.Entity<Drawing>()
.Property(e => e.Customer) entity.Property(e => e.SizeX).HasPrecision(15, 4);
.IsUnicode(false); entity.Property(e => e.SizeY).HasPrecision(15, 4);
}
modelBuilder.Entity<Drawing>()
.Property(e => e.Comment) private void ConfigureNestHeaderEntity(DbModelBuilder modelBuilder)
.IsUnicode(false); {
ConfigureStringProperties(modelBuilder.Entity<NestHeader>(),
modelBuilder.Entity<Drawing>() e => e.NestName, e => e.CustID, e => e.CustomerName, e => e.Material,
.Property(e => e.Notes) e => e.MatDescription, e => e.MatGrade, e => e.Programmer, e => e.Post,
.IsUnicode(false); e => e.Comments, e => e.Remarks, e => e.TypeOfGas, e => e.UserDefined1,
e => e.UserDefined2, e => e.UserDefined3, e => e.UserDefined4, e => e.UserDefined5,
modelBuilder.Entity<Drawing>() e => e.UserDefined6, e => e.ModifiedBy, e => e.Path, e => e.NestGenMethod,
.Property(e => e.Material) e => e.FeedRateScenarios, e => e.OutputJobCosting, e => e.ReportNestedDrawingsOnly,
.IsUnicode(false); e => e.DisplayTimingInfo, e => e.OutputPostTechTable, e => e.WeightTypeForDisplay,
e => e.WeightTypeForCosting, e => e.Errors, e => e.DefPlateSize, e => e.DefKerfDirection,
modelBuilder.Entity<Drawing>() e => e.InUse, e => e.ApplicationName);
.Property(e => e.MatGrade) }
.IsUnicode(false);
private void ConfigurePlateDetailEntity(DbModelBuilder modelBuilder)
modelBuilder.Entity<Drawing>() {
.Property(e => e.Programmer) ConfigureStringProperties(modelBuilder.Entity<PlateDetail>(),
.IsUnicode(false); e => e.NestName, e => e.Drawing, e => e.DwgRevision, e => e.LoopList,
e => e.DwgDesc, e => e.WorkOrder, e => e.Note, e => e.Sales, e => e.Remarks,
modelBuilder.Entity<Drawing>() e => e.RequiredGrade, e => e.JobNo, e => e.Sequence, e => e.Marking,
.Property(e => e.CreatedBy) e => e.ModifiedBy, e => e.LifetimeList, e => e.CustPO, e => e.CustID);
.IsUnicode(false); }
modelBuilder.Entity<Drawing>() private void ConfigurePlateHeaderEntity(DbModelBuilder modelBuilder)
.Property(e => e.Type) {
.IsUnicode(false); ConfigureStringProperties(modelBuilder.Entity<PlateHeader>(),
e => e.NestName, e => e.InvPlateName, e => e.RemnantSize, e => e.PlateSize,
modelBuilder.Entity<Drawing>() e => e.HeatLot, e => e.UpdateStatus, e => e.ImageFile, e => e.Note,
.Property(e => e.Errors) e => e.ProgramName, e => e.ModifiedBy, e => e.Location, e => e.NestedSize);
.IsUnicode(false); }
modelBuilder.Entity<Drawing>() private void ConfigureStringProperties<TEntity>(EntityTypeConfiguration<TEntity> entity,
.Property(e => e.Hardness) params Expression<Func<TEntity, string>>[] properties)
.IsUnicode(false); where TEntity : class
{
modelBuilder.Entity<Drawing>() foreach (var property in properties)
.Property(e => e.Specification) {
.IsUnicode(false); entity.Property(property).IsUnicode(false);
}
modelBuilder.Entity<Drawing>()
.Property(e => e.UserDefined1)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.UserDefined2)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.UserDefined3)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.UserDefined4)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.UserDefined5)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.UserDefined6)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.Application)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.SourceFile)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.CadScaled)
.IsUnicode(false);
modelBuilder.Entity<Drawing>()
.Property(e => e.ModifiedBy)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.NestName)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.Drawing)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.CustID)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.DwgRevision)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.CustomerNo)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.CustomerName)
.IsUnicode(false);
modelBuilder.Entity<NestDetail>()
.Property(e => e.ModifiedBy)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.NestName)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.Drawing)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.CustID)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.DwgRevision)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.DwgDesc)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.ImageFile)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.UserDefined1)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.UserDefined2)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.UserDefined3)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.UserDefined4)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.UserDefined5)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.UserDefined6)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.Description)
.IsUnicode(false);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.SizeX)
.HasPrecision(15, 4);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.SizeY)
.HasPrecision(15, 4);
modelBuilder.Entity<NestDrawing>()
.Property(e => e.ModifiedBy)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.NestName)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.CustID)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.CustomerName)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Material)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.MatDescription)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.MatGrade)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Programmer)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Post)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Comments)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Remarks)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.TypeOfGas)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.UserDefined1)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.UserDefined2)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.UserDefined3)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.UserDefined4)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.UserDefined5)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.UserDefined6)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.ModifiedBy)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Path)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.NestGenMethod)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.FeedRateScenarios)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.OutputJobCosting)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.ReportNestedDrawingsOnly)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.DisplayTimingInfo)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.OutputPostTechTable)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.WeightTypeForDisplay)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.WeightTypeForCosting)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.Errors)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.DefPlateSize)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.DefKerfDirection)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.InUse)
.IsUnicode(false);
modelBuilder.Entity<NestHeader>()
.Property(e => e.ApplicationName)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.NestName)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.Drawing)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.DwgRevision)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.LoopList)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.DwgDesc)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.WorkOrder)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.Note)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.Sales)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.Remarks)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.RequiredGrade)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.JobNo)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.Sequence)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.Marking)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.ModifiedBy)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.LifetimeList)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.CustPO)
.IsUnicode(false);
modelBuilder.Entity<PlateDetail>()
.Property(e => e.CustID)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.NestName)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.InvPlateName)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.RemnantSize)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.PlateSize)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.HeatLot)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.UpdateStatus)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.ImageFile)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.Note)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.ProgramName)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.ModifiedBy)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.Location)
.IsUnicode(false);
modelBuilder.Entity<PlateHeader>()
.Property(e => e.NestedSize)
.IsUnicode(false);
} }
} }
} }

View File

@@ -142,31 +142,19 @@ namespace PepLib.IO
private void ParsePostedFiles(string data) private void ParsePostedFiles(string data)
{ {
if (data.Length < 14) Plate.PostedFiles = StringParsingHelper.ExtractAfterPrefix(data, "POSTED FILES=");
return;
Plate.PostedFiles = data.Remove(0, 14).Trim();
} }
private void ParseHeatLot(string data) private void ParseHeatLot(string data)
{ {
if (data.Length < 9) Plate.HeatLot = StringParsingHelper.ExtractAfterPrefix(data, "HEAT LOT=");
return;
Plate.HeatLot = data.Remove(0, 9).Trim();
} }
private void ParseSpacing(string data) private void ParseSpacing(string data)
{ {
var parts = data.Split('=');
if (parts.Length != 2)
return;
double spacing; double spacing;
double.TryParse(parts[1], out spacing); if (StringParsingHelper.TryParseDoubleFromKeyValue(data, '=', out spacing))
Plate.PartSpacing = spacing;
Plate.PartSpacing = spacing;
} }
private void ParseEdgeSpacing(string data) private void ParseEdgeSpacing(string data)
@@ -176,37 +164,18 @@ namespace PepLib.IO
if (parts.Length != 5) if (parts.Length != 5)
return; return;
var leftSplit = parts[1].Split('='); double value;
if (leftSplit.Length == 2) if (StringParsingHelper.TryParseDoubleFromKeyValue(parts[1], '=', out value))
{ Plate.EdgeSpacing.Left = value;
double x;
double.TryParse(leftSplit[1], out x);
Plate.EdgeSpacing.Left = x;
}
var bottomSplit = parts[2].Split('='); if (StringParsingHelper.TryParseDoubleFromKeyValue(parts[2], '=', out value))
if (bottomSplit.Length == 2) Plate.EdgeSpacing.Bottom = value;
{
double x;
double.TryParse(bottomSplit[1], out x);
Plate.EdgeSpacing.Bottom = x;
}
var rightSplit = parts[3].Split('='); if (StringParsingHelper.TryParseDoubleFromKeyValue(parts[3], '=', out value))
if (rightSplit.Length == 2) Plate.EdgeSpacing.Right = value;
{
double x;
double.TryParse(rightSplit[1], out x);
Plate.EdgeSpacing.Right = x;
}
var topSplit = parts[4].Split('='); if (StringParsingHelper.TryParseDoubleFromKeyValue(parts[4], '=', out value))
if (topSplit.Length == 2) Plate.EdgeSpacing.Top = value;
{
double x;
double.TryParse(topSplit[1], out x);
Plate.EdgeSpacing.Top = x;
}
} }
private void ParsePlateSize(string data) private void ParsePlateSize(string data)
@@ -265,74 +234,44 @@ namespace PepLib.IO
private void ParseMaterial(string data) private void ParseMaterial(string data)
{ {
var parts = data.Split('=');
if (parts.Length != 2)
return;
int material; int material;
int.TryParse(parts[1], out material); if (StringParsingHelper.TryParseInt32FromKeyValue(data, '=', out material))
Plate.Material.Id = material;
Plate.Material.Id = material;
} }
private void ParseGrade(string data) private void ParseGrade(string data)
{ {
var parts = data.Split('='); string value;
if (StringParsingHelper.TryParseKeyValue(data, '=', out value))
if (parts.Length != 2) Plate.Material.Grade = value;
return;
Plate.Material.Grade = parts[1].Trim();
} }
private void ParseDescription(string data) private void ParseDescription(string data)
{ {
var parts = data.Split('='); string value;
if (StringParsingHelper.TryParseKeyValue(data, '=', out value))
if (parts.Length != 2) Plate.Description = value;
return;
Plate.Description = parts[1].Trim();
} }
private void ParseThickness(string data) private void ParseThickness(string data)
{ {
var parts = data.Split('=');
if (parts.Length != 2)
return;
double thickness; double thickness;
double.TryParse(parts[1], out thickness); if (StringParsingHelper.TryParseDoubleFromKeyValue(data, '=', out thickness))
Plate.Thickness = thickness;
Plate.Thickness = thickness;
} }
private void ParseDensity(string data) private void ParseDensity(string data)
{ {
var parts = data.Split('=');
if (parts.Length != 2)
return;
double density; double density;
double.TryParse(parts[1], out density); if (StringParsingHelper.TryParseDoubleFromKeyValue(data, '=', out density))
Plate.Material.Density = density;
Plate.Material.Density = density;
} }
private void ParseTorchCount(string data) private void ParseTorchCount(string data)
{ {
var parts = data.Split('=');
if (parts.Length != 2)
return;
int torchCount; int torchCount;
int.TryParse(parts[1], out torchCount); if (StringParsingHelper.TryParseInt32FromKeyValue(data, '=', out torchCount))
Plate.TorchCount = torchCount;
Plate.TorchCount = torchCount;
} }
} }
} }

View File

@@ -170,7 +170,7 @@ namespace PepLib.IO
break; break;
case "Thickness": case "Thickness":
plt.Thickness = ParseDouble(value); plt.Thickness = StringParsingHelper.ParseDouble(value);
break; break;
case "Plate Size": case "Plate Size":
@@ -178,7 +178,7 @@ namespace PepLib.IO
break; break;
case "Material": case "Material":
plt.MaterialNumber = ParseInt32(value); plt.MaterialNumber = StringParsingHelper.ParseInt32(value);
break; break;
case "Grade": case "Grade":
@@ -194,23 +194,23 @@ namespace PepLib.IO
break; break;
case "Plate Util": case "Plate Util":
plt.PlateUtilization = ParsePercent(value); plt.PlateUtilization = StringParsingHelper.ParsePercent(value);
break; break;
case "Material Util": case "Material Util":
plt.MaterialUtilization = ParsePercent(value); plt.MaterialUtilization = StringParsingHelper.ParsePercent(value);
break; break;
case "Total Area1": case "Total Area1":
plt.Area1 = ParseDouble(value); plt.Area1 = StringParsingHelper.ParseDouble(value);
break; break;
case "Total Area2": case "Total Area2":
plt.Area2 = ParseDouble(value); plt.Area2 = StringParsingHelper.ParseDouble(value);
break; break;
case "Bubble pierces": case "Bubble pierces":
plt.BubblePierceCount = ParseInt32(value); plt.BubblePierceCount = StringParsingHelper.ParseInt32(value);
break; break;
case "Total cutting time": case "Total cutting time":
@@ -218,11 +218,11 @@ namespace PepLib.IO
break; break;
case "Cutting feedrate": case "Cutting feedrate":
Report.CutFeedrate = ParseInt32(value); Report.CutFeedrate = StringParsingHelper.ParseInt32(value);
break; break;
case "Rapid feedrate": case "Rapid feedrate":
Report.RapidFeedrate = ParseInt32(value); Report.RapidFeedrate = StringParsingHelper.ParseInt32(value);
break; break;
default: default:
@@ -248,35 +248,35 @@ namespace PepLib.IO
break; break;
case "Qty Req": case "Qty Req":
dwg.QtyRequired = ParseInt32(value); dwg.QtyRequired = StringParsingHelper.ParseInt32(value);
break; break;
case "Qty Nstd": case "Qty Nstd":
dwg.QtyNested = ParseInt32(value); dwg.QtyNested = StringParsingHelper.ParseInt32(value);
break; break;
case "# of Pierces": case "# of Pierces":
dwg.PierceCount = ParseInt32(value); dwg.PierceCount = StringParsingHelper.ParseInt32(value);
break; break;
case "Intersections": case "Intersections":
dwg.IntersectionCount = ParseInt32(value); dwg.IntersectionCount = StringParsingHelper.ParseInt32(value);
break; break;
case "Area1*": case "Area1*":
dwg.Area1 = ParseDouble(value); dwg.Area1 = StringParsingHelper.ParseDouble(value);
break; break;
case "Area2**": case "Area2**":
dwg.Area2 = ParseDouble(value); dwg.Area2 = StringParsingHelper.ParseDouble(value);
break; break;
case "% of Material": case "% of Material":
dwg.PercentOfMaterial = ParsePercent(value); dwg.PercentOfMaterial = StringParsingHelper.ParsePercent(value);
break; break;
case "% of Time": case "% of Time":
dwg.PercentOfCutTime = ParsePercent(value); dwg.PercentOfCutTime = StringParsingHelper.ParsePercent(value);
dwg.TotalCutTime = dwg.TotalCutTime =
TimeSpan.FromTicks((long)(Report.TotalCutTime.Ticks * dwg.PercentOfCutTime / 100.0)); TimeSpan.FromTicks((long)(Report.TotalCutTime.Ticks * dwg.PercentOfCutTime / 100.0));
break; break;
@@ -327,45 +327,6 @@ namespace PepLib.IO
report.TotalCutTime = new TimeSpan(hrs, min, sec); report.TotalCutTime = new TimeSpan(hrs, min, sec);
} }
private static double ParsePercent(string s, double defaultValue = 0.0)
{
var t = s.TrimEnd('%', ' ');
double f;
if (!double.TryParse(t, out f))
{
Debug.WriteLine("Failed to convert \"" + s + "\" from percent string to double");
return defaultValue;
}
return f;
}
private static double ParseDouble(string s, double defaultValue = 0.0)
{
double f;
if (!double.TryParse(s, out f))
{
Debug.WriteLine("Failed to convert \"" + s + "\" from string to double");
return defaultValue;
}
return f;
}
private static int ParseInt32(string s, int defaultValue = 0)
{
int i;
if (!int.TryParse(s, out i))
{
Debug.WriteLine("Failed to convert \"" + s + "\" from string to int");
return defaultValue;
}
return i;
}
private enum Section private enum Section
{ {

View File

@@ -0,0 +1,107 @@
using System;
using System.Diagnostics;
namespace PepLib.IO
{
internal static class StringParsingHelper
{
public static int ParseInt32(string value, int defaultValue = 0)
{
int result;
if (!int.TryParse(value, out result))
{
Debug.WriteLine($"Failed to convert \"{value}\" from string to int");
return defaultValue;
}
return result;
}
public static double ParseDouble(string value, double defaultValue = 0.0)
{
double result;
if (!double.TryParse(value, out result))
{
Debug.WriteLine($"Failed to convert \"{value}\" from string to double");
return defaultValue;
}
return result;
}
public static double ParsePercent(string value, double defaultValue = 0.0)
{
var trimmed = value.TrimEnd('%', ' ');
double result;
if (!double.TryParse(trimmed, out result))
{
Debug.WriteLine($"Failed to convert \"{value}\" from percent string to double");
return defaultValue;
}
return result;
}
public static bool TrySplitKeyValue(string data, char separator, out string key, out string value)
{
var parts = data.Split(separator);
if (parts.Length == 2)
{
key = parts[0].Trim();
value = parts[1].Trim();
return true;
}
key = null;
value = null;
return false;
}
public static string ExtractAfterPrefix(string data, string prefix)
{
if (data.Length < prefix.Length)
return string.Empty;
return data.Remove(0, prefix.Length).Trim();
}
public static bool TryParseKeyValue(string data, char separator, out string value, Action<string> onError = null)
{
var parts = data.Split(separator);
if (parts.Length == 2)
{
value = parts[1].Trim();
return true;
}
if (onError != null)
onError($"Expected 2 parts when splitting '{data}' by '{separator}', got {parts.Length}");
value = null;
return false;
}
public static bool TryParseInt32FromKeyValue(string data, char separator, out int result, int defaultValue = 0)
{
string value;
if (TryParseKeyValue(data, separator, out value))
{
result = ParseInt32(value, defaultValue);
return true;
}
result = defaultValue;
return false;
}
public static bool TryParseDoubleFromKeyValue(string data, char separator, out double result, double defaultValue = 0.0)
{
string value;
if (TryParseKeyValue(data, separator, out value))
{
result = ParseDouble(value, defaultValue);
return true;
}
result = defaultValue;
return false;
}
}
}

View File

@@ -1,5 +1,8 @@
namespace PepLib using System;
namespace PepLib
{ {
[Serializable]
public class Machine public class Machine
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@@ -1,5 +1,8 @@
namespace PepLib using System;
namespace PepLib
{ {
[Serializable]
public class Material public class Material
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@@ -2,6 +2,7 @@
namespace PepLib namespace PepLib
{ {
[Serializable]
public class Part : IMovable public class Part : IMovable
{ {
private Loop baseLoop; private Loop baseLoop;

View File

@@ -97,6 +97,7 @@
<Compile Include="Size.cs" /> <Compile Include="Size.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="IO\ReportReader.cs" /> <Compile Include="IO\ReportReader.cs" />
<Compile Include="IO\StringParsingHelper.cs" />
<Compile Include="Spacing.cs" /> <Compile Include="Spacing.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Report.cs" /> <Compile Include="Report.cs" />

View File

@@ -4,6 +4,7 @@ using System.Linq;
namespace PepLib namespace PepLib
{ {
[Serializable]
public class Plate : IMovable public class Plate : IMovable
{ {
public Plate() public Plate()

View File

@@ -1,5 +1,8 @@
namespace PepLib using System;
namespace PepLib
{ {
[Serializable]
public class Size public class Size
{ {
public Size(double height, double width) public Size(double height, double width)

View File

@@ -1,6 +1,9 @@
 
using System;
namespace PepLib namespace PepLib
{ {
[Serializable]
public class Spacing public class Spacing
{ {
public Spacing() public Spacing()