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

@ -2412,6 +2412,7 @@ namespace VEPROMS
{
if(parameter.StartsWith("/P="))
{
MSWordToPDF.Automatic = true;
PromsPrinter.BaselineTesting = true;// Set Baseline Testing property for PROMsPrinter
string[] dvstrs = parameter.Substring(3).Split(",".ToCharArray());
foreach (string dvstr in dvstrs)

View File

@ -908,29 +908,37 @@ namespace VEPROMS.CSLA.Library
pngFile = VlnSettings.TemporaryFolder + @"\XYPlot" + filecount.ToString() + @".png"; //@"C:\Temp\XYPlot1.png";
filecount++;
RectangleF plotRect = CreatePlot(pngFile, xyplot, 600F, FormForPlotGraphics);
float yAdjust = selxy.Font.Size;
float xxx = pt.X + plotRect.X;
if (xxx < 0 && xxx > -.5)
xxx = 0;
float yyy = yAdjust + y + plotRect.Y;
LBShape shape = myDoc.Shapes.AddPicture(pngFile, xxx, yyy, selxy.Range);
File.Delete(pngFile);
if (adjustMargins)
try // C2018-035 if an error occurs make the error message more specific
{
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;// .wdRelativeHorizontalPositionMargin;
RectangleF plotRect = CreatePlot(pngFile, xyplot, 600F, FormForPlotGraphics);
float yAdjust = selxy.Font.Size;
float xxx = pt.X + plotRect.X;
if (xxx < 0 && xxx > -.5)
xxx = 0;
float yyy = yAdjust + y + plotRect.Y;
LBShape shape = myDoc.Shapes.AddPicture(pngFile, xxx, yyy, selxy.Range);
File.Delete(pngFile);
if (adjustMargins)
{
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;// .wdRelativeHorizontalPositionMargin;
}
else
{
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin;
}
shape.LockAspectRatio = LBMsoTriState.msoTrue;
shape.Width = plotRect.Width;
shape.Left = xxx;
shape.Top = pt.Y;
}
else
catch (Exception ex)// C2018-035 if an error occurs make the error message more specific
{
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin;
// C2018-035 Don't use a messagebox if in automatic(Baseline) testing mode.
if (!Automatic) System.Windows.Forms.MessageBox.Show(ex.Message, "X/Y Plot Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
_MyLog.WarnFormat("Problem with XYPlot {0} - {1}", ex.GetType().Name, ex.Message);
}
shape.LockAspectRatio = LBMsoTriState.msoTrue;
shape.Width = plotRect.Width;
shape.Left = xxx;
shape.Top = pt.Y;
selxy.WholeStory();
selxy = FindXyPlot();
}
@ -1136,6 +1144,15 @@ namespace VEPROMS.CSLA.Library
return fileName;
}
}
private static bool _Automatic = false;
/// <summary>
/// C2018-035 Don't use a messagebox if in automatic(Baseline) testing mode.
/// </summary>
public static bool Automatic
{
get { return MSWordToPDF._Automatic; }
set { MSWordToPDF._Automatic = value; }
}
private static void AddErrorLogInfoMarginNotFixed(ItemInfo sect,string msg)// B2018-089 - Made error log output more useful
{
_MyLog.WarnFormat("\r\n==> {0}\r\n" +

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