B2018-088 - Corrected logic to handle partially processed ROs so that the code will not crash. Also changed the Error Log message to be more useful.

B2018-089 - Changed the Error Log message to be more useful when Word refuses to adjust Document margins during print.
This commit is contained in:
Rich 2018-06-11 14:29:57 +00:00
parent be7d9da0f0
commit 4d20d8219b
2 changed files with 39 additions and 11 deletions

View File

@ -534,7 +534,8 @@ namespace VEPROMS.CSLA.Library
} }
private string DoROAdjustments(string text) private string DoROAdjustments(string text)
{ {
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject:([0-9]*|<NewID>) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline); // B2018-088 - Added code to look for CROUSGID
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject:([0-9]*|<NewID>|<CROUSGID=-?[0-9]+>) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
string strippedText = StaticStripRtfCommands(text); string strippedText = StaticStripRtfCommands(text);
// (\\[^v \\]+)* --> look for any rtf commands (first part of lookFor) // (\\[^v \\]+)* --> look for any rtf commands (first part of lookFor)
// \\v0 --> end of comment // \\v0 --> end of comment
@ -565,13 +566,18 @@ namespace VEPROMS.CSLA.Library
myIndex = m.Groups[3].Index; myIndex = m.Groups[3].Index;
myLength += m.Groups[3].Length; myLength += m.Groups[3].Length;
} }
string gg = text.Substring(myIndex, myLength); string gg = text.Substring(myIndex, myLength).TrimEnd(" ".ToCharArray());// RHM 20180608 - Found an issue where the value contained a trailing space
//System.Text.RegularExpressions.Group g = m.Groups[3]; //System.Text.RegularExpressions.Group g = m.Groups[3];
string beforeRO = StaticStripRtfCommands(text.Substring(0, myIndex)); string beforeRO = StaticStripRtfCommands(text.Substring(0, myIndex));
string afterRO = StaticStripRtfCommands(text.Substring(myIndex + myLength)); string afterRO = StaticStripRtfCommands(text.Substring(myIndex + myLength));
Match myMatch = regRefObj.Match(m.ToString()); Match myMatch = regRefObj.Match(m.ToString());
if(m.ToString().ToUpper().Contains("<NEWID>")) // B-2018-088 Made Error Log output more useful
_MyLog.WarnFormat("Unprocessed RO in {0},({1})",_MyItemInfo.ShortPath,gg); if (m.ToString().ToUpper().Contains("<NEWID>") || m.ToString().ToUpper().Contains("<CROUSGID="))
_MyLog.WarnFormat("\r\n==> Unprocessed RO in [{0}] {1} with a value of {2} \r\n" +
" in {3}\r\n" +
" ACTION REQUIRED: Step should be relinked (Deleted, Retyped and Linked)",
_MyItemInfo.ItemID, _MyItemInfo.ShortPath,gg.Replace("\\u8209?","-"),
_MyItemInfo.SearchDVPath.Replace("\a","/"));
int dbid = System.Convert.ToInt32(myMatch.Groups[2].Value.Substring(0, 4), 16); int dbid = System.Convert.ToInt32(myMatch.Groups[2].Value.Substring(0, 4), 16);
int rodbid = int.Parse(myMatch.Groups[3].Value); int rodbid = int.Parse(myMatch.Groups[3].Value);
ROFstInfo myROFst = _MyItemInfo.MyDocVersion.GetROFst(rodbid); ROFstInfo myROFst = _MyItemInfo.MyDocVersion.GetROFst(rodbid);

View File

@ -842,7 +842,8 @@ namespace VEPROMS.CSLA.Library
} }
catch (Exception ex) catch (Exception ex)
{ {
_MyLog.Error("Could not Adjust Margins", ex); AddErrorLogInfoMarginNotFixed(sect,"Word section could not adjust margins"); // B2018-089 - Made error log output more useful
//_MyLog.Error("Could not Adjust Margins", ex);
} }
LBSelection selxy = hasRos ? FindXyPlot() : null; LBSelection selxy = hasRos ? FindXyPlot() : null;
string pngFile = VlnSettings.TemporaryFolder + @"\XYPlot1.png"; //@"C:\Temp\XYPlot1.png"; string pngFile = VlnSettings.TemporaryFolder + @"\XYPlot1.png"; //@"C:\Temp\XYPlot1.png";
@ -1101,6 +1102,16 @@ namespace VEPROMS.CSLA.Library
return fileName; return fileName;
} }
} }
private static void AddErrorLogInfoMarginNotFixed(ItemInfo sect,string msg)// B2018-089 - Made error log output more useful
{
_MyLog.WarnFormat("\r\n==> {0}\r\n" +
" [{1}] {2}\r\n" +
" in {3}\r\n" +
" Document: {4}\r\n" +
" ACTION REQUIRED: Should use Word Margins",
msg, sect.ItemID, sect.ShortPath,
sect.SearchDVPath.Replace("\a", "/"), sect.MyContent.MyEntry.MyDocument.LibTitle ?? sect.MyContent.MyEntry.DocID.ToString());
}
private static PointF GetLocation(LBSelection sel, bool adjustMargins) private static PointF GetLocation(LBSelection sel, bool adjustMargins)
{ {
LBRange rng0 = MyApp.ActiveDocument.Range(0, 0); LBRange rng0 = MyApp.ActiveDocument.Range(0, 0);
@ -1357,11 +1368,13 @@ namespace VEPROMS.CSLA.Library
{ {
if (_MySection != null) if (_MySection != null)
{ {
_MyLog.ErrorFormat("<<< ERROR >>> MSWord could not set margins\r\n==>'MSWord could not set margins',{0},'{1}','{2}'" AddErrorLogInfoMarginNotFixed(_MySection, "MSWord could not set Section margins");// B2018-089 - Made error log output more useful
, _MySection.ItemID, _MySection.MyDocVersion.MyFolder.Name, _MySection.ShortPath); //_MyLog.ErrorFormat("<<< ERROR >>> MSWord could not set margins\r\n==>'MSWord could not set margins',{0},'{1}','{2}'"
// , _MySection.ItemID, _MySection.MyDocVersion.MyFolder.Name, _MySection.ShortPath);
} }
else else
_MyLog.ErrorFormat("Could not set margins {0}", myDoc.FullName); AddErrorLogInfoMarginNotFixed(myDoc, "MSWord could not set Document margins");// B2018-089 - Made error log output more useful
//_MyLog.ErrorFormat("Could not set margins {0}", myDoc.FullName);
} }
} }
else else
@ -1378,11 +1391,13 @@ namespace VEPROMS.CSLA.Library
{ {
if (_MySection != null) if (_MySection != null)
{ {
_MyLog.ErrorFormat("<<< ERROR >>> MSWord could not set margins\r\n==>'MSWord could not set margins',{0},'{1}','{2}'" AddErrorLogInfoMarginNotFixed(_MySection, "MSWord could not set Section margins");// B2018-089 - Made error log output more useful
, _MySection.ItemID, _MySection.MyDocVersion.MyFolder.Name, _MySection.ShortPath); //_MyLog.ErrorFormat("<<< ERROR >>> MSWord could not set margins\r\n==>'MSWord could not set margins',{0},'{1}','{2}'"
// , _MySection.ItemID, _MySection.MyDocVersion.MyFolder.Name, _MySection.ShortPath);
} }
else else
_MyLog.Error("Could not set margins", ex); AddErrorLogInfoMarginNotFixed(myDoc, "MSWord could not set Document margins");// B2018-089 - Made error log output more useful
//_MyLog.Error("Could not set margins", ex);
} }
} }
} }
@ -1404,6 +1419,13 @@ namespace VEPROMS.CSLA.Library
myDoc.PageSetup.BottomMargin = Math.Max(0, bm); myDoc.PageSetup.BottomMargin = Math.Max(0, bm);
} }
} }
private static void AddErrorLogInfoMarginNotFixed(LBDocumentClass myDoc, string msg)// B2018-089 - Made error log output more useful
{
_MyLog.WarnFormat("\r\n==> {0}\r\n" +
" Document: {1}\r\n" +
" ACTION REQUIRED: Should use Word Margins",
msg, myDoc.FullName);
}
public static void CloseApp() public static void CloseApp()
{ {
//WaitMS(900);// This was added because MSWord will sometimes get the error below //WaitMS(900);// This was added because MSWord will sometimes get the error below