From ee241103c621e32518a9d88ec9b44176f4ae3572 Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 22 Aug 2019 15:26:51 +0000 Subject: [PATCH] C2018-035 Added error Handling to provide more useful information when a plot fails --- PROMS/VEPROMS User Interface/frmVEPROMS.cs | 1 + .../Extension/DocumentExt.cs | 55 +++++++++------ PROMS/XYPlots/XYPlots.cs | 67 ++++++++++++++++--- 3 files changed, 94 insertions(+), 29 deletions(-) diff --git a/PROMS/VEPROMS User Interface/frmVEPROMS.cs b/PROMS/VEPROMS User Interface/frmVEPROMS.cs index 7b218ab7..e4abfbf2 100644 --- a/PROMS/VEPROMS User Interface/frmVEPROMS.cs +++ b/PROMS/VEPROMS User Interface/frmVEPROMS.cs @@ -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) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 8e3d8b7b..30b25f8a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -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; + /// + /// C2018-035 Don't use a messagebox if in automatic(Baseline) testing mode. + /// + 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" + diff --git a/PROMS/XYPlots/XYPlots.cs b/PROMS/XYPlots/XYPlots.cs index cee1681b..dc098b3f 100644 --- a/PROMS/XYPlots/XYPlots.cs +++ b/PROMS/XYPlots/XYPlots.cs @@ -15,6 +15,10 @@ namespace XYPlots /// 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 { } @@ -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 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) {