B2026-052 - Issue when parens inside a Hardspaced Multi-RO Return Values.

PROMS crashes when doing an update ROFst.
This commit is contained in:
2026-06-25 15:46:25 -04:00
parent 38e42723af
commit 7f75af7119
+122 -93
View File
@@ -8,7 +8,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using static System.Net.Mime.MediaTypeNames;
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
@@ -61,6 +60,7 @@ namespace VEPROMS.CSLA.Library
#region Structs / Internal Classes #region Structs / Internal Classes
[Serializable] [Serializable]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Keep Older Pre-existing naming conventions")]
public struct roHdr public struct roHdr
{ {
public int hSize; public int hSize;
@@ -78,6 +78,7 @@ namespace VEPROMS.CSLA.Library
}; };
[Serializable] [Serializable]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Keep Older Pre-existing naming conventions")]
public struct rodbi public struct rodbi
{ {
public int dbiID; public int dbiID;
@@ -91,6 +92,7 @@ namespace VEPROMS.CSLA.Library
}; };
[Serializable] [Serializable]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Keep Older Pre-existing naming conventions")]
public struct rogrp public struct rogrp
{ {
public string value; public string value;
@@ -102,6 +104,7 @@ namespace VEPROMS.CSLA.Library
}; };
[Serializable] [Serializable]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Keep Older Pre-existing naming conventions")]
public struct rochild public struct rochild
{ {
public int ID; public int ID;
@@ -133,7 +136,7 @@ namespace VEPROMS.CSLA.Library
private List<string> _baseAccPageKeys; private List<string> _baseAccPageKeys;
// RofstLookup/Conversion Variables // RofstLookup/Conversion Variables
private int _rofstID; private readonly int _rofstID;
private DocVersionInfo _myDocVersionInfo; private DocVersionInfo _myDocVersionInfo;
private int _selectedSlave; private int _selectedSlave;
private string _otherChild = string.Empty; private string _otherChild = string.Empty;
@@ -149,7 +152,7 @@ namespace VEPROMS.CSLA.Library
// B2022-107: Display Progress Bar Messages/Statuses when a new ROFST binary file is loaded into the database // B2022-107: Display Progress Bar Messages/Statuses when a new ROFST binary file is loaded into the database
private frmRofstLoadStatus _frmRofstLoadStatus = null; private frmRofstLoadStatus _frmRofstLoadStatus = null;
private Dictionary<int, int> _dicRoCounts = null; private Dictionary<int, int> _dicRoCounts = null;
private bool _showLoadingStatus = true; private readonly bool _showLoadingStatus = true;
private int _curRoCnt = 0; private int _curRoCnt = 0;
private int _dbRoCnt = 0; private int _dbRoCnt = 0;
@@ -414,7 +417,6 @@ namespace VEPROMS.CSLA.Library
ROFSTLookup.rochild rc = RofstDataGetChildByAccPageID(_rofstID, accPageBase); ROFSTLookup.rochild rc = RofstDataGetChildByAccPageID(_rofstID, accPageBase);
//if (rc.ID >=0 && rc.roid.Length < 16 && Regex.IsMatch(accPageKey, @".*\.[A-Z]") && rc.children != null && rc.children.Count() > 0)
if (rc.ID >= 0 && rc.roid.Length < 16 && !string.IsNullOrEmpty(accPageExt) && rc.children != null && rc.children.Count() > 0) if (rc.ID >= 0 && rc.roid.Length < 16 && !string.IsNullOrEmpty(accPageExt) && rc.children != null && rc.children.Count() > 0)
{ {
// Check if AccPageID/Key has a return value specific extension. Try to find the RoChild record with the specific return value type, // Check if AccPageID/Key has a return value specific extension. Try to find the RoChild record with the specific return value type,
@@ -507,8 +509,6 @@ namespace VEPROMS.CSLA.Library
// B2023-037: Handle <=, >=, +-, -> and <- symbols. Convert to unicode for output, i.e. print and edit/view (when editing // B2023-037: Handle <=, >=, +-, -> and <- symbols. Convert to unicode for output, i.e. print and edit/view (when editing
// step, will show as 2 characters, not unicode, unless ro inserted when code replaced link text with unicode. // step, will show as 2 characters, not unicode, unless ro inserted when code replaced link text with unicode.
//(_MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.UseDashGreaterLessThenForArrowsInROValue ||
// _MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertGTELTEPMinROValue))
bool arrows1 = myiteminfo.ActiveFormat.PlantFormat.FormatData.SectData.UseDashGreaterLessThenForArrowsInROValue; bool arrows1 = myiteminfo.ActiveFormat.PlantFormat.FormatData.SectData.UseDashGreaterLessThenForArrowsInROValue;
bool arrows2 = myiteminfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertGTELTEPMinROValue; bool arrows2 = myiteminfo.ActiveFormat.PlantFormat.FormatData.SectData.ConvertGTELTEPMinROValue;
@@ -681,11 +681,10 @@ namespace VEPROMS.CSLA.Library
if (minutes > 0) duration = string.Format("{0} min(s) ", minutes.ToString("n0")); if (minutes > 0) duration = string.Format("{0} min(s) ", minutes.ToString("n0"));
if (secs < 0) secs = 0.00; if (secs < 0) secs = 0.00;
duration = duration + string.Format("{0,10:#####0.00} sec(s)", secs).Trim(); duration += string.Format("{0,10:#####0.00} sec(s)", secs).Trim();
return duration; return duration;
//return string.Format("{0,10:#####0.00}", TimeSpan.FromTicks(DateTime.Now.Ticks - dtStart.Ticks).TotalSeconds);
} }
//C2026-008 Re-Architect RO.FST to include RO Modification date/time //C2026-008 Re-Architect RO.FST to include RO Modification date/time
@@ -1475,19 +1474,20 @@ namespace VEPROMS.CSLA.Library
private ROFSTLookup.roHdr ConvertFst2Objects(byte[] ab) private ROFSTLookup.roHdr ConvertFst2Objects(byte[] ab)
{ {
ROFSTLookup.roHdr roh = new ROFSTLookup.roHdr(); ROFSTLookup.roHdr roh = new ROFSTLookup.roHdr
{
roh.hSize = BitConverter.ToInt32(ab, 0); hSize = BitConverter.ToInt32(ab, 0),
roh.hYear = BitConverter.ToInt16(ab, 4); hYear = BitConverter.ToInt16(ab, 4),
roh.hMonth = ab[6]; hMonth = ab[6],
roh.hDay = ab[7]; hDay = ab[7],
roh.hcYear = BitConverter.ToInt16(ab, 8); hcYear = BitConverter.ToInt16(ab, 8),
roh.hcMonth = ab[10]; hcMonth = ab[10],
roh.hcDay = ab[11]; hcDay = ab[11],
roh.hcHour = ab[12]; hcHour = ab[12],
roh.hcMin = ab[13]; hcMin = ab[13],
roh.hcSec = ab[14]; hcSec = ab[14],
roh.hcHund = ab[15]; hcHund = ab[15]
};
int hdrOffset = BitConverter.ToInt32(ab, 16); int hdrOffset = BitConverter.ToInt32(ab, 16);
int dbs = BitConverter.ToInt16(ab, hdrOffset + 4); int dbs = BitConverter.ToInt16(ab, hdrOffset + 4);
@@ -1525,10 +1525,11 @@ namespace VEPROMS.CSLA.Library
private ROFSTLookup.rogrp LoadGroup(byte[] ab, int offset, int tableID) private ROFSTLookup.rogrp LoadGroup(byte[] ab, int offset, int tableID)
{ {
ROFSTLookup.rogrp myGrp = new ROFSTLookup.rogrp(); ROFSTLookup.rogrp myGrp = new ROFSTLookup.rogrp
{
myGrp.ID = BitConverter.ToInt32(ab, offset); ID = BitConverter.ToInt32(ab, offset),
myGrp.ParentID = BitConverter.ToInt32(ab, offset + 4); ParentID = BitConverter.ToInt32(ab, offset + 4)
};
int numChildren = BitConverter.ToInt16(ab, offset + 8); int numChildren = BitConverter.ToInt16(ab, offset + 8);
@@ -1660,7 +1661,7 @@ namespace VEPROMS.CSLA.Library
} }
// Update Progress Bar Accordingly // Update Progress Bar Accordingly
if (_totalRoCnt > 0) _pctComplete = _pctComplete + ((Convert.ToDouble(_dbRoCnt) / Convert.ToDouble(_totalRoCnt)) * 80.0); if (_totalRoCnt > 0) _pctComplete += ((Convert.ToDouble(_dbRoCnt) / Convert.ToDouble(_totalRoCnt)) * 80.0);
OnProgressChanged(displayText, Convert.ToInt32(_pctComplete), 100); OnProgressChanged(displayText, Convert.ToInt32(_pctComplete), 100);
} }
@@ -1720,15 +1721,13 @@ namespace VEPROMS.CSLA.Library
protected virtual void OnProgressChanged(string title, string displayText, int curVal = 0, int maxVal = 100) protected virtual void OnProgressChanged(string title, string displayText, int curVal = 0, int maxVal = 100)
{ {
// If frmRofstLoadStatus is not null then call Update Progress Method // If frmRofstLoadStatus is not null then call Update Progress Method
if (_frmRofstLoadStatus != null) _frmRofstLoadStatus?.UpdateProgress(title, displayText, curVal, maxVal);
_frmRofstLoadStatus.UpdateProgress(title, displayText, curVal, maxVal);
} }
protected virtual void OnProgressChanged(string displayText, int curVal = 0, int maxVal = 100) protected virtual void OnProgressChanged(string displayText, int curVal = 0, int maxVal = 100)
{ {
// If frmRofstLoadStatus is not null then call Update Progress Method // If frmRofstLoadStatus is not null then call Update Progress Method
if (_frmRofstLoadStatus != null) _frmRofstLoadStatus?.UpdateProgress(_frmRofstLoadStatus.Title, displayText, curVal, maxVal);
_frmRofstLoadStatus.UpdateProgress(_frmRofstLoadStatus.Title, displayText, curVal, maxVal);
} }
#endregion #endregion
@@ -1739,19 +1738,20 @@ namespace VEPROMS.CSLA.Library
private ROFSTLookup.roHdr ConvertToRoHdrObject(SafeDataReader dr, bool loadChildren) private ROFSTLookup.roHdr ConvertToRoHdrObject(SafeDataReader dr, bool loadChildren)
{ {
ROFSTLookup.roHdr rh = new ROFSTLookup.roHdr(); ROFSTLookup.roHdr rh = new ROFSTLookup.roHdr
{
rh.hSize = (int)dr.GetValue("hSize"); hSize = (int)dr.GetValue("hSize"),
rh.hYear = (int)dr.GetValue("hYear"); hYear = (int)dr.GetValue("hYear"),
rh.hMonth = (byte)dr.GetValue("hMonth"); hMonth = (byte)dr.GetValue("hMonth"),
rh.hDay = (byte)dr.GetValue("hDay"); hDay = (byte)dr.GetValue("hDay"),
rh.hcYear = (int)dr.GetValue("hcYear"); hcYear = (int)dr.GetValue("hcYear"),
rh.hcMonth = (byte)dr.GetValue("hcMonth"); hcMonth = (byte)dr.GetValue("hcMonth"),
rh.hcDay = (byte)dr.GetValue("hcDay"); hcDay = (byte)dr.GetValue("hcDay"),
rh.hcHour = (byte)dr.GetValue("hcHour"); hcHour = (byte)dr.GetValue("hcHour"),
rh.hcMin = (byte)dr.GetValue("hcMin"); hcMin = (byte)dr.GetValue("hcMin"),
rh.hcSec = (byte)dr.GetValue("hcSec"); hcSec = (byte)dr.GetValue("hcSec"),
rh.hcHund = (byte)dr.GetValue("hcHund"); hcHund = (byte)dr.GetValue("hcHund")
};
if (loadChildren) if (loadChildren)
{ {
@@ -1763,15 +1763,16 @@ namespace VEPROMS.CSLA.Library
private ROFSTLookup.rodbi ConvertToRodbiObject(SafeDataReader dr, bool loadChildren, bool loadAllChildren) private ROFSTLookup.rodbi ConvertToRodbiObject(SafeDataReader dr, bool loadChildren, bool loadAllChildren)
{ {
ROFSTLookup.rodbi rd = new ROFSTLookup.rodbi(); ROFSTLookup.rodbi rd = new ROFSTLookup.rodbi
{
rd.dbiID = (int)dr.GetValue("dbiID"); dbiID = (int)dr.GetValue("dbiID"),
rd.dbiType = (int)dr.GetValue("dbiType"); dbiType = (int)dr.GetValue("dbiType"),
rd.dbiAW = (int)dr.GetValue("dbiAW"); dbiAW = (int)dr.GetValue("dbiAW"),
rd.dbiAP = (string)dr.GetValue("dbiAP"); dbiAP = (string)dr.GetValue("dbiAP"),
rd.dbiTitle = (string)dr.GetValue("dbiTitle"); dbiTitle = (string)dr.GetValue("dbiTitle"),
rd.ID = (int)dr.GetValue("ID"); ID = (int)dr.GetValue("ID"),
rd.ParentID = (int)dr.GetValue("ParentID"); ParentID = (int)dr.GetValue("ParentID")
};
if (loadChildren || loadAllChildren) if (loadChildren || loadAllChildren)
{ {
@@ -1783,13 +1784,14 @@ namespace VEPROMS.CSLA.Library
private ROFSTLookup.rochild ConvertToRochildObject(SafeDataReader dr, bool loadChildren, bool loadAllChildren) private ROFSTLookup.rochild ConvertToRochildObject(SafeDataReader dr, bool loadChildren, bool loadAllChildren)
{ {
ROFSTLookup.rochild rc = new ROFSTLookup.rochild(); ROFSTLookup.rochild rc = new ROFSTLookup.rochild
{
rc.ID = (int)dr.GetValue("ID"); ID = (int)dr.GetValue("ID"),
rc.ParentID = (int)dr.GetValue("ParentID"); ParentID = (int)dr.GetValue("ParentID"),
rc.type = (int)dr.GetValue("type"); type = (int)dr.GetValue("type"),
rc.title = (string)dr.GetValue("title"); title = (string)dr.GetValue("title"),
rc.roid = (string)dr.GetValue("roid"); roid = (string)dr.GetValue("roid")
};
if (!string.IsNullOrEmpty((string)dr.GetValue("appid"))) if (!string.IsNullOrEmpty((string)dr.GetValue("appid")))
{ {
@@ -1811,11 +1813,12 @@ namespace VEPROMS.CSLA.Library
private ROFSTLookup.RoExtension ConvertToRoExtensionObject(SafeDataReader dr) private ROFSTLookup.RoExtension ConvertToRoExtensionObject(SafeDataReader dr)
{ {
ROFSTLookup.RoExtension re = new ROFSTLookup.RoExtension(); ROFSTLookup.RoExtension re = new ROFSTLookup.RoExtension
{
re.Offset = (int)dr.GetValue("Offset"); Offset = (int)dr.GetValue("Offset"),
re.RoidExt = (string)dr.GetValue("RoidExt"); RoidExt = (string)dr.GetValue("RoidExt"),
re.AccPageExt = (string)dr.GetValue("AccPageExt"); AccPageExt = (string)dr.GetValue("AccPageExt")
};
return re; return re;
} }
@@ -1875,7 +1878,6 @@ namespace VEPROMS.CSLA.Library
// Instead of returning the RoChildBase object with a single RoReturnVal object attached, just return the single Ro ReturnValue object. // Instead of returning the RoChildBase object with a single RoReturnVal object attached, just return the single Ro ReturnValue object.
var roRetVal = child.children.First(); var roRetVal = child.children.First();
//child.title = roRetVal.title;
child.appid = roRetVal.appid; child.appid = roRetVal.appid;
child.roid = roRetVal.roid; child.roid = roRetVal.roid;
child.value = roRetVal.value; child.value = roRetVal.value;
@@ -2129,41 +2131,68 @@ namespace VEPROMS.CSLA.Library
return ProcessRO(match, multiRtnVal); return ProcessRO(match, multiRtnVal);
} }
private string ProcessMacros(string str)
{
// Takes the RO text value and sees if a macro has been used. // Takes the RO text value and sees if a macro has been used.
// If so it will perform the macro operation on the substring in the text value // If so it will perform the macro operation on the substring in the text value
// Note** Right now the only macro is @HSP(), where every space between the "(" and ")" will be replaced with a hard space // Note** Right now the only macro is @HSP(), where every space between the "(" and ")" will be replaced with a hard space
private static string ProcessMacros(string str)
{
if (string.IsNullOrEmpty(str)) if (string.IsNullOrEmpty(str) || str.ToUpper().IndexOf("@HSP(") < 0)
return str; return str;
string rtnstr = str;
int indx;
while ((indx = rtnstr.ToUpper().IndexOf("@HSP(")) > -1) string processingstr = str; //holds current string being processed
{ int indx; //current position of @HSP( in string
string resstr = rtnstr.Substring(0, indx); int endpos = 0; //end of last parens
int endHsp = rtnstr.IndexOf(")", indx);
//B2026 - 002 handle if parens inside a HSP StringBuilder sb = new StringBuilder();
int startpos = indx + 5; Stack<char> endparens = new Stack<char>();
while (rtnstr.Substring(startpos, endHsp - startpos).Contains("("))
while ((indx = processingstr.ToUpper().IndexOf("@HSP(")) > -1)
{ {
startpos = rtnstr.IndexOf("(", startpos + 1, endHsp - startpos) + 1; sb.Append(processingstr.Substring(0, indx)); // initial string before @HSP(
endHsp = rtnstr.IndexOf(")", endHsp + 1);
for (int i = indx + 5; i < processingstr.Length; i++)
{
char ch = processingstr[i];
if (ch == '(')
{
//if opening paren inside HSP add it to the stack to look for a closing parens
endparens.Push(ch);
}
else if (ch == ')' && endparens.Count > 0)
{
//if cloing parens and it matches an opening parens inside of HSP, remove a level
_ = endparens.Pop();
}
else if (ch == ')' && endparens.Count == 0)
{
//if closing parens and at same level as HSP, break out since found correct closing parens
endpos = i;
break;
}
else if (i == processingstr.Length - 1)
{
//if hit the end of the string and no matching closing parens found, take to the end of the string
endpos = processingstr.Length;
}
} }
string tmpstr = rtnstr.Substring(indx + 5, endHsp - indx - 5); //Add the text inside the @HSP(...)
string tmpstr = processingstr.Substring(indx + 5, endpos - indx - 5);
// B2017-012 Don't convert space to hard spaces for XY Plots. // B2017-012 Don't convert space to hard spaces for XY Plots.
if (!tmpstr.Contains("<<G")) tmpstr = tmpstr.Replace(" ", @"\u160?"); if (!tmpstr.Contains("<<G")) tmpstr = tmpstr.Replace(" ", @"\u160?");
sb.Append(tmpstr);
resstr = resstr + tmpstr; //Set the processing string to after the ending parens found in case multiple @HSP
rtnstr = resstr + rtnstr.Substring(endHsp + 1); processingstr = endpos + 1 >= processingstr.Length ? "" : processingstr.Substring(endpos + 1);
} }
return rtnstr; //add text after last end parens
sb.Append(processingstr);
return sb.ToString();
} }
private int StringLength(byte[] ab, int offset) private int StringLength(byte[] ab, int offset)
@@ -2275,7 +2304,7 @@ namespace VEPROMS.CSLA.Library
{ {
rc.roid = FormatRoidKey(roid).Substring(0, 12); rc.roid = FormatRoidKey(roid).Substring(0, 12);
DocVersionConfig dvc = (_myDocVersionInfo != null) ? _myDocVersionInfo.DocVersionConfig : null; DocVersionConfig dvc = _myDocVersionInfo?.DocVersionConfig;
if (dvc != null) dvc.SelectedSlave = this.SelectedSlave; if (dvc != null) dvc.SelectedSlave = this.SelectedSlave;
switch (rc.roid) switch (rc.roid)
@@ -2283,49 +2312,49 @@ namespace VEPROMS.CSLA.Library
case "FFFF00000001": case "FFFF00000001":
rc.title = "Number"; rc.title = "Number";
rc.appid = "U-NUMBER"; rc.appid = "U-NUMBER";
rc.value = (dvc != null) ? dvc.Unit_Number : null; rc.value = dvc?.Unit_Number;
break; break;
case "FFFF00000002": case "FFFF00000002":
rc.title = "Other Number"; rc.title = "Other Number";
rc.appid = "U-OTHERNUMBER"; rc.appid = "U-OTHERNUMBER";
rc.value = (dvc != null) ? dvc.Other_Unit_Number : null; rc.value = dvc?.Other_Unit_Number;
break; break;
case "FFFF00000003": case "FFFF00000003":
rc.title = "Text"; rc.title = "Text";
rc.appid = "U-TEXT"; rc.appid = "U-TEXT";
rc.value = (dvc != null) ? dvc.Unit_Text : null; rc.value = dvc?.Unit_Text;
break; break;
case "FFFF00000004": case "FFFF00000004":
rc.title = "Other Text"; rc.title = "Other Text";
rc.appid = "U-OTHERTEXT"; rc.appid = "U-OTHERTEXT";
rc.value = (dvc != null) ? dvc.Other_Unit_Text : null; rc.value = dvc?.Other_Unit_Text;
break; break;
case "FFFF00000005": case "FFFF00000005":
rc.title = "ID"; rc.title = "ID";
rc.appid = "U-ID"; rc.appid = "U-ID";
rc.value = (dvc != null) ? dvc.Unit_ID : null; rc.value = dvc?.Unit_ID;
break; break;
case "FFFF00000006": case "FFFF00000006":
rc.title = "Other ID"; rc.title = "Other ID";
rc.appid = "U-OTHERID"; rc.appid = "U-OTHERID";
rc.value = (dvc != null) ? dvc.Other_Unit_ID : null; rc.value = dvc?.Other_Unit_ID;
break; break;
case "FFFF00000007": case "FFFF00000007":
rc.title = "Name"; rc.title = "Name";
rc.appid = "U-NAME"; rc.appid = "U-NAME";
rc.value = (dvc != null) ? dvc.Unit_Name : null; rc.value = dvc?.Unit_Name;
break; break;
case "FFFF00000008": case "FFFF00000008":
rc.title = "Other Name"; rc.title = "Other Name";
rc.appid = "U-OTHERNAME"; rc.appid = "U-OTHERNAME";
rc.value = (dvc != null) ? dvc.Other_Unit_Name : null; rc.value = dvc?.Other_Unit_Name;
break; break;
} }