Added LogDataParser
This commit is contained in:
@@ -38,7 +38,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Laser\LaserWebPanel.cs" />
|
||||
<Compile Include="Laser\ProductLog.cs" />
|
||||
<Compile Include="PressBrake\Extensions.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="PressBrake\LogDataParser.cs" />
|
||||
<Compile Include="PressBrake\MatType.cs" />
|
||||
<Compile Include="PressBrake\Program.cs" />
|
||||
<Compile Include="PressBrake\ProgramReader.cs" />
|
||||
|
||||
163
CincyLib/Extensions.cs
Normal file
163
CincyLib/Extensions.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CincyLib
|
||||
{
|
||||
internal static class Extensions
|
||||
{
|
||||
private static bool? ToBool(this string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
return null;
|
||||
|
||||
int intValue;
|
||||
|
||||
if (!int.TryParse(s, out intValue))
|
||||
return null;
|
||||
|
||||
return Convert.ToBoolean(intValue);
|
||||
}
|
||||
|
||||
public static bool ToBool(this XAttribute a, bool defaultValue = false)
|
||||
{
|
||||
if (a == null)
|
||||
return defaultValue;
|
||||
|
||||
var b = a.Value.ToBool();
|
||||
|
||||
return b != null ? b.Value : defaultValue;
|
||||
}
|
||||
|
||||
public static bool? ToBoolOrNull(this XAttribute a)
|
||||
{
|
||||
if (a == null)
|
||||
return null;
|
||||
|
||||
return a.Value.ToBool();
|
||||
}
|
||||
|
||||
private static int? ToInt(this string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
return null;
|
||||
|
||||
int intValue;
|
||||
|
||||
if (!int.TryParse(s, out intValue))
|
||||
return null;
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public static int ToInt(this XAttribute a, int defaultValue = 0)
|
||||
{
|
||||
if (a == null)
|
||||
return defaultValue;
|
||||
|
||||
var b = a.Value.ToInt();
|
||||
|
||||
return b != null ? b.Value : defaultValue;
|
||||
}
|
||||
|
||||
public static int? ToIntOrNull(this XAttribute a)
|
||||
{
|
||||
if (a == null)
|
||||
return null;
|
||||
|
||||
return a.Value.ToInt();
|
||||
}
|
||||
|
||||
public static int ToInt(this XElement a, int defaultValue = 0)
|
||||
{
|
||||
if (a == null)
|
||||
return defaultValue;
|
||||
|
||||
var b = a.Value.ToInt();
|
||||
|
||||
return b != null ? b.Value : defaultValue;
|
||||
}
|
||||
|
||||
public static int? ToIntOrNull(this XElement a)
|
||||
{
|
||||
if (a == null)
|
||||
return null;
|
||||
|
||||
return a.Value.ToInt();
|
||||
}
|
||||
|
||||
private static double? ToDouble(this string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
return null;
|
||||
|
||||
double d;
|
||||
|
||||
if (!double.TryParse(s, out d))
|
||||
return null;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public static double ToDouble(this XAttribute a, double defaultValue = 0)
|
||||
{
|
||||
if (a == null)
|
||||
return defaultValue;
|
||||
|
||||
var b = a.Value.ToDouble();
|
||||
|
||||
return b != null ? b.Value : defaultValue;
|
||||
}
|
||||
|
||||
public static double? ToDoubleOrNull(this XAttribute a)
|
||||
{
|
||||
if (a == null)
|
||||
return null;
|
||||
|
||||
return a.Value.ToDouble();
|
||||
}
|
||||
|
||||
public static double ToDouble(this XElement a, double defaultValue = 0)
|
||||
{
|
||||
if (a == null)
|
||||
return defaultValue;
|
||||
|
||||
var b = a.Value.ToDouble();
|
||||
|
||||
return b != null ? b.Value : defaultValue;
|
||||
}
|
||||
|
||||
public static double? ToDoubleOrNull(this XElement a)
|
||||
{
|
||||
if (a == null)
|
||||
return null;
|
||||
|
||||
return a.Value.ToDouble();
|
||||
}
|
||||
|
||||
public static DateTime? ToDateTime(this XAttribute a)
|
||||
{
|
||||
if (a == null || string.IsNullOrWhiteSpace(a.Value))
|
||||
return null;
|
||||
|
||||
DateTime d;
|
||||
|
||||
if (!DateTime.TryParse(a.Value, out d))
|
||||
return null;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public static TimeSpan? ToTimeSpan(this XElement e)
|
||||
{
|
||||
if (e == null || string.IsNullOrWhiteSpace(e.Value))
|
||||
return null;
|
||||
|
||||
TimeSpan d;
|
||||
|
||||
if (!TimeSpan.TryParse(e.Value, out d))
|
||||
return null;
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CincyLib.PressBrake
|
||||
{
|
||||
static class Extensions
|
||||
{
|
||||
public static bool ToBool(this XAttribute a, bool defaultValue = false)
|
||||
{
|
||||
if (a == null || string.IsNullOrWhiteSpace(a.Value))
|
||||
return defaultValue;
|
||||
|
||||
int intValue;
|
||||
|
||||
if (!int.TryParse(a.Value, out intValue))
|
||||
return defaultValue;
|
||||
|
||||
return Convert.ToBoolean(intValue);
|
||||
}
|
||||
|
||||
public static int ToInt(this XAttribute a, int defaultValue = 0)
|
||||
{
|
||||
if (a == null || string.IsNullOrWhiteSpace(a.Value))
|
||||
return defaultValue;
|
||||
|
||||
int intValue;
|
||||
|
||||
if (!int.TryParse(a.Value, out intValue))
|
||||
return defaultValue;
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
public static double ToDouble(this XAttribute a, double defaultValue = 0)
|
||||
{
|
||||
if (a == null || string.IsNullOrWhiteSpace(a.Value))
|
||||
return defaultValue;
|
||||
|
||||
double d;
|
||||
|
||||
if (!double.TryParse(a.Value, out d))
|
||||
return defaultValue;
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
122
CincyLib/PressBrake/LogDataParser.cs
Normal file
122
CincyLib/PressBrake/LogDataParser.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CincyLib.PressBrake
|
||||
{
|
||||
public class LogDataParser
|
||||
{
|
||||
public List<LogEvent> GetEvents(string filepath)
|
||||
{
|
||||
var xml = File.ReadAllText(filepath);
|
||||
|
||||
xml = xml.Insert(0, "<LogFile>");
|
||||
xml += "</LogFile>";
|
||||
|
||||
var doc = XDocument.Parse(xml);
|
||||
var elem = doc.Element("LogFile");
|
||||
|
||||
var events = new List<LogEvent>();
|
||||
|
||||
foreach (var e in elem.Elements())
|
||||
{
|
||||
Console.WriteLine(e.Name);
|
||||
|
||||
var name = e.Name.ToString();
|
||||
|
||||
switch (name)
|
||||
{
|
||||
case "ProgramStart":
|
||||
events.Add(ReadProgramStart(e));
|
||||
break;
|
||||
|
||||
case "ProgramStop":
|
||||
events.Add(ReadProgramStop(e));
|
||||
break;
|
||||
|
||||
case "Fault":
|
||||
events.Add(ReadFault(e));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
static ProgramStart ReadProgramStart(XElement e)
|
||||
{
|
||||
var programStart = new ProgramStart();
|
||||
programStart.DateTime = e.Attribute("DateTime").ToDateTime();
|
||||
programStart.ProgramName = e.FirstNode.NodeType == System.Xml.XmlNodeType.Text ? e.FirstNode.ToString().Trim() : null;
|
||||
programStart.RamGageMode = e.Element("RamGageMode")?.Value;
|
||||
programStart.UpperTool = e.Element("UpperTool")?.Value;
|
||||
programStart.LowerTool = e.Element("LowerTool")?.Value;
|
||||
|
||||
return programStart;
|
||||
}
|
||||
|
||||
static ProgramStop ReadProgramStop(XElement e)
|
||||
{
|
||||
var programStop = new ProgramStop();
|
||||
programStop.DateTime = e.Attribute("DateTime").ToDateTime();
|
||||
programStop.ProgramName = e.FirstNode.NodeType == System.Xml.XmlNodeType.Text ? e.FirstNode.ToString().Trim() : null;
|
||||
programStop.TotalPartCounter = e.Element("TotalPartCounter").ToIntOrNull();
|
||||
programStop.CurrentPartCounter = e.Element("CurrentPartCounter").ToIntOrNull();
|
||||
programStop.BatchCounter = e.Element("BatchCounter").ToIntOrNull();
|
||||
programStop.TotalMachineStrokes = e.Element("TotalMachineStrokes").ToIntOrNull();
|
||||
programStop.CurrentMachineStrokes = e.Element("CurrentMachineStrokes").ToIntOrNull();
|
||||
programStop.RunTime = e.Element("RunTime").ToTimeSpan();
|
||||
programStop.TotalCycleTime = e.Element("TotalCycleTime").ToDoubleOrNull();
|
||||
programStop.CurrentCycleTime = e.Element("CurrentCycleTime").ToDoubleOrNull();
|
||||
programStop.CurrentCycleTimeSec = e.Element("CurrentCycleTimeSec").ToDoubleOrNull();
|
||||
programStop.MainDriveOnTime = e.Element("MainDriveOnTime").ToDoubleOrNull();
|
||||
programStop.PowerOnTime = e.Element("PowerOnTime").ToDoubleOrNull();
|
||||
|
||||
return programStop;
|
||||
}
|
||||
|
||||
static Fault ReadFault(XElement e)
|
||||
{
|
||||
var fault = new Fault();
|
||||
fault.DateTime = e.Attribute("DateTime").ToDateTime();
|
||||
fault.Message = e.Value;
|
||||
|
||||
return fault;
|
||||
}
|
||||
}
|
||||
|
||||
public class LogEvent
|
||||
{
|
||||
public DateTime? DateTime { get; set; }
|
||||
}
|
||||
|
||||
public class ProgramStart : LogEvent
|
||||
{
|
||||
public string ProgramName { get; set; }
|
||||
public string RamGageMode { get; set; }
|
||||
public string LowerTool { get; internal set; }
|
||||
public string UpperTool { get; internal set; }
|
||||
}
|
||||
|
||||
public class ProgramStop : LogEvent
|
||||
{
|
||||
public string ProgramName { get; set; }
|
||||
public int? TotalPartCounter { get; set; }
|
||||
public int? CurrentPartCounter { get; set; }
|
||||
public int? BatchCounter { get; set; }
|
||||
public int? TotalMachineStrokes { get; set; }
|
||||
public int? CurrentMachineStrokes { get; internal set; }
|
||||
public TimeSpan? RunTime { get; set; }
|
||||
public double? TotalCycleTime { get; internal set; }
|
||||
public double? CurrentCycleTime { get; internal set; }
|
||||
public double? PowerOnTime { get; internal set; }
|
||||
public double? MainDriveOnTime { get; internal set; }
|
||||
public double? CurrentCycleTimeSec { get; internal set; }
|
||||
}
|
||||
|
||||
public class Fault : LogEvent
|
||||
{
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user