C2018-035 Added error Handling to provide more useful information when a plot fails

This commit is contained in:
Rich
2019-08-22 15:26:51 +00:00
parent 17f24b7100
commit ee241103c6
3 changed files with 94 additions and 29 deletions

View File

@@ -15,6 +15,10 @@ namespace XYPlots
/// </summary>
public class XYPlot
{
#region Log4Net
// C2018-035 Added error Handling to provide more useful information when a plot fails
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
static string _MyFontFamily = "Letter Gothic Tall";
public static string MyFontFamily
{
@@ -158,6 +162,10 @@ namespace XYPlots
private XyBoxes ActiveBoxes = new XyBoxes();
public class DataPoint
{
public override string ToString() // Make it easier to Debug
{
return string.Format("{0},{1}", APoint.xyValue[X],APoint.xyValue[Y]);
}
private point m_APoint;
public point APoint
{
@@ -170,7 +178,7 @@ namespace XYPlots
get { return m_slope; }
set { m_slope = value; }
}
};
}
public class DataPoints : List<DataPoint>
{
}
@@ -385,14 +393,27 @@ namespace XYPlots
else
return nxtstring[0];
}
// C2018-035 Added error Handling to provide more useful information when a plot fails
private string _XYPlotIssue;
public string XYPlotIssue
{
get { return _XYPlotIssue; }
set { _XYPlotIssue = value; }
}
private point GetPair(int flag)
{
point retval = new point();
retval.xyValue = new int[Dimensions];
double x, y;
char[] sepchar = { ',' };
string[] xystr = NextPiece().Split(sepchar);
x = double.Parse(xystr[0]);
string nextPiece = NextPiece(); // Plot Definition
string[] xystr = nextPiece.Split(sepchar);
// C2018-035 Added error Handling to provide more useful information when a plot fails
if (xystr.Length != 2)
XYPlotIssue = String.Format("Invalid Pair {0}", nextPiece);
if (xystr.Length == 1)
throw new Exception(XYPlotIssue);
x = double.Parse(xystr[0]);
char[] trimEndDot = { '.' }; // Wolf Creek OFN SB-008, figure 3 had a string like 50.0. so trim the ending '.'
string ystr = xystr[1];
if (ystr.EndsWith(".0")) // bug fix B2012-169, the Trim converted a ".75" value to a "75.0" value
@@ -1128,12 +1149,29 @@ namespace XYPlots
}
private void DrawCurve(PlotLine linestart, VG.Page pg, IVGOutput vgOutput)
{
CheckDataPoints(linestart);
int pltptListIdx = -1;
while (++pltptListIdx < linestart.PlotDataPoints.Count - 1)
{
DoSubArcs(linestart.PlotDataPoints, pltptListIdx, pg, vgOutput);
}
}
private void CheckDataPoints(PlotLine linestart)
{
for(int i = 0;i<linestart.PlotDataPoints.Count-1;i++)
{
DataPoint dp0 = linestart.PlotDataPoints[i];
DataPoint dp1 = linestart.PlotDataPoints[i+1];
double x0 = dp0.APoint.xyValue[X];
double x1 = dp1.APoint.xyValue[X];
if (x0 > x1)
{
XYPlotIssue = "X Values should be Increasing";
throw new Exception("Curve has Invalid Values");
}
}
}
private double GetAngle(double s1)
{
double t1;
@@ -1962,13 +2000,22 @@ namespace XYPlots
public void Process(IVGOutput vgOutput)
{
VG.Page pg = new Page(true, _LeftMargin, _TopMargin, _RightMargin, _BottomMargin);
GenerateGrid(pg, vgOutput);
DoAxisTitles(pg, vgOutput);
DrawLines(pg, vgOutput);
DoBoxes(pg, vgOutput);
FreeBoxList();
FreeLineList();
CloseGraph();
string step = "Process";
try // C2018-035 Added error Handling to Process to provide more useful information when a plot fails
{
step = "GenerateGrid";GenerateGrid(pg, vgOutput);
step = "DoAxisTitles";DoAxisTitles(pg, vgOutput);
step = "DrawLines";DrawLines(pg, vgOutput);
step = "DoBoxes";DoBoxes(pg, vgOutput);
step = "FreeBoxList";FreeBoxList();
step = "FreeLineList";FreeLineList();
step = "CloseGraph";CloseGraph();
}
catch (Exception ex)
{
_MyLog.WarnFormat("X/Y Plot Error - {0} - {1} - {2}", step, XYPlotIssue ?? "Unknown Issue");
throw new Exception(String.Format("X/Y Plot Error - {0} - {1}",step,XYPlotIssue ?? "Unknown Issue"));
}
}
private void ShowPoints(DataPoints dataPoints)
{