From d77494d6e4a4deafc0bee8e8264acc4c8f58e51f Mon Sep 17 00:00:00 2001 From: John Date: Thu, 26 May 2022 20:27:06 +0000 Subject: [PATCH] B2022-026 RO Memory reduction coding --- .../Config/ROFSTLookup.cs | 2964 ++++++++++------- 1 file changed, 1697 insertions(+), 1267 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs b/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs index 6aa270e2..14726ccb 100644 --- a/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs +++ b/PROMS/VEPROMS.CSLA.Library/Config/ROFSTLookup.cs @@ -1,22 +1,55 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Text; using System.ComponentModel; using System.Text.RegularExpressions; -using System.IO; -using Volian.Base.Library; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using Csla.Data; + +// B2022-026 New code for RO Memory reduction - now use SQL tables instead of building dictionarys to get RO values namespace VEPROMS.CSLA.Library { + + [Flags] + public enum E_ROValueType : uint + { + All = 0, + Text = 1, + Table = 2, + Graph = 4, + Image = 8, + Video = 16, + Hologram = 32 + } + [Serializable] [TypeConverter(typeof(ExpandableObjectConverter))] public class ROFSTLookup { #region Log4Net + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #endregion - #region Structs + + #region Enums + + [Flags] + public enum SearchType + { + StartsWith = 1, + EndsWith = 2, + Contains = 3, + ExactMatch = 4 + } + + #endregion + + #region Structs / Internal Classes + [Serializable] public struct roHdr { @@ -33,6 +66,7 @@ namespace VEPROMS.CSLA.Library public byte hcHund; public rodbi[] myDbs; }; + [Serializable] public struct rodbi { @@ -45,16 +79,18 @@ namespace VEPROMS.CSLA.Library public int ParentID; public rochild[] children; }; - // rogrp defines tree structure + + [Serializable] public struct rogrp { + public string value; + public string appid; public int ID; public int ParentID; public rochild[] children; - public string value; - public string appid; }; - // rochild can be read directory from the ro.fst. Read in from ro.fst as bytes. + + [Serializable] public struct rochild { public int ID; @@ -66,7 +102,8 @@ namespace VEPROMS.CSLA.Library public string value; // return value, can be multiple values public rochild[] children; }; - // roChild is a container for rochild + + public class roChild { //private static int _roChildUnique = 0; @@ -87,165 +124,296 @@ namespace VEPROMS.CSLA.Library } public override string ToString() { - return _MyChild.title.Replace("\\u160?"," "); + return _MyChild.title.Replace("\\u160?", " "); } }; - #endregion - #region Local Data - private string _ROValue = ""; - private List lstRoValues; - private List multiRoValues; - private Dictionary DictROVar = new Dictionary(); //use this to find values within return value - #endregion - #region Constructors - private ROFst _ROFst; - private ROFstInfo _ROFstInfo; - private int _SelectedSlave; - private DocVersionInfo _MyDocVersionInfo; + #endregion - private ItemInfo _MyItemInfo; // B2022-020 to pass information into error log if needed - public ItemInfo MyItemInfo + #region Fields + + public static Regex regRoKeyHigh = new Regex("( |-|_)(HIGH|HI)([0-9])"); + public static Regex regRoKeyLow = new Regex("( |-|_)(LOW|LO)([0-9])"); + + // RofstLookup/Conversion Variables + private int _rofstID; + private DocVersionInfo _myDocVersionInfo; + private int _selectedSlave; + private string _otherChild = string.Empty; + + private List _lstRoValues; + private List _multiRoValues; + private Dictionary _dicRoVars; + + private ItemInfo _itemInfo; + + #endregion + + #region Properties + + public int RofstID { - get { return _MyItemInfo; } - set { _MyItemInfo = value; } + get { return _rofstID; } } + public DocVersionInfo MyDocVersionInfo { - get { return _MyDocVersionInfo; } - set - { - _MyDocVersionInfo = value; - if (_MyDocVersionInfo.DocVersionConfig.SelectedSlave != _SelectedSlave) - { - _SelectedSlave = _MyDocVersionInfo.DocVersionConfig.SelectedSlave; - Reset(); - } - } - } - //C2021-065 used by Barakah Alarms so that we get ROLookUp for the Other applicability - private string _OtherChild; - public string OtherChild - { - get - { return _OtherChild;} + get { return _myDocVersionInfo; } set - { _OtherChild = value;} + { + _myDocVersionInfo = value; + _selectedSlave = (_myDocVersionInfo == null) ? 0 : _myDocVersionInfo.DocVersionConfig.SelectedSlave; + } } - public ROFSTLookup(ROFst rofst, DocVersionInfo dvi) + // C2021-065 see if we need to get the RO information for the "Other" Child applicability value + public int SelectedSlave { - _ROFst = rofst; - _ROFstInfo = null; - using (ROFstInfo rfi = ROFstInfo.GetJustROFst(_ROFst.ROFstID)) + get { return (!string.IsNullOrEmpty(_otherChild)) ? Convert.ToInt32(_otherChild) : _selectedSlave; } + } + + //C2021-065 used by Barakah Alarms so that we get ROLookUp for the Other applicability + public string OtherChild + { + get { return _otherChild; } + set { _otherChild = value; } + } + + // B2022-020 to pass information into error log if needed + public ItemInfo MyItemInfo + { + get { return _itemInfo; } + set { _itemInfo = value; } + } + + #endregion + + #region Constructors + + public ROFSTLookup(int rofstID, DocVersionInfo dvi, string otherChild) + { + _rofstID = rofstID; + MyDocVersionInfo = dvi; + _otherChild = otherChild; + + if (!RofstDataExists(rofstID)) { - _MyDocVersionInfo = dvi;//==null?null: DocVersionInfo.Get(rfi.docVer.VersionID); + Load(rofstID); } - ParseIntoDictionary(rofst.ROLookup); } - public ROFSTLookup(ROFstInfo rofstinfo, DocVersionInfo dvi) + + public ROFSTLookup(int rofstID, DocVersionInfo dvi) { - _ROFstInfo = rofstinfo; - _ROFst = null; - // docversion will be null if we're working with an ro.fst that is not currently connected - // to a docversion. One example of this is when updating ro.fst and comparing the original - // with the new to find differences. The docversioninfo is only used to get unit/master - // slave info, thus is not needed to compare the raw values. - _MyDocVersionInfo = dvi;//==null?null: DocVersionInfo.Get(_ROFstInfo.docVer.VersionID); - ParseIntoDictionary(rofstinfo.ROLookup); - } - public ROFSTLookup(string filePath) - { - _ROFstInfo = null; - _ROFst = null; - _MyDocVersionInfo = null; - FileInfo rofstFile = new FileInfo(filePath); - FileStream fs = rofstFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - byte[] buf = new byte[rofstFile.Length]; - fs.Read(buf, 0, buf.Length); - fs.Close(); - ParseIntoDictionary(buf); - } - #endregion - #region PropertiesAndData - public roHdr myHdr; - private int TableID; - private Dictionary dicRos; - // private Dictionary dicRosIntIDs; - not used - private Dictionary dicRoDBs; - public void Reset() - { - dicRos = null; - //dicRosIntIDs = null; - dicRoDBs = null; - } - #endregion - #region AppSupport - public void Close() - { - // remove the dictionary - //if (dicRosIntIDs != null)dicRosIntIDs.Clear(); - //dicRosIntIDs = null; - if (dicRos != null)dicRos.Clear(); - dicRos = null; - if (dicRoDBs != null) dicRoDBs.Clear(); - dicRoDBs = null; - } - //private Dictionary _dicROAPIDLookup; - //public string GetAccPageID(string roid) - //{ - // if(_dicROAPIDLookup==null) - // { - // _dicROAPIDLookup = new Dictionary(); - // if (_dicROAPID == null) - // BuildROAPIDDictionary(); - // foreach (string appid in _dicROAPID.Keys) - // _dicROAPIDLookup.Add(_dicROAPID[appid].roid,appid); - // } - // String roidkey = roid.Substring(0, 12).ToUpper(); - // if(_dicROAPIDLookup.ContainsKey(roidkey)) - // return _dicROAPIDLookup[roidkey]; - // return null; - //} - public List GetValueDifferences(ROFSTLookup origROFst, ref List delList) - { - // use this list to see what differences are between it and the original - List modList = new List(); - // assume each rofstlookup has a parsed dictionary - foreach (string key in origROFst.dicRos.Keys) + _rofstID = rofstID; + MyDocVersionInfo = dvi; + + if (!RofstDataExists(rofstID)) { - string cvalue = null; - string ovalue = origROFst.dicRos[key].value; - if (dicRos.ContainsKey(key)) - cvalue = dicRos[key].value; - if (cvalue == null && cvalue != ovalue) - delList.Add(key); - else if (cvalue != ovalue) + Load(rofstID); + } + } + + public ROFSTLookup(int rofstID) + { + _rofstID = rofstID; + MyDocVersionInfo = null; + + if (!RofstDataExists(rofstID)) + { + Load(rofstID); + } + } + + #endregion + + #region Public Methods + + #region (RO Info) + + public ROFSTLookup.rochild GetRoChild12(string ROID16, bool loadChildren = false, bool loadAllChildren = false) + { + string ROID = (ROID16.Length < 12) ? ROID16 : ROID16.Substring(0, 12); + + ROFSTLookup.rochild rc = RofstDataGetChildByRoid(_rofstID, ROID, loadChildren, loadAllChildren); + + if (rc.ID <= 0 && ROID16.Length == 4) + { + rc.title = GetRODatabaseTitle(GetRODatabaseTitleIndex(ROID16)); + } + + return rc; + } + + public ROFSTLookup.rochild GetRoChild(string ROID, bool loadChildren = false, bool loadAllChildren = false) + { + ROFSTLookup.rochild rc = new ROFSTLookup.rochild() { ID = -1 }; + + if (ROID.StartsWith("FFFF")) + { + rc.ID = 0; + rc.ParentID = 0; + rc.roid = ROID; + rc.type = 1; + rc.value = GetRoValue(ROID); + + if (ROID == "FFFF00000001") rc.appid = "U-Number"; + else if (ROID == "FFFF00000002") rc.appid = "U-Other Number"; + else if (ROID == "FFFF00000003") rc.appid = "U-Text"; + else if (ROID == "FFFF00000004") rc.appid = "U-Other Text"; + else if (ROID == "FFFF00000005") rc.appid = "U-ID"; + else if (ROID == "FFFF00000006") rc.appid = "U-Other ID"; + else if (ROID == "FFFF00000007") rc.appid = "U-Name"; + else if (ROID == "FFFF00000008") rc.appid = "U-Other Name"; + else rc.appid = "U-Unknown"; + } + else + { + rc = GetRoChild12(ROID, loadChildren, loadAllChildren); + + if (rc.children != null && rc.children.Length > 0) { - // Value Change - modList.Add(key); - //Console.WriteLine("RO{0}\t\"{1}\"\t\"{2}\"", key, cvalue, ovalue); + foreach (ROFSTLookup.rochild c in rc.children) + { + if (c.roid.ToUpper() == ROID.ToUpper()) + { + return c; + } + } } } - return modList; + + return rc; } - //public static ROImageInfo Get(RODbInfo rodbinfo, string filename) - //{ - // if (rodbinfo.RODbROImageCount != 0) - // { - // foreach (ROImageInfo ri in rodbinfo.RODbROImages) - // { - // if (ri.FileName == filename) return ri; - // } - // } - // return null; - //} - + + public string GetRoValue(string ROID16) + { + // This only gets rochild values, not groups + string ROID = ROID16.Substring(0, 12); + + if (ROID.StartsWith("FFFF")) + { + DocVersionConfig dvc = _myDocVersionInfo.DocVersionConfig; + + if (ROID == "FFFF00000001") return dvc.Unit_Number; + if (ROID == "FFFF00000002") return dvc.Other_Unit_Number; + if (ROID == "FFFF00000003") return dvc.Unit_Text; + if (ROID == "FFFF00000004") return dvc.Other_Unit_Text; + if (ROID == "FFFF00000005") return dvc.Unit_ID; + if (ROID == "FFFF00000006") return dvc.Other_Unit_ID; + if (ROID == "FFFF00000007") return dvc.Unit_Name; + if (ROID == "FFFF00000008") return dvc.Other_Unit_Name; + + } + + ROFSTLookup.rochild rc = GetRoChild12(ROID); + + if (rc.ID > 0) + { + if (!string.IsNullOrEmpty(rc.value)) + { + return FixUnitROs(GetParentChildROValue(rc)); + } + + if (rc.children != null && rc.children.Length > 0) + { + foreach (ROFSTLookup.rochild c in rc.children) + { + if (c.roid.ToUpper() == ROID16.ToUpper() || (c.roid.EndsWith("0041") && ROID16.EndsWith("0000"))) + { + return FixUnitROs(GetParentChildROValue(c) ?? "?"); + } + } + + // if there isn't a specific match for multi-return values, default to the first child. + return FixUnitROs(GetParentChildROValue(rc.children[0]) ?? "?"); + } + } + + return "?"; + } + + public string GetParentChildROValue(ROFSTLookup.rochild roc) + { + // C2021-026 Get the child RO value if it exists, otherwise to the default (parent) RO value + // C2022-001 new logic to handle new format of Parent/Child RO.FST + // The RO.FST will not have a specific child value if that child value is the same as the default value + + string roval = roc.value; + + // B2021-093 Don't look for child RO values if "roval" is null + if (roval == null) return null; + + // B2022-020 remove a un-needed question mark that was in the search criteria "(" + // B2022-050 change the search string from "(" to "" to handle when RO values have less then sign + MatchCollection mm = Regex.Matches(roval, ""); + + // C2022-014 commented write to error log. Keep for debugging purposes. + //if (mm.Count == 0) // B2022-020 will now write in error log if there is a problem + // _MyLog.WarnFormat("Parent/Child Values not parsable for \r\nItemId={0}\r\nROValue={1} ",MyDocVersionInfo.ItemID,roval); + + StringBuilder sb = new StringBuilder(); + int lastIndex = 0; + + // Get selected child Idx + int selChldIdx = this.SelectedSlave; + + // Get Selected Child Value + foreach (Match m in mm) + { + sb.Append(roval.Substring(lastIndex, m.Index - lastIndex)); + + string aplString = m.Value; + string chldValStr = string.Format("UnitIdx={0} Value=", selChldIdx); + int offsetIdx = aplString.IndexOf(chldValStr); + int nextIDX = -1; + + if (offsetIdx == -1) + { + offsetIdx = aplString.IndexOf("DefaultVal=") + 11; + } + else + { + offsetIdx += chldValStr.Length; + } + + nextIDX = aplString.IndexOf(",UnitIdx", offsetIdx); + if (nextIDX == -1) nextIDX = aplString.IndexOf(" /APL>"); + sb.Append(aplString.Substring(offsetIdx, nextIDX - offsetIdx)); + + lastIndex = m.Index + m.Length; + } + + // B2022-018 append any remaining text + if (lastIndex < roval.Length) + { + sb.Append(roval.Substring(lastIndex)); + } + + return sb.ToString(); + } + + public List GetROReturnValue(string roval) + { + _lstRoValues = new List(); + _multiRoValues = new List(); + _dicRoVars = new Dictionary(); + + string tmp = ProcessRO(_myDocVersionInfo == null ? roval : _myDocVersionInfo.ProcessDocVersionSpecificInfo(roval), false); + + if (!string.IsNullOrEmpty(tmp) && _lstRoValues.Count == 0) // was not a multiple return value + { + _lstRoValues.Add(tmp); + } + + return _lstRoValues; + } + public string GetTranslatedRoValue(string ROID16, bool DoCaret, bool DoDOSSuperSubScript) { string retval = GetRoValue(ROID16); retval = ReplaceUnicode(retval, DoCaret); retval = ConvertFortranFormatToScienctificNotation(retval); + // B2019-037 handle the super an sub scripts after getting the RO value from the FST // the corrected RO text is added to the display text in the link info if (DoDOSSuperSubScript) @@ -253,54 +421,1362 @@ namespace VEPROMS.CSLA.Library retval = Regex.Replace(retval, "[#](.*?)[#]", "\\up2 $1\\up0 ");// Superscript retval = Regex.Replace(retval, "[~](.*?)[~]", "\\dn2 $1\\up0 ");// Subscript } + return retval.Replace("\r\n", @"\par "); } + + public Dictionary Search(string value, int searchTypeID, int? maxNumRecords = null) + { + if (string.IsNullOrEmpty(value)) + return null; + + return RofstDataSearch(_rofstID, value, searchTypeID, maxNumRecords); + } + + public ROFSTLookup.rochild[] GetRoChildrenByID(int id, int dbiID, bool loadChildren = false, bool loadAllChildren = false) + { + return RofstDataGetChildrenByID(_rofstID, dbiID, id, loadChildren, loadAllChildren); + } + + public ROFSTLookup.rochild[] GetRoChildrenByRoid(string roid, bool loadChildren = false, bool loadAllChildren = false) + { + return RofstDataGetChildrenByRoid(_rofstID, roid, loadChildren, loadAllChildren); + } + + public ROFSTLookup.rochild[] GetRoChildrenByType(E_ROValueType valueTypes, bool loadChildren = false, bool loadAllChildren = false) + { + return RofstDataGetRoChildrenByType(_rofstID, valueTypes, loadChildren, loadAllChildren); + } + + public List GetValueDifferences(int originalRofstID, ref List delList) + { + return RofstDataGetValueDifferences(originalRofstID, _rofstID, ref delList); + } + + public List GetROTitleAndGroupPath(string ROID, bool reportMissingROs, bool convertCaretToDelta) + { + // Return the RO Title in a list of strings. The last item in the list is the actual RO title, + // the items preceding it are the titles of the groups and sub-groups containing the RO + + List titlePath = new List(); + + ROFSTLookup.rochild roc = GetRoChild12(ROID); + + if (roc.appid != null) + { + string tmp = roc.title; + + if (roc.appid != string.Empty && roc.title.Contains(roc.appid)) + { + tmp = roc.title.Replace(roc.appid, "").Trim(); + } + + tmp = string.Format("[{0}] {1}", roc.appid, tmp); + tmp = tmp.Replace("`", "\u00B0"); //degree + tmp = tmp.Replace("\xF8", "\u00B0"); //degree + if (convertCaretToDelta) tmp = tmp.Replace("^", "\u0394"); // delta + + titlePath.Add(tmp); + + do + { + string parent = ROID.Substring(0, 4) + string.Format("{0:X8}", roc.ParentID); + roc = GetRoChild12(parent); + if (roc.ID > 0) titlePath.Add(roc.title.Trim()); + + } while (roc.ID > 0); + + titlePath.Reverse(); + } + else if (reportMissingROs) // Missing RO, put a message with the ROID on the report... + { + titlePath.Add(string.Format("Missing RO for ROID {0}", ROID)); + } + + return titlePath; + } + + public string GetROTitle(string ROID) + { + StringBuilder sb = new StringBuilder(); + + ROFSTLookup.rochild rc = GetRoChild12(ROID); + if (rc.value == null) rc = GetRoChild(ROID); + + // B2020-125: View of Consistency check report displaying error message and crashing. And also in 'else' check for null + if (rc.ID == -1) + { + sb.Append("Could not find RO data"); + } + else + { + string tmp = string.Empty; + if (!string.IsNullOrEmpty(rc.title)) tmp = rc.title; + if (!string.IsNullOrEmpty(rc.appid)) tmp = tmp.Replace(rc.appid, string.Empty); + if (!string.IsNullOrEmpty(rc.value)) tmp = tmp.Replace(rc.value, string.Empty); + sb.Append(tmp.Trim()); + } + + do + { + string parentROID = ROID.Substring(0, 4) + string.Format("{0:X8}", rc.ParentID); + rc = GetRoChild12(parentROID); + if (rc.ID > 0) sb.Insert(0, rc.title + " - "); + + } while (rc.ID > 0); + + return sb.ToString(); + } + + public DateTime GetRoFSTdts() + { + return GetRofstDtsByID(_rofstID); + } + + public static byte[] GetRofstLookupBytes(int rofstID) + { + return RofstDataGetRofstLookupBytes(rofstID); + } + + #endregion + + #region (RO Database Info) + + public int GetRODatabaseTitleIndex(string roid) + { + return Convert.ToInt32("0x" + roid.Substring(0, 4), 16); + } + + public string GetRODatabaseTitle(int idx) + { + ROFSTLookup.rodbi rd = RofstDataGetDatabaseByID(_rofstID, idx); + return (!string.IsNullOrEmpty(rd.dbiTitle) ? rd.dbiTitle : "RO Database Title Not Found"); + } + + public ROFSTLookup.rodbi GetRODatabase(string roid, bool loadChildren = false, bool loadAllChildren = false) + { + int idx = GetRODatabaseTitleIndex(roid); + ROFSTLookup.rodbi rd = RofstDataGetDatabaseByID(_rofstID, idx, loadChildren, loadAllChildren); + return (rd.dbiID > 0) ? rd : RofstDataGetDatabaseByID(_rofstID, 1, loadChildren, loadAllChildren); + } + + public ROFSTLookup.rodbi[] GetRODatabaseList(bool loadChildren = false, bool loadAllChildren = false) + { + return RofstDataGetDatabases(_rofstID, loadChildren, loadAllChildren); + } + + #endregion + + #region (RO Info By AccPageID) + + public string GetROValueByAccPagID(string accPageID, string spDefault, string igDefault) + { + ROFSTLookup.rochild? child = GetROChildByAccPageID(accPageID, spDefault, igDefault); + if (child == null) return null; + return GetParentChildROValue((ROFSTLookup.rochild)child); // C2021-026 get the P/C value if it exists, otherwise get the non-P/C value + } + + public int? GetROTypeByAccPagID(string accPageID, string spDefault, string igDefault) + { + ROFSTLookup.rochild? child = GetROChildByAccPageID(accPageID, spDefault, igDefault); + if (child == null) return null; + return ((ROFSTLookup.rochild)child).type; + } + + public string GetROIDByAccPagID(string accPageID, string spDefault, string igDefault) + { + ROFSTLookup.rochild? child = GetROChildByAccPageID(accPageID, spDefault, igDefault); + if (child == null) return null; + return ((ROFSTLookup.rochild)child).roid; + } + + public ROFSTLookup.rochild? GetROChildByAccPageID(string accPageID, string spDefault, string igDefault) + { + ROFSTLookup.rochild? child = GetRoChildByAccPagID(accPageID, spDefault, igDefault); + + if (child == null) + { + if (Regex.IsMatch(accPageID, @".*\.[A-Z]")) + { + string accpage = accPageID.Substring(0, accPageID.Length - 3); + int index = accPageID.Substring(accPageID.Length - 2, 1)[0] - 'A'; + child = GetRoChildByAccPagID(accpage.TrimStart("<".ToCharArray()), spDefault, igDefault); + + if (child == null) return null; + + if (((ROFSTLookup.rochild)child).children != null && ((ROFSTLookup.rochild)child).children.Length > 0 && ((ROFSTLookup.rochild)child).children.Length > index) + { + return ((ROFSTLookup.rochild)child).children[index]; + } + } + + return null; + } + + if (((ROFSTLookup.rochild)child).children != null && ((ROFSTLookup.rochild)child).children.Length > 0) + return ((ROFSTLookup.rochild)child).children[0]; + + return (ROFSTLookup.rochild)child; + } + + public ROFSTLookup.rochild? GetRoChildByAccPagID(string accPageID, string spDefault, string igDefault) + { + accPageID = accPageID.Replace("".ToCharArray()); // String < and > + string key = FormatKey(accPageID); + + ROFSTLookup.rochild rc = RofstDataGetChildByAccPageID(_rofstID, key); + if (rc.ID > 0) return rc; + + return null; + } + + #endregion + + #endregion + + #region Private Methods + + #region (Database Calls) + + private bool RofstDataExists(int rofstID) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataExists"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + + return Convert.ToBoolean(cmd.ExecuteScalar()); + } + } + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataExists", ex); + } + } + + private static byte[] RofstDataGetRofstLookupBytes(int rofstID) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetRofstByID"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@IncludeRoLookup", SqlDbType.Bit)).Value = 1; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + if (dr.Read()) return (byte[])dr.GetValue("ROLookup"); + } + } + } + + return null; + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetRofstByID", ex); + } + } + + private DateTime GetRofstDtsByID(int rofstID) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetRofstByID"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@IncludeRoLookup", SqlDbType.Bit)).Value = 0; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + if (dr.Read()) return (DateTime)dr.GetValue("DTS"); + } + } + } + + return new DateTime(); + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetRofstByID", ex); + } + } + + private void RofstHeaderInsert(int rofstID, int hSize, int hMonth, int hDay, int hcYear, int hcMonth, int hcDay, int hcHour, int hcMin, int hcSec, int hcHund, string userID) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstHeaderInsert"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@hSize", SqlDbType.Int)).Value = hSize; + cmd.Parameters.Add(new SqlParameter("@hMonth", SqlDbType.Int)).Value = hMonth; + cmd.Parameters.Add(new SqlParameter("@hDay", SqlDbType.Int)).Value = hDay; + cmd.Parameters.Add(new SqlParameter("@hcYear", SqlDbType.Int)).Value = hcYear; + cmd.Parameters.Add(new SqlParameter("@hcMonth", SqlDbType.Int)).Value = hcMonth; + cmd.Parameters.Add(new SqlParameter("@hcDay", SqlDbType.Int)).Value = hcDay; + cmd.Parameters.Add(new SqlParameter("@hcHour", SqlDbType.Int)).Value = hcHour; + cmd.Parameters.Add(new SqlParameter("@hcMin", SqlDbType.Int)).Value = hcMin; + cmd.Parameters.Add(new SqlParameter("@hcSec", SqlDbType.Int)).Value = hcSec; + cmd.Parameters.Add(new SqlParameter("@hcHund", SqlDbType.Int)).Value = hcHund; + cmd.Parameters.Add(new SqlParameter("@userID", SqlDbType.VarChar)).Value = userID; + + cmd.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstHeaderInsert", ex); + } + } + + private void RofstDatabaseInsert(int rofstID, int dbiID, int dbiType, int dbiAW, string dbiTitle, string dbiAP, int id, int parentID) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDatabaseInsert"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@dbiID", SqlDbType.Int)).Value = dbiID; + cmd.Parameters.Add(new SqlParameter("@dbiType", SqlDbType.Int)).Value = dbiType; + cmd.Parameters.Add(new SqlParameter("@dbiAW", SqlDbType.Int)).Value = dbiAW; + cmd.Parameters.Add(new SqlParameter("@dbiTitle", SqlDbType.VarChar)).Value = dbiTitle; + cmd.Parameters.Add(new SqlParameter("@dbiAP", SqlDbType.VarChar)).Value = dbiAP; + cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = id; + cmd.Parameters.Add(new SqlParameter("@ParentID", SqlDbType.Int)).Value = parentID; + + cmd.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDatabaseInsert", ex); + } + } + + private void RofstChildInsert(int rofstID, int id, int parentID, int dbiID, int type, string title, string roid, string appid, string value) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstChildInsert"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = id; + cmd.Parameters.Add(new SqlParameter("@ParentID", SqlDbType.Int)).Value = parentID; + cmd.Parameters.Add(new SqlParameter("@dbiID", SqlDbType.Int)).Value = dbiID; + cmd.Parameters.Add(new SqlParameter("@type", SqlDbType.Int)).Value = type; + cmd.Parameters.Add(new SqlParameter("@title", SqlDbType.VarChar)).Value = title; + cmd.Parameters.Add(new SqlParameter("@roid", SqlDbType.VarChar)).Value = roid; + + if (!string.IsNullOrEmpty(appid)) + cmd.Parameters.Add(new SqlParameter("@appid", SqlDbType.VarChar)).Value = appid; + if (!string.IsNullOrEmpty(value)) + cmd.Parameters.Add(new SqlParameter("@value", SqlDbType.VarChar)).Value = value; + + cmd.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstChildInsert", ex); + } + } + + private ROFSTLookup.rodbi RofstDataGetDatabaseByID(int rofstID, int dbiID, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetDatabaseByID"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@dbiID", SqlDbType.Int)).Value = dbiID; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + if (dr.Read()) + { + return ConvertToRodbiObject(dr, loadChildren, loadAllChildren); + } + } + } + } + + return new ROFSTLookup.rodbi(); + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetDatabaseByID", ex); + } + } + + private ROFSTLookup.rodbi[] RofstDataGetDatabases(int rofstID, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + List dbs = new List(); + + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetDatabases"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + while (dr.Read()) + { + dbs.Add(ConvertToRodbiObject(dr, loadChildren, loadAllChildren)); + } + } + } + } + + return dbs.ToArray(); + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetDatabases", ex); + } + } + + private ROFSTLookup.rochild[] RofstDataGetChildrenByID(int rofstID, int dbiID, int id, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + List lst = new List(); + + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetChildrenByID"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@DbiID", SqlDbType.Int)).Value = dbiID; + cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = id; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + while (dr.Read()) + { + lst.Add(ConvertToRochildObject(dr, loadChildren, loadAllChildren)); + } + } + } + } + + return lst.ToArray(); + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetChildrenByID", ex); + } + } + + private ROFSTLookup.rochild RofstDataGetChildByRoid(int rofstID, string roid, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetChildByRoid"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@Roid", SqlDbType.VarChar)).Value = roid; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + if (dr.Read()) + { + return ConvertToRochildObject(dr, loadChildren, loadAllChildren); + } + } + } + } + + return new ROFSTLookup.rochild() { ID = -1 }; + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetChildByRoid", ex); + } + } + + private ROFSTLookup.rochild RofstDataGetChildByAccPageID(int rofstID, string accPageID, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetChildByAccPageID"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@AccPageID", SqlDbType.VarChar)).Value = accPageID; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + if (dr.Read()) + { + return ConvertToRochildObject(dr, loadChildren, loadAllChildren); + } + } + } + } + + return new ROFSTLookup.rochild() { ID = -1 }; + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetChildByAccPageID", ex); + } + } + + private ROFSTLookup.rochild[] RofstDataGetChildrenByRoid(int rofstID, string roid, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + List lst = new List(); + + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetChildrenByRoid"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@Roid", SqlDbType.VarChar)).Value = roid; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + while (dr.Read()) + { + lst.Add(ConvertToRochildObject(dr, loadChildren, loadAllChildren)); + } + } + } + } + + return lst.ToArray(); + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetChildrenByRoid", ex); + } + } + + private List RofstDataGetValueDifferences(int originalRofstID, int currentRofstID, ref List delList) + { + // use this list to see what differences are between the current and the original + List modList = new List(); + List roidList = new List(); + + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetValueDifferences"; + + cmd.Parameters.Add(new SqlParameter("@OriginalRofstID", SqlDbType.Int)).Value = originalRofstID; + cmd.Parameters.Add(new SqlParameter("@CurrentRofstID", SqlDbType.Int)).Value = currentRofstID; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + while (dr.Read()) + { + roidList.Add((string)dr.GetValue("Roid")); + } + } + } + } + + ROFSTLookup.rochild originalRoChild; + ROFSTLookup.rochild currentRoChild; + + Dictionary originalRos = new Dictionary(); + Dictionary currentRos = new Dictionary(); + + foreach (string roid in roidList) + { + originalRoChild = RofstDataGetChildByRoid(originalRofstID, roid); + originalRos.Add(originalRoChild.roid, originalRoChild.value); + + if (originalRoChild.children != null && originalRoChild.children.Length > 0) + { + foreach (ROFSTLookup.rochild roc in originalRoChild.children) + { + originalRos.Add(roc.roid, roc.value); + } + } + + currentRoChild = RofstDataGetChildByRoid(currentRofstID, roid); + currentRos.Add(currentRoChild.roid, currentRoChild.value); + + if (currentRoChild.children != null && currentRoChild.children.Length > 0) + { + foreach (ROFSTLookup.rochild roc in currentRoChild.children) + { + currentRos.Add(roc.roid, roc.value); + } + } + } + + string cvalue = string.Empty; + string ovalue = string.Empty; + + foreach (string key in originalRos.Keys) + { + cvalue = null; + ovalue = originalRos[key]; + + if (currentRos.ContainsKey(key)) + cvalue = currentRos[key]; + + if (cvalue == null && cvalue != ovalue) + delList.Add(key); + else if (cvalue != ovalue) + modList.Add(key); + } + + return modList; + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetValueDifferences", ex); + } + } + + private Dictionary RofstDataSearch(int rofstID, string value, int searchTypeID, int? maxNumRecords) + { + Dictionary dic = new Dictionary(); + + if (string.IsNullOrEmpty(value)) + return dic; + + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataSearch"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@Value", SqlDbType.VarChar)).Value = value; + cmd.Parameters.Add(new SqlParameter("@SearchTypeID", SqlDbType.Int)).Value = searchTypeID; + + if (maxNumRecords != null) + cmd.Parameters.Add(new SqlParameter("@MaxNumOfRecords", SqlDbType.Int)).Value = (int)maxNumRecords; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + while (dr.Read()) + { + dic.Add((string)dr.GetValue("roid"), (string)dr.GetValue("value")); + } + } + } + } + + return dic; + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataSearch", ex); + } + } + + private ROFSTLookup.rochild RofstDataGetChildByID(int rofstID, int dbiID, int id, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetChildByID"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@DbiID", SqlDbType.Int)).Value = dbiID; + cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)).Value = id; + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + if (dr.Read()) + { + return ConvertToRochildObject(dr, loadChildren, loadAllChildren); + } + } + } + } + + return new ROFSTLookup.rochild() { ID = -1 }; + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.vesp_RofstDataGetChildByID", ex); + } + } + + private ROFSTLookup.rochild[] RofstDataGetRoChildrenByType(int rofstID, E_ROValueType valueTypes, bool loadChildren = false, bool loadAllChildren = false) + { + try + { + List lst = new List(); + + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = cn.CreateCommand()) + { + cmd.CommandTimeout = Database.DefaultTimeout; + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandText = "vesp_RofstDataGetChildrenByType"; + + cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; + cmd.Parameters.Add(new SqlParameter("@ValueTypes", SqlDbType.VarChar)).Value = valueTypes.ToCommaDelimString(); + + using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader())) + { + while (dr.Read()) + { + lst.Add(ConvertToRochildObject(dr, loadChildren, loadAllChildren)); + } + } + } + } + + return lst.ToArray(); + } + catch (Exception ex) + { + throw new DbCslaException("RofstData.RofstDataGetRoChildrenByType", ex); + } + } + + #endregion + + #region (Parse/Load) + + private ROFSTLookup.roHdr ConvertFst2Objects(byte[] ab) + { + ROFSTLookup.roHdr roh = new ROFSTLookup.roHdr(); + + roh.hSize = BitConverter.ToInt32(ab, 0); + roh.hYear = BitConverter.ToInt16(ab, 4); + roh.hMonth = ab[6]; + roh.hDay = ab[7]; + roh.hcYear = BitConverter.ToInt16(ab, 8); + roh.hcMonth = ab[10]; + roh.hcDay = ab[11]; + roh.hcHour = ab[12]; + roh.hcMin = ab[13]; + roh.hcSec = ab[14]; + roh.hcHund = ab[15]; + + int hdrOffset = BitConverter.ToInt32(ab, 16); + int dbs = BitConverter.ToInt16(ab, hdrOffset + 4); + + roh.myDbs = new ROFSTLookup.rodbi[dbs]; + + for (int i = 0; i < dbs; i++) + { + int offset = hdrOffset + 6 + (i * 30); + + roh.myDbs[i].dbiID = BitConverter.ToInt16(ab, offset + 0); + int tableID = roh.myDbs[i].dbiID; + + roh.myDbs[i].dbiType = BitConverter.ToInt16(ab, offset + 2); + roh.myDbs[i].dbiAW = BitConverter.ToInt16(ab, offset + 4); + + int iPtr = BitConverter.ToInt32(ab, offset + 22) + hdrOffset + 6; + roh.myDbs[i].dbiTitle = Encoding.Default.GetString(ab, iPtr, StringLength(ab, iPtr)); + + iPtr = BitConverter.ToInt32(ab, offset + 26) + hdrOffset + 6; + roh.myDbs[i].dbiAP = Encoding.Default.GetString(ab, iPtr, StringLength(ab, iPtr)); + + ROFSTLookup.rogrp tmp = LoadGroup(ab, BitConverter.ToInt32(ab, offset + 6), tableID); + + roh.myDbs[i].ID = tmp.ID; + roh.myDbs[i].children = tmp.children; + } + + return roh; + } + + private ROFSTLookup.rogrp LoadGroup(byte[] ab, int offset, int tableID) + { + ROFSTLookup.rogrp myGrp = new ROFSTLookup.rogrp(); + + myGrp.ID = BitConverter.ToInt32(ab, offset); + myGrp.ParentID = BitConverter.ToInt32(ab, offset + 4); + + int numChildren = BitConverter.ToInt16(ab, offset + 8); + + if (numChildren > 0) + { + myGrp.children = new ROFSTLookup.rochild[numChildren]; + + int myOffset = offset + 10; + + for (int i = 0; i < myGrp.children.Length; i++) + { + ROFSTLookup.rochild tmp = new ROFSTLookup.rochild(); + + int childOffset = BitConverter.ToInt32(ab, myOffset); + tmp.type = BitConverter.ToInt16(ab, myOffset + 4); + + int slen = StringLength(ab, myOffset + 6); + tmp.title = Encoding.Default.GetString(ab, myOffset + 6, slen); + + myOffset += (7 + slen); + + ROFSTLookup.rogrp tmpg = LoadGroup(ab, childOffset, tableID); + + //MultipleReturnValuesInheritType(ref tmpg, tmp.type); + + tmp.ID = tmpg.ID; + tmp.ParentID = tmpg.ParentID; + tmp.value = tmpg.value; + tmp.appid = tmpg.appid; + tmp.roid = tableID.ToString("X4") + tmp.ID.ToString("X8"); + tmp.children = tmpg.children; + + int j; + + for (j = i - 1; j >= 0 && tmp.ID < myGrp.children[j].ID; j--) + { + myGrp.children[j + 1] = myGrp.children[j]; + } + + myGrp.children[j + 1] = tmp; + } + } + else + { + int slen = StringLength(ab, offset + 12); + myGrp.value = Encoding.Default.GetString(ab, offset + 12, slen); + + //ProcessROReturnValue(ref myGrp, Encoding.Default.GetString(ab, offset + 12, slen), tableID, dvi); + + int slen2 = StringLength(ab, offset + 13 + slen); + myGrp.appid = Encoding.Default.GetString(ab, offset + 13 + slen, slen2); + } + + return myGrp; + } + + private void Load(int rofstID) + { + //Get Original ROLookup Bytes + byte[] bytes = RofstDataGetRofstLookupBytes(rofstID); + + //Convert Bytes to Objects + ROFSTLookup.roHdr roh = ConvertFst2Objects(bytes); + + //Save FstObjects to Database + string userID = "System"; + + //Insert Rofst Header + RofstHeaderInsert(rofstID, roh.hSize, roh.hMonth, roh.hDay, roh.hcYear, roh.hcMonth, + roh.hcDay, roh.hcHour, roh.hcMin, roh.hcSec, roh.hcHund, userID); + + for (int i = 0; i < roh.myDbs.Length; i++) + { + ROFSTLookup.rodbi rodbi = roh.myDbs[i]; + + //Insert Rofst Database + RofstDatabaseInsert(rofstID, rodbi.dbiID, rodbi.dbiType, rodbi.dbiAW, + rodbi.dbiTitle, rodbi.dbiAP, rodbi.ID, rodbi.ParentID); + + if (rodbi.children != null && rodbi.children.Length > 0) + { + for (int j = 0; j < rodbi.children.Length; j++) + { + //Insert Rofst Child + LoadChild(rofstID, rodbi.dbiID, rodbi.children[j]); + } + } + } + } + + private void LoadChild(int rofstID, int dbiID, ROFSTLookup.rochild child) + { + //Insert Rofst Child + RofstChildInsert(rofstID, child.ID, child.ParentID, dbiID, child.type, child.title, child.roid, child.appid, child.value); + + if (child.children != null && child.children.Length > 0) + { + for (int i = 0; i < child.children.Length; i++) + { + //Insert Rofst Child + LoadChild(rofstID, dbiID, child.children[i]); + } + } + } + + #endregion + + #region (Convert To Objects) + + private ROFSTLookup.roHdr ConvertToRoHdrObject(SafeDataReader dr, bool loadChildren) + { + ROFSTLookup.roHdr rh = new ROFSTLookup.roHdr(); + + rh.hSize = (int)dr.GetValue("hSize"); + rh.hYear = (int)dr.GetValue("hYear"); + rh.hMonth = (byte)dr.GetValue("hMonth"); + rh.hDay = (byte)dr.GetValue("hDay"); + rh.hcYear = (int)dr.GetValue("hcYear"); + rh.hcMonth = (byte)dr.GetValue("hcMonth"); + rh.hcDay = (byte)dr.GetValue("hcDay"); + rh.hcHour = (byte)dr.GetValue("hcHour"); + rh.hcMin = (byte)dr.GetValue("hcMin"); + rh.hcSec = (byte)dr.GetValue("hcSec"); + rh.hcHund = (byte)dr.GetValue("hcHund"); + + if (loadChildren) + { + rh.myDbs = RofstDataGetDatabases(_rofstID); + } + + return rh; + } + + private ROFSTLookup.rodbi ConvertToRodbiObject(SafeDataReader dr, bool loadChildren, bool loadAllChildren) + { + ROFSTLookup.rodbi rd = new ROFSTLookup.rodbi(); + + rd.dbiID = (int)dr.GetValue("dbiID"); + rd.dbiType = (int)dr.GetValue("dbiType"); + rd.dbiAW = (int)dr.GetValue("dbiAW"); + rd.dbiAP = (string)dr.GetValue("dbiAP"); + rd.dbiTitle = (string)dr.GetValue("dbiTitle"); + rd.ID = (int)dr.GetValue("ID"); + rd.ParentID = (int)dr.GetValue("ParentID"); + + if (loadChildren || loadAllChildren) + { + rd.children = RofstDataGetChildrenByID(_rofstID, rd.dbiID, rd.ID, loadAllChildren); + } + + return rd; + } + + private ROFSTLookup.rochild ConvertToRochildObject(SafeDataReader dr, bool loadChildren, bool loadAllChildren) + { + ROFSTLookup.rochild rc = new ROFSTLookup.rochild(); + + rc.ID = (int)dr.GetValue("ID"); + rc.ParentID = (int)dr.GetValue("ParentID"); + rc.type = (int)dr.GetValue("type"); + rc.title = (string)dr.GetValue("title"); + rc.roid = (string)dr.GetValue("roid"); + + if (!string.IsNullOrEmpty((string)dr.GetValue("appid"))) rc.appid = (string)dr.GetValue("appid"); + + if (!string.IsNullOrEmpty((string)dr.GetValue("value"))) + { + rc.value = (string)dr.GetValue("value"); + ProcessROReturnValue(ref rc, rc.value, GetRODatabaseTitleIndex(rc.roid)); + } + + if (loadChildren || loadAllChildren) + { + rc.children = RofstDataGetChildrenByRoid(_rofstID, rc.roid, loadAllChildren); + } + + return rc; + } + + #endregion + + #region (RO Values) + + private void ProcessROReturnValue(ref ROFSTLookup.rochild child, string rawvalue, int tableID) + { + // This function will take the raw RO return value and resolve any macros, conditionals, + // and generate the return value or a list of multiple return values. + List lstValues = GetROReturnValue(rawvalue); + + if (lstValues.Count > 1) // Multiple Return Values + { + child.children = new ROFSTLookup.rochild[lstValues.Count]; + + for (int i = 0; i < lstValues.Count; i++) + { + string tsts = Convert.ToInt32(_multiRoValues[i][0]).ToString("X4"); + child.children[i].value = lstValues[i].Replace("\xFF", "\xa0"); + child.children[i].roid = tableID.ToString("X4") + child.ID.ToString("X8") + tsts; + child.children[i].type = child.type; // Multiple return value inherit type from parent + child.children[i].title = lstValues[i].Replace("\xFF", "\xa0"); + child.children[i].appid = child.appid; + } + + child.value = null; + } + else + { + child.value = lstValues[0]; + } + + _lstRoValues.Clear(); + _multiRoValues.Clear(); + + return; + } + + private string ProcessRO(string roval, bool multiRtnVal) + { + string str = roval; + string rtnstr = ""; + int len = roval.Length; + + while (len > 0) + { + int ptr = NextDelimiter("{", str); + + if (ptr == -1) + { + rtnstr += str; // add remaining text + len = 0; // break out of while loop + } + else + { + int cnt = ptr; + + if (cnt > 0) + { + // add text + rtnstr += str.Substring(0, cnt); + len -= cnt; + str = str.Substring(ptr); + } + + ptr = MatchingBrace(str) + 1; + cnt = ptr; + + bool nfnd = false; + string pbstr = ProcessBrace(str.Substring(1, cnt - 2), cnt - 2, ref nfnd, multiRtnVal); + + if (pbstr == null) + return null; + + if (nfnd) + rtnstr += str.Substring(0, cnt); + else + rtnstr += pbstr; + + len -= cnt; + str = str.Substring(ptr); + } + } + + return ProcessMacros(rtnstr); + } + + private string ProcessBrace(string str, int l, ref bool nfnd, bool multiRtnVal) + { + string rtnstr = ""; + int nxt = NextDelimiter("{=", str); + + if (nxt == -1) // no delimiter found + { + if (_dicRoVars.ContainsKey(str)) + rtnstr = _dicRoVars[str]; + else + nfnd = true; + } + else + { + if (str[nxt] == '{') + { + if (nxt == 0) // Multiple Return Values + { + ProcessMultiReturnValues(str, l); + } + else // Conditional + { + rtnstr = ProcessConditional(str, str.Substring(nxt), nxt, str.Length - nxt - 1, multiRtnVal); + } + } + else // must be variable definition + { + // 'l' is the length up to the matching brace of the variable definition + string tmpval = ProcessRO(str.Substring(nxt + 1, l - nxt - 1), multiRtnVal); + if (string.IsNullOrEmpty(tmpval)) tmpval = " "; // nothing assigned to variable + + if (!_dicRoVars.ContainsKey(str.Substring(0, nxt))) + { + _dicRoVars.Add(str.Substring(0, nxt), tmpval); + if (nxt == 1) _multiRoValues.Add(str.Substring(0, nxt)); + } + else + { + return null; + } + + if (multiRtnVal) rtnstr = tmpval; + } + } + + return rtnstr; + } + + private void ProcessMultiReturnValues(string str, int len) + { + string tstr = (!string.IsNullOrEmpty(str)) ? str.Substring(0, len) : string.Empty; + + while (tstr.Length > 0) + { + int idx = MatchingBrace(tstr); + string tmpVal = ProcessRO(tstr.Substring(0, idx + 1), true); + if (tmpVal != null) _lstRoValues.Add(tmpVal); // duplicates get returned as null + tstr = tstr.Substring(idx + 1); + } + } + + private string ProcessConditional(string cnd, string opt, int lencnd, int lenopt, bool multiRtnVal) + { + // Evaluate Condition + string stat = (_myDocVersionInfo != null) ? _myDocVersionInfo.Evaluate(cnd, lencnd) : string.Empty; + + // if evaluation not defined then return an empty string - no matches can be made, look for match - remember default + if (stat.Length == 0) + return string.Empty; + + int ls = stat.Length; + string match = null; + string def = null; + int deflen = 0; + + while (lenopt > 0 && match == null) + { + int end = MatchingBrace(opt); + int eq = opt.IndexOf('='); + int len = end + 1; + int li = eq - 1; + int ld = len - li - 3; + + if (def == null || eq == 1) + { + def = opt.Substring(eq + 1); + deflen = ld; + } + + if (ls == li && opt.Substring(1).StartsWith(stat + "=")) + { + match = opt.Substring(eq + 1, ld); + } + + opt = opt.Substring(len); // point to the next piece + lenopt -= len; + } + + // if match process option - or process default + if (match == null) //(!match) + { + match = def.Substring(0, deflen); + } + + return ProcessRO(match, multiRtnVal); + } + + private string ProcessMacros(string str) + { + // 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 + // Note** Right now the only macro is @HSP(), where every space between the "(" and ")" will be replaced with a hard space + + if (string.IsNullOrEmpty(str)) + return str; + + string rtnstr = str; + int indx; + + while ((indx = rtnstr.ToUpper().IndexOf("@HSP(")) > -1) + { + string resstr = rtnstr.Substring(0, indx); + int endHsp = rtnstr.IndexOf(")", indx); + string tmpstr = rtnstr.Substring(indx + 5, endHsp - indx - 5); + + // B2017-012 Don't convert space to hard spaces for XY Plots. + if (!tmpstr.Contains("< 0 && idx++ < str.Length) + { + switch (str[idx]) + { + case '{': + level++; + break; + + case '}': + level--; + break; + } + } + } + + return (level != 0) ? -1 : idx; //return -1 if didn't find matching brace otherwise length including end brace + } + + private string FormatKey(string keyStr) + { + if (!string.IsNullOrEmpty(keyStr)) + { + keyStr = keyStr.ToUpper(); + keyStr = regRoKeyHigh.Replace(keyStr, "_HIGH$3"); + keyStr = regRoKeyLow.Replace(keyStr, "_LOW$3"); + } + + return keyStr; + } + private string ReplaceUnicode(string s2, bool DoCaret) { string orig = s2; - s2 = s2.Replace( @"\u160?",""); // convert hard spaces bug fix: B2016-206 - s2 = s2.Replace(@"\", @"\u9586?"); // convert backslashes to a backslash symbol - s2 = s2.Replace("", @"\u160?"); // convert hard spaces bug fix: B2016-206 - s2 = s2.Replace("`", @"\'b0"); // convert backquote to degree - left over from DOS days. + + s2 = s2.Replace(@"\u160?", ""); // convert hard spaces bug fix: B2016-206 + s2 = s2.Replace(@"\", @"\u9586?"); // convert backslashes to a backslash symbol + s2 = s2.Replace("", @"\u160?"); // convert hard spaces bug fix: B2016-206 + s2 = s2.Replace("`", @"\'b0"); // convert backquote to degree - left over from DOS days. s2 = s2.Replace("\xf8", @"\'b0"); // convert \xf8 to degree. - s2 = s2.Replace("\xa0", @"\u160?"); // hardspace - s2 = s2.Replace("\xb0", @"\'b0"); // degree - s2 = s2.Replace("\x7f", @"\u916?"); // delta - s2 = s2.Replace("\x2265", @"\u8805?"); // greater than or equal - s2 = s2.Replace("\x2264", @"\u8804?"); // less than or equal - s2 = s2.Replace("\xB1", @"\'b1"); // plus minus - s2 = s2.Replace("\x3A3", @"\u931?"); // sigma - s2 = s2.Replace("\x3C4", @"\u947?"); // gamma - s2 = s2.Replace("\xBD", @"\'bd"); // half - s2 = s2.Replace("\x25A0", @"\u9604?"); // accum 2584 - s2 = s2.Replace("\x7", @"\u9679?"); // bullet 25CF - s2 = s2.Replace("\x2248", @"\u8776?"); // approx eq - s2 = s2.Replace("\x2261", @"\u8773?"); // similar eq 2245 - s2 = s2.Replace("\xF7", @"\'f7"); // division - s2 = s2.Replace("\x221A", @"\u8730?"); // square root - s2 = s2.Replace("\x393", @"\u961?"); // rho 3C1 - s2 = s2.Replace("\x3C0", @"\u960?"); // pi - s2 = s2.Replace("\xb5", @"\u956?"); // micro 3BC (try e6, if not work try 109) - s2 = s2.Replace("\x3B4", @"\u948?"); // lower case delta - s2 = s2.Replace("\x3C3", @"\u963?"); // lower case sigma - s2 = s2.Replace("\xBC", @"\'bc"); // quarter - s2 = s2.Replace("\x3C6", @"\'d8"); // dist zero, D8 - s2 = s2.Replace("\xC9", @"\u274?"); // energy, 112 - s2 = s2.Replace("\xEC", @"\'ec"); // grave - s2 = s2.Replace("\x2502", @"\u9474?"); // bar - s2 = s2.Replace("\x3B5", @"\u949?"); // epsilon - s2 = s2.Replace("\x398", @"\u952?"); // theta, 3B8 - s2 = s2.Replace("\x221E", @"\u8857?"); // dot in oval, 2299 - s2 = s2.Replace("\xBF", @"\u964?"); // tau, 3C4 - s2 = s2.Replace("\x2310", @"\u9830?"); // diamond, 2666 - s2 = s2.Replace("\x2192", @"\u8594?"); - s2 = s2.Replace("\x2190", @"\u8592?"); - s2 = s2.Replace("\x2191", @"\u8593?"); - s2 = s2.Replace("\x2193", @"\u8595?"); - s2 = s2.Replace("\x2207", @"\u8711?"); - s2 = s2.Replace("\x2591", @"\'b0"); // Degree Symbol - s2 = s2.Replace("\xFF", @"\u8593?"); // Up Arrow - s2 = s2.Replace("\xD6", @"\u8595?"); // Down Arrow + s2 = s2.Replace("\xa0", @"\u160?"); // hardspace + s2 = s2.Replace("\xb0", @"\'b0"); // degree + s2 = s2.Replace("\x7f", @"\u916?"); // delta + s2 = s2.Replace("\x2265", @"\u8805?"); // greater than or equal + s2 = s2.Replace("\x2264", @"\u8804?"); // less than or equal + s2 = s2.Replace("\xB1", @"\'b1"); // plus minus + s2 = s2.Replace("\x3A3", @"\u931?"); // sigma + s2 = s2.Replace("\x3C4", @"\u947?"); // gamma + s2 = s2.Replace("\xBD", @"\'bd"); // half + s2 = s2.Replace("\x25A0", @"\u9604?"); // accum 2584 + s2 = s2.Replace("\x7", @"\u9679?"); // bullet 25CF + s2 = s2.Replace("\x2248", @"\u8776?"); // approx eq + s2 = s2.Replace("\x2261", @"\u8773?"); // similar eq 2245 + s2 = s2.Replace("\xF7", @"\'f7"); // division + s2 = s2.Replace("\x221A", @"\u8730?"); // square root + s2 = s2.Replace("\x393", @"\u961?"); // rho 3C1 + s2 = s2.Replace("\x3C0", @"\u960?"); // pi + s2 = s2.Replace("\xb5", @"\u956?"); // micro 3BC (try e6, if not work try 109) + s2 = s2.Replace("\x3B4", @"\u948?"); // lower case delta + s2 = s2.Replace("\x3C3", @"\u963?"); // lower case sigma + s2 = s2.Replace("\xBC", @"\'bc"); // quarter + s2 = s2.Replace("\x3C6", @"\'d8"); // dist zero, D8 + s2 = s2.Replace("\xC9", @"\u274?"); // energy, 112 + s2 = s2.Replace("\xEC", @"\'ec"); // grave + s2 = s2.Replace("\x2502", @"\u9474?"); // bar + s2 = s2.Replace("\x3B5", @"\u949?"); // epsilon + s2 = s2.Replace("\x398", @"\u952?"); // theta, 3B8 + s2 = s2.Replace("\x221E", @"\u8857?"); // dot in oval, 2299 + s2 = s2.Replace("\xBF", @"\u964?"); // tau, 3C4 + s2 = s2.Replace("\x2310", @"\u9830?"); // diamond, 2666 + s2 = s2.Replace("\x2192", @"\u8594?"); // Rightwards Arrow + s2 = s2.Replace("\x2190", @"\u8592?"); // Leftwards Arrow + s2 = s2.Replace("\x2191", @"\u8593?"); // Upwards Arrow + s2 = s2.Replace("\x2193", @"\u8595?"); // Downwards Arrow + s2 = s2.Replace("\x2207", @"\u8711?"); // Nabla (?) + s2 = s2.Replace("\x2591", @"\'b0"); // Degree Symbol + s2 = s2.Replace("\xFF", @"\u8593?"); // Up Arrow + s2 = s2.Replace("\xD6", @"\u8595?"); // Down Arrow if (DoCaret) s2 = s2.Replace("^", @"\u916?"); // Convert dash to a non-breaking dash. This is a unicode character. @@ -308,1086 +1784,39 @@ namespace VEPROMS.CSLA.Library //if the dash is preceeded byte a token remove the space following the token s2 = Regex.Replace(s2, @"(\\[^ \\?]*) \-", @"$1\u8209?"); s2 = s2.Replace("-", @"\u8209?"); + return s2; } + private string FixUnitROs(string val) { - if (val.StartsWith("") val = MyDocVersionInfo.DocVersionConfig.Unit_Text; - else if (val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Unit_Number; - else if (val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Unit_Name; - else if (val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Unit_ID; + if (val.ToUpper() == "") val = dvi.DocVersionConfig.Unit_Text; + else if (val.ToUpper() == "") val = dvi.DocVersionConfig.Unit_Number; + else if (val.ToUpper() == "") val = dvi.DocVersionConfig.Unit_Name; + else if (val.ToUpper() == "") val = dvi.DocVersionConfig.Unit_ID; // B2021-145: For applicability, the tree view & pdf file name are not getting resolved when using any of the ‘OTHER’ tokens // B2022-023 also check for other followed by a space - else if (val.ToUpper() == "" || val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Other_Unit_Text; - else if (val.ToUpper() == "" || val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Other_Unit_Number; - else if (val.ToUpper() == "" || val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Other_Unit_Name; - else if (val.ToUpper() == "" || val.ToUpper() == "") val = MyDocVersionInfo.DocVersionConfig.Other_Unit_ID; + else if (val.ToUpper() == "" || val.ToUpper() == "") val = dvi.DocVersionConfig.Other_Unit_Text; + else if (val.ToUpper() == "" || val.ToUpper() == "") val = dvi.DocVersionConfig.Other_Unit_Number; + else if (val.ToUpper() == "" || val.ToUpper() == "") val = dvi.DocVersionConfig.Other_Unit_Name; + else if (val.ToUpper() == "" || val.ToUpper() == "") val = dvi.DocVersionConfig.Other_Unit_ID; } + return val; } - // C2021-026 Get the child RO value if it exists, otherwise to the default (parent) RO value - // C2022-001 new logic to handle new format of Parent/Child RO.FST - // The RO.FST will not have a specific child value if that child value is the same as the default value - public string GetParentChildROValue(rochild roc) - { - string roval = roc.value; - // B2021-093 Don't look for child RO values if "roval" is null - if (roval == null) return null; - //string childName = MyDocVersionInfo.DocVersionConfig.Unit_Name; - // B2022-020 remove a un-needed question mark that was in the search criteria "(" - // B2022-050 change the search string from "(" to "" to handle when RO values have less then sign - MatchCollection mm = Regex.Matches(roval, ""); - - // C2022-014 commented write to error log. Keep for debugging purposes. - //if (mm.Count == 0) // B2022-020 will now write in error log if there is a problem - // _MyLog.WarnFormat("Parent/Child Values not parsable for \r\nItemId={0}\r\nROValue={1} ",MyDocVersionInfo.ItemID,roval); - StringBuilder sb = new StringBuilder(); - int lastIndex = 0; - // Get selected child Idx - int selChldIdx = MyDocVersionInfo.DocVersionConfig.SelectedSlave; - // C2021-065 see if we need to get the RO information for the "Other" Child applicability value - if (OtherChild != null && OtherChild != "") - selChldIdx = Convert.ToInt32(OtherChild); // the OTHER unit number - foreach (Match m in mm) - { - sb.Append(roval.Substring(lastIndex, m.Index - lastIndex)); - string aplString = m.Value; - string chldValStr = string.Format("UnitIdx={0} Value=", selChldIdx); - int offsetIdx = aplString.IndexOf(chldValStr);//m.Value.IndexOf(chldValStr); - int nextIDX = -1; - if (offsetIdx == -1) - offsetIdx = aplString.IndexOf("DefaultVal=") + 11; - else - offsetIdx += chldValStr.Length; - nextIDX = aplString.IndexOf(",UnitIdx", offsetIdx); - if (nextIDX == -1) nextIDX = aplString.IndexOf(" /APL>"); - sb.Append(aplString.Substring(offsetIdx, nextIDX - offsetIdx)); - lastIndex = m.Index + m.Length; // B2022-032 don't do a += of lastIndex the m.Index is the true position in the roval string - } - if (lastIndex < roval.Length) - sb.Append(roval.Substring(lastIndex)); // B2022-018 append any remaining text - return sb.ToString(); - //int startCVIdx = roval.IndexOf("", startCVIdx); - //int endDefIdx = roval.IndexOf(",UnitIdx=", startCVIdx); // look for more than just a comma incase value contains a comma - //string defValue = roval.Substring(16, (endDefIdx > 0 ? endDefIdx : EndCVidx) - 16); // save the default RO value - //// Get - //// Get selected child Idx - //int selChldIdx = MyDocVersionInfo.DocVersionConfig.SelectedSlave; - //// Get selected value - ////return either default value or child value as appropriate - //return defValue; - // get the child (slave) information and set the rtnchld.value to the corresponding RO Value - //string aplString = roval; - ////string ChldValue = ""; - //// if the RO Value contains Parent/Child values, parse out default value and the child (slave or unit specific) value - ////while (roval != null && roval.Contains("" - // idxEndVal = aplString.IndexOf(" /APL>", idx); // B2021-141 get end of Parent/Child RO Values for this RO reference - // if (idxEndVal > idx) - // ChldValue = aplString.Substring(idx, idxEndVal - idx); // selected Child RO value - // else - // ChldValue = defValue; // incomplete "") with the specifc value - ////} - //return roval; - } - // this only gets rochild values. Later we may want another - // dictionary to get groups. - public string GetRoValue(string ROID16) - { - string ROID = ROID16.Substring(0,12); - if (dicRos == null) ParseIntoDictionary(_ROFst!=null?_ROFst.ROLookup:_ROFstInfo.ROLookup); - // Use the ROID to get the value from the dictionary - if (dicRos.ContainsKey(ROID.ToUpper())) - { - rochild rochld = (rochild)dicRos[ROID.ToUpper()]; - if (rochld.value != null && rochld.value != string.Empty) - return FixUnitROs(GetParentChildROValue(rochld)); - if (rochld.children != null) - { - foreach (rochild child in rochld.children) - if (child.roid.ToUpper() == ROID16.ToUpper() || (child.roid.EndsWith("0041") && ROID16.EndsWith("0000"))) - return FixUnitROs(GetParentChildROValue(child) ?? "?"); - // if there isn't a specific match for multi-return values, default to the first child. - return FixUnitROs(GetParentChildROValue(rochld.children[0]) ?? "?"); - } - } - //if (ROID == "FFFF00000001") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Unit_Number; - //if (ROID == "FFFF00000002") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Other_Unit_Number; - //if (ROID == "FFFF00000003") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Unit_Text; - //if (ROID == "FFFF00000004") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Other_Unit_Text; - //if (ROID == "FFFF00000005") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Unit_ID; - //if (ROID == "FFFF00000006") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Other_Unit_ID; - //if (ROID == "FFFF00000007") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Unit_Name; - //if (ROID == "FFFF00000008") return _ROFstInfo.ROFstAssociations[0].MyDocVersion.DocVersionConfig.Other_Unit_Name; - //new stuff - if (ROID == "FFFF00000001") return MyDocVersionInfo.DocVersionConfig.Unit_Number;// _ROFstInfo.docVer.DocVersionConfig.Unit_Number; - if (ROID == "FFFF00000002") return MyDocVersionInfo.DocVersionConfig.Other_Unit_Number;// _ROFstInfo.docVer.DocVersionConfig.Other_Unit_Number; - if (ROID == "FFFF00000003") return MyDocVersionInfo.DocVersionConfig.Unit_Text;// _ROFstInfo.docVer.DocVersionConfig.Unit_Text; - if (ROID == "FFFF00000004") return MyDocVersionInfo.DocVersionConfig.Other_Unit_Text;// _ROFstInfo.docVer.DocVersionConfig.Other_Unit_Text; - if (ROID == "FFFF00000005") return MyDocVersionInfo.DocVersionConfig.Unit_ID;// _ROFstInfo.docVer.DocVersionConfig.Unit_ID; - if (ROID == "FFFF00000006") return MyDocVersionInfo.DocVersionConfig.Other_Unit_ID;// _ROFstInfo.docVer.DocVersionConfig.Other_Unit_ID; - if (ROID == "FFFF00000007") return MyDocVersionInfo.DocVersionConfig.Unit_Name;// _ROFstInfo.docVer.DocVersionConfig.Unit_Name; - if (ROID == "FFFF00000008") return MyDocVersionInfo.DocVersionConfig.Other_Unit_Name;// _ROFstInfo.docVer.DocVersionConfig.Other_Unit_Name; - //end new stuff - if (ROID.StartsWith("FFFF")) return "?"; // string.Format("Invalid Unit RO '{0}'", ROID); - return "?"; // string.Format("Invalid RO '{0}'", ROID); - } - // Get the the RO's Accessory Page ID - public string GetRoACID(string ROID16) - { - string ROID = ROID16.Substring(0,12); - if (dicRos == null) ParseIntoDictionary(_ROFst!=null?_ROFst.ROLookup:_ROFstInfo.ROLookup); - // Use the ROID to get the value from the dictionary - if (dicRos.ContainsKey(ROID.ToUpper())) - { - rochild rochld = (rochild)dicRos[ROID.ToUpper()]; - if (rochld.value != null && rochld.value != string.Empty) - return rochld.appid; - if (rochld.children != null) - { - foreach (rochild child in rochld.children) - if (child.roid.ToUpper() == ROID16 || (child.roid.EndsWith("0041") && ROID16.EndsWith("0000"))) - return child.appid; - // if there isn't a specific match for multi-return values, default to the first child. - return rochld.children[0].appid; - } - } - return ""; // no accessory page ID found - } - // Get the the RO's Description - public string GetRoDescription(string ROID16) - { - string ROID = ROID16.Substring(0,12); - if (dicRos == null) ParseIntoDictionary(_ROFst!=null?_ROFst.ROLookup:_ROFstInfo.ROLookup); - // Use the ROID to get the value from the dictionary - if (dicRos.ContainsKey(ROID.ToUpper())) - { - rochild rochld = (rochild)dicRos[ROID.ToUpper()]; - if (rochld.value != null && rochld.value != string.Empty) - return rochld.title; - if (rochld.children != null) - { - foreach (rochild child in rochld.children) - if (child.roid.ToUpper() == ROID16 || (child.roid.EndsWith("0041") && ROID16.EndsWith("0000"))) - return child.title; - // if there isn't a specific match for multi-return values, default to the first child. - return rochld.children[0].title; - } - } - return ""; // no Title/Description found - } - //public string GetRoValueAccIDAndDescription(string ROID16) - //{ - // string rtnstr = GetRoValue(ROID16); - // rtnstr += " " + GetRoACID(ROID16); - // rtnstr += " " + GetRoDescription(ROID16); - // return rtnstr; - //} - - public rochild GetRoChild12(string ROID16) - { - string ROID = (ROID16.Length < 12)?ROID16 : ROID16.Substring(0, 12); - if (dicRos == null) ParseIntoDictionary(_ROFst != null ? _ROFst.ROLookup : _ROFstInfo.ROLookup); - // Use the ROID to get the value from the dictionary - if (dicRos.ContainsKey(ROID.ToUpper())) - { - rochild rochld = (rochild)dicRos[ROID.ToUpper()]; - return rochld; - } - rochild tmp = new rochild(); - tmp.ID = -1; - if (ROID16.Length == 4) - tmp.title = dicRoDBs[ROID16]; - return tmp; - } - public rochild GetRoChild(string ROID) - { - if (dicRos == null) ParseIntoDictionary(_ROFst != null ? _ROFst.ROLookup : _ROFstInfo.ROLookup); - // Use the ROID to get the value from the dictionary - if (dicRos.ContainsKey(ROID.ToUpper())) - { - rochild rochld = (rochild)dicRos[ROID.ToUpper()]; - return rochld; - } - if (ROID.StartsWith("FFFF")) - { - rochild roc = new rochild(); - roc.roid = ROID; - roc.type = 1; - //int selectedSlave = _ROFstInfo.docVer.DocVersionConfig.SelectedSlave; - //_ROFstInfo.docVer.DocVersionConfig.SelectedSlave = 0; - roc.value = GetRoValue(ROID); - //_ROFstInfo.docVer.DocVersionConfig.SelectedSlave = selectedSlave; - switch (ROID) - { - case "FFFF00000001": - roc.appid = "U-Number"; - break; - case "FFFF00000002": - roc.appid = "U-Other Number"; - break; - case "FFFF00000003": - roc.appid = "U-Text"; - break; - case "FFFF00000004": - roc.appid = "U-Other Text"; - break; - case "FFFF00000005": - roc.appid = "U-ID"; - break; - case "FFFF00000006": - roc.appid = "U-Other ID"; - break; - case "FFFF00000007": - roc.appid = "U-Name"; - break; - case "FFFF00000008": - roc.appid = "U-Other Name"; - break; - default: - roc.appid = "U-Unknown"; - break; - } - return roc; - } - rochild tmp = new rochild(); - tmp.ID = -1; - return tmp; - } - public string GetROTitle(string ROID) - { - StringBuilder sb = new StringBuilder(); - rochild roc = GetRoChild12(ROID); - if (roc.value == null) - roc = GetRoChild(ROID); - // B2020-125: View of Consistency check report displaying error message and crashing. And also in 'else' check for null - if (roc.ID == -1) - sb.Append("Could not find RO data"); - else - { - string tmp = roc.title; - if (tmp == null) tmp = ""; - if (roc.appid != null) tmp = tmp.Replace(roc.appid, ""); - if (roc.value != null) tmp = tmp.Replace(roc.value, ""); - sb.Append(tmp.Trim()); - } - do - { - string parent = ROID.Substring(0, 4) + string.Format("{0:X8}", roc.ParentID); - roc = GetRoChild12(parent); - if (roc.ID > 0) - sb.Insert(0, roc.title + " - "); - } while (roc.ID > 0); - return sb.ToString(); - } - // Return the RO Title in a list of strings - // The last item in the list is the actual RO title, the items preceding it are the - // titles of the groups and sub-groups containing the RO - public List GetROTitleAndGroupPath(string ROID, bool reportMissingROs, bool convertCaretToDelta) - { - List titlePath = new List(); - rochild roc = GetRoChild12(ROID); - if (roc.appid != null) - { - string tmp = roc.title; - if (roc.appid != "") - if (roc.title.Contains(roc.appid)) - //tmp = roc.title.Replace(roc.appid, string.Format("<{0}>", roc.appid)).Trim(); - // remove the setpoint ID (appid) from the title string and always put the sepoint ID - // at the beginning of the report line item. - tmp = roc.title.Replace(roc.appid, "").Trim(); - //else - tmp = string.Format("[{0}] {1}", roc.appid, tmp); - tmp = tmp.Replace("`", "\u00B0"); //degree - tmp = tmp.Replace("\xF8", "\u00B0"); //degree - if (convertCaretToDelta) - tmp = tmp.Replace("^", "\u0394"); // delta - titlePath.Add(tmp); - do - { - string parent = ROID.Substring(0, 4) + string.Format("{0:X8}", roc.ParentID); - roc = GetRoChild12(parent); - if (roc.ID > 0) - titlePath.Add(roc.title); - } while (roc.ID > 0); - titlePath.Reverse(); - } - else if (reportMissingROs) // Missing RO, put a message with the ROID on the report... - titlePath.Add(string.Format("Missing RO for ROID {0}", ROID)); - - return titlePath; - } - //public List GetROTitleAndGroupPathForSummary(string ROID) - //{ - // List titlePath = new List(); - // rochild roc = GetRoChild(ROID); - // string tmp = roc.title.Replace(roc.appid, string.Format("<{0}>",roc.appid)).Trim(); - // titlePath.Add(tmp); - // do - // { - // string parent = ROID.Substring(0, 4) + string.Format("{0:X8}", roc.ParentID); - // roc = GetRoChild(parent); - // if (roc.ID > 0) - // titlePath.Add(roc.title); - // } while (roc.ID > 0); - // titlePath.Reverse(); - // return titlePath; - //} - public DateTime GetRoFSTdts() - { - return MyDocVersionInfo.DocVersionAssociations[0].MyROFst.DTS; - } - // The following Method is not correct. It needs to have a RO database id as well as an id. Without that, - // the first RO with a specific id will be found regardless of the RO Database id. - //public rochild GetRoChildFromID(int id) - //{ - // if (dicRosIntIDs == null) ParseIntoDictionary(_ROFst != null ? _ROFst.ROLookup : _ROFstInfo.ROLookup); - // // Use the id to get the value from the dictionary - // if (dicRosIntIDs.ContainsKey(id)) - // { - // rochild rochld = (rochild)dicRosIntIDs[id]; - // return rochld; - // } - // rochild tmp = new rochild(); - // tmp.ID = -1; - // return tmp; - //} - public rodbi[] GetRODatabaseList() - { - return myHdr.myDbs; - } - public int GetRODatabaseTitleIndex(string roid) - { - rochild roc = GetRoChild12(roid); - int parentID = roc.ParentID; - return Convert.ToInt32("0x"+roid.Substring(0, 4),16); - } - public string GetRODatabaseTitle(string roid) - { - return GetRODatabaseTitle(GetRODatabaseTitleIndex(roid)); - } - public string GetRODatabaseTitle(int idx) - { - string dbtitle ="RO Database Title Not Found"; - for (int i = 0; i < myHdr.myDbs.Length; i++) - if (myHdr.myDbs[i].dbiID == idx) - { - dbtitle = myHdr.myDbs[i].dbiTitle; - break; - } - return dbtitle; - } - public rodbi GetRODatabase(int idx) - { - for (int i = 0; i < myHdr.myDbs.Length; i++) - if (myHdr.myDbs[i].dbiID == idx) - return myHdr.myDbs[i]; - return myHdr.myDbs[0]; - } - public rodbi GetRODatabase(string roid) - { - int idx = Convert.ToInt32("0x" + roid.Substring(0, 4), 16); - for (int i = 0; i < myHdr.myDbs.Length; i++) - if (myHdr.myDbs[i].dbiID == idx) - return myHdr.myDbs[i]; - return myHdr.myDbs[0]; - } - //public string GetDefaultROPrefix() - //{ - // if (docVer != null) - // return docVer.DocVersionConfig.RODefaults_setpointprefix; - // else - // return "SP1"; // Not Sure about this... - //} - //public string GetDefaultGraphicsPrefix() - //{ - // if (docVer != null) - // return docVer.DocVersionConfig.RODefaults_graphicsprefix; - // else - // return "IG1"; // Not Sure about this... - //} - #region Update Ro Values - /// - /// Updates an ro.fst into a sql database. - /// - /// - /// ROFst: Returns the created rofst object - //public static ROFst UpdateRoFst(RODbInfo rdi, DocVersionAssociation dva, DocVersion docver) - //{ - // // file validity checks are done before getting here - just do the import - // // here. - // string rofstfilepath = rdi.FolderPath + @"\ro.fst"; - - // DirectoryInfo di = new DirectoryInfo(rdi.FolderPath); - - // // There may be more than 1 'ro' as the 'ROName' field (ROName is derived from the ropath). - // // Get new name be incrementing, if so. - // string newname = NewROName(di.Name); - - // // Next read in the rofst & make the rofst record. - // FileStream fsIn = new FileStream(rofstfilepath, FileMode.Open, FileAccess.Read, FileShare.Read); - // // Create an instance of StreamReader that can read characters from the FileStream. - // BinaryReader r = new BinaryReader(fsIn); - // byte[] ab = r.ReadBytes((int)fsIn.Length); - // fsIn.Close(); - - // using (RODb rd = RODb.Get(rdi.RODbID)) - // { - // ROFst rofst = ROFst.MakeROFst(rd, ab, null, di.LastWriteTimeUtc, rdi.UserID); - // // Hook this into the current docversion by replacing the rofstid field in the doc version - // // association object: - // dva.MyROFst = rofst; - // docver.Save(); - - // // Now load any images in... type 8 - integrated graphics ro type - // ROFstInfo rofstInfo = ROFstInfo.Get(rofst.ROFstID); - // rofstInfo.ParseIntoDictionary(rofstInfo.ROFST); - // for (int i = 0; i < rofstInfo.myHdr.myDbs.Length; i++) - // { - // // walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8: - // if (rofstInfo.myHdr.myDbs[i].children != null) rofstInfo.MigrateRoFstGraphics(rdi, rofstInfo.myHdr.myDbs[i].children); - // } - // return rofst; - // } - //} - //private static string RoAppConfigExt(string fstPath) - //{ - // string inipath = fstPath + @"\roapp.ini"; - // if (!File.Exists(inipath)) return null; - // StreamReader myReader = new StreamReader(inipath); - // string sLine; - // int indx = -1; - // while ((sLine = myReader.ReadLine()) != null) - // { - // if (sLine.Length > 0 && sLine.Substring(0, 1) != ";") - // { - // if ((indx = sLine.ToLower().IndexOf("extention")) >= 0) - // { - // indx = sLine.IndexOf("=", indx + 9); - // return sLine.Substring(indx + 1, sLine.Length - indx - 1).Trim(); - // } - // } - // } - // myReader.Close(); - // return null; - //} - //private static string NewROName(string roName) - //{ - // string retval = roName; - // int iSuffix = -1; - // RODbInfoList rodblist = RODbInfoList.Get(); - - - // foreach (RODbInfo rdi in rodblist) - // { - // if (rdi.ROName.StartsWith(roName)) - // { - // if (rdi.ROName == roName) - // iSuffix = 0; - // else if (Regex.IsMatch(rdi.ROName, roName + "[_][0-9]+")) - // { - // int ii = int.Parse(rdi.ROName.Substring(1 + roName.Length)); - // if (ii > iSuffix) iSuffix = ii; - // } - // } - // } - // if (iSuffix >= 0) - // retval = string.Format("{0}_{1}", roName, iSuffix + 1); - // return retval; - //} - //private void MigrateRoFstGraphics(RODbInfo rdi, ROFstInfo.rochild[] rochild) - //{ - // for (int i = 0; i < rochild.Length; i++) - // { - // if (rochild[i].type == 8) AddGraphic(rdi, rochild[i].value); - // if (rochild[i].children != null) MigrateRoFstGraphics(rdi, rochild[i].children); - // } - //} - //private void AddGraphic(RODbInfo rdi, string p) - //{ - // if (p == null) return; - // string imgname = p.Substring(0, p.IndexOf('\n')); - // int thedot = imgname.LastIndexOf('.'); - // string fname = imgname; - // if (thedot == -1 || (thedot != (imgname.Length - 4))) - // { - // RODbConfig roDbCfg = new RODbConfig(rdi.Config); - // fname += string.Format(".{0}", roDbCfg.GetDefaultGraphicExtension()); - // } - - // string imgfile = rdi.FolderPath + @"\" + fname; - - // ROImage roImg = null; - // if (File.Exists(imgfile)) - // { - // FileInfo fi = new FileInfo(imgfile); - // // if the roimage record exists, don't create a new one... - // using (roImg = ROImage.GetByRODbID_FileName_DTS(rdi.RODbID, imgname, fi.LastWriteTimeUtc)) - // { - // if (roImg == null) - // { - // FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.Read); - // BinaryReader r = new BinaryReader(fsIn); - // byte[] ab = r.ReadBytes((int)fsIn.Length); - // r.Close(); - // fsIn.Close(); - // using (RODb rodb = RODb.Get(rdi.RODbID)) - // { - // roImg = ROImage.MakeROImage(rodb, imgname, ab, null, fi.LastWriteTimeUtc, "Migration"); - // } - // } - // Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID); - // if (figure != null) return; - // using (ROFst rofst = ROFst.Get(this.ROFstID)) - // { - // figure = Figure.MakeFigure(rofst, roImg, null); - // } - // } - // } - // else - // Console.WriteLine(string.Format("{0}", imgfile), "Cannot Find Image File"); - //} #endregion + #endregion - #region LoadStructs - private int StringLength(byte[] ab, int offset) - { - int i = 0; - while (ab[i + offset] != 0) i++; - return i; - } - private rogrp LoadGroup(byte[] ab, int offset) - { - rogrp myGrp = new rogrp(); - myGrp.ID = BitConverter.ToInt32(ab, offset); - myGrp.ParentID = BitConverter.ToInt32(ab, offset + 4); - int howmany = BitConverter.ToInt16(ab, offset + 8); - if (howmany > 0) - { - myGrp.children = new rochild[howmany]; - int myOffset = offset + 10; - for (int i = 0; i < myGrp.children.Length; i++) - { - int childOffset = BitConverter.ToInt32(ab, myOffset); - rochild tmp = new rochild(); - //tmp.offset=BitConverter.ToInt32(ab,myOffset); - tmp.type = BitConverter.ToInt16(ab, myOffset + 4); - int slen = StringLength(ab, myOffset + 6); - tmp.title = Encoding.Default.GetString(ab, myOffset + 6, slen); - myOffset += (7 + slen); - rogrp tmpg = LoadGroup(ab, childOffset); - MultipleReturnValuesInheritType(ref tmpg, tmp.type); - tmp.ID = tmpg.ID; - tmp.ParentID = tmpg.ParentID; - tmp.children = tmpg.children; - tmp.value = tmpg.value; - tmp.appid = tmpg.appid; - tmp.roid = TableID.ToString("X4") + tmp.ID.ToString("X8"); - // Add dictionary entries for children - if (tmp.children != null) - { - foreach (rochild child in tmp.children) - if (!dicRos.ContainsKey(child.roid.ToUpper())) - dicRos.Add(child.roid.ToUpper(), child); // child is a struct not a class. - } - dicRos.Add(tmp.roid.ToUpper(), tmp); - //if (!dicRosIntIDs.ContainsKey(tmp.ID)) dicRosIntIDs.Add(tmp.ID, tmp); - int j; - for (j = i - 1; j >= 0 && tmp.ID < myGrp.children[j].ID; j--) - { - myGrp.children[j + 1] = myGrp.children[j]; - } - myGrp.children[j + 1] = tmp; - } - } - else - { - int slen = StringLength(ab, offset + 12); - //myGrp.value = Encoding.Default.GetString(ab, offset + 12, slen); - ProcessROReturnValue(ref myGrp, Encoding.Default.GetString(ab, offset + 12, slen)); - int slen2 = StringLength(ab, offset + 13 + slen); - myGrp.appid = Encoding.Default.GetString(ab, offset + 13 + slen, slen2); - } - return myGrp; - } - /// - /// This function will take the raw RO return value and resolve any macros, conditionals, and - /// generated the return value or a list of multiple return values. - /// - /// - /// - private void ProcessROReturnValue(ref rogrp myGrp, string rawvalue) - { - if (dicRos == null) ParseIntoDictionary(_ROFst != null ? _ROFst.ROLookup : _ROFstInfo.ROLookup); - List lstROVals = GetROReturnValue(rawvalue); - if (lstROVals.Count > 1) // mulitple return values - { - myGrp.children = new rochild[lstROVals.Count]; - for (int i = 0; i < lstROVals.Count; i++) - { - string tsts = Convert.ToInt32(multiRoValues[i][0]).ToString("X4"); - myGrp.children[i].value = lstROVals[i].Replace("\xFF", "\xa0"); - myGrp.children[i].roid = TableID.ToString("X4") + myGrp.ID.ToString("X8") + tsts; - myGrp.children[i].type = -1; // Multiple return value inherit type from parent - myGrp.children[i].title = lstROVals[i].Replace("\xFF", "\xa0"); - } - } - else - myGrp.value = lstROVals[0]; - return; + #region Public Static Methods - } - /// - /// Multiple return values need to get the type from the parent node. - /// - /// - /// - private void MultipleReturnValuesInheritType(ref rogrp myGrp, int parenttype) - { - if (myGrp.children != null) - { - for (int cnt = 0; cnt < myGrp.children.Length; cnt++) - { - if (myGrp.children[cnt].type == -1) - { - myGrp.children[cnt].type = parenttype; - myGrp.children[cnt].appid = myGrp.appid; - } - } - } - } + #region (FortranFormat) - private void ParseIntoDictionary(byte[] ab) - { - if (dicRos == null) dicRos = new Dictionary(); - //if (dicRosIntIDs == null) dicRosIntIDs = new Dictionary(); - if (dicRoDBs == null) dicRoDBs = new Dictionary(); - - myHdr.hSize = BitConverter.ToInt32(ab, 0); - myHdr.hYear = BitConverter.ToInt16(ab, 4); - myHdr.hMonth = ab[6]; - myHdr.hDay = ab[7]; - myHdr.hcYear = BitConverter.ToInt16(ab, 8); - myHdr.hcMonth = ab[10]; - myHdr.hcDay = ab[11]; - myHdr.hcHour = ab[12]; - myHdr.hcMin = ab[13]; - myHdr.hcSec = ab[14]; - myHdr.hcHund = ab[15]; - int hdrOffset = BitConverter.ToInt32(ab, 16); - int howbig = BitConverter.ToInt32(ab, hdrOffset); - int dbs = BitConverter.ToInt16(ab, hdrOffset + 4); - myHdr.myDbs = new rodbi[dbs]; - for (int i = 0; i < dbs; i++) - { - int offset = hdrOffset + 6 + (i * 30); - myHdr.myDbs[i].dbiID = BitConverter.ToInt16(ab, offset + 0); - TableID = myHdr.myDbs[i].dbiID; - myHdr.myDbs[i].dbiType = BitConverter.ToInt16(ab, offset + 2); - myHdr.myDbs[i].dbiAW = BitConverter.ToInt16(ab, offset + 4); - rogrp tmp = LoadGroup(ab, BitConverter.ToInt32(ab, offset + 6)); - myHdr.myDbs[i].ID = tmp.ID; - myHdr.myDbs[i].children = tmp.children; - int iPtr = BitConverter.ToInt32(ab, offset + 22) + hdrOffset + 6; - myHdr.myDbs[i].dbiTitle = Encoding.Default.GetString(ab, iPtr, StringLength(ab, iPtr)); - iPtr = BitConverter.ToInt32(ab, offset + 26) + hdrOffset + 6; - myHdr.myDbs[i].dbiAP = Encoding.Default.GetString(ab, iPtr, StringLength(ab, iPtr)); - dicRoDBs.Add(string.Format("{0:X4}", TableID), myHdr.myDbs[i].dbiTitle); - } - } - #endregion - #region GetRoValues - public List GetROReturnValue(string roval) - { - lstRoValues = new List(); - multiRoValues = new List(); - DictROVar = new Dictionary(); // set up a dictionary of RO defined Variables - string tmp = ProcessRO(_MyDocVersionInfo==null?roval:_MyDocVersionInfo.ProcessDocVersionSpecificInfo(roval), false); - if (tmp != null && lstRoValues.Count == 0) // was not a multiple return value - lstRoValues.Add(tmp); - return lstRoValues; - } - - private string ProcessRO(string roval, bool multiRtnVal) - { - string str = roval; - string rtnstr = ""; - int l = roval.Length; - while (l > 0) - { - int ptr = NextDelimiter("{", str); - if (ptr == -1) - { // add remaining text - //add(new seText(str, l)); - rtnstr += str; - l = 0; // break out of while loop - } - else - { - int cnt = ptr; //(int)(ptr - str); - if (cnt > 0) - { // add text - //add(new seText(str, cnt)); - rtnstr += str.Substring(0, cnt); - l -= cnt; - //str = ptr; - str = str.Substring(ptr); - } - ptr = MatchingBrace(str) + 1; - cnt = ptr; //(int)(ptr - str); - bool nfnd = false; - string pbstr = ProcessBrace(str.Substring(1, cnt - 2), cnt - 2, ref nfnd, multiRtnVal); - if (pbstr == null) return null; - if (nfnd) - rtnstr += str.Substring(0, cnt); - // add(new seText(str, cnt)); - else - rtnstr += pbstr; - l -= cnt; - //str = ptr; - str = str.Substring(ptr); - } - } - //rtnstr = rtnstr.Replace("`", @"\'b0"); // convert backquote to degree - left over from DOS days. - rtnstr = ProcessMacros(rtnstr); - return rtnstr; - } - - // - // 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 - // - // right now the only macro is @HSP(), where every space between the "(" and ")" will be replaced with a hardspace - // - private string ProcessMacros(string str) - { - if( str == null || str == "" ) return str; - string rtnstr = str; - int indx = -1; - while ((indx = rtnstr.ToUpper().IndexOf("@HSP(")) > -1) - { - string resstr = rtnstr.Substring(0, indx); - int endHsp = rtnstr.IndexOf(")", indx); - string tmpstr = rtnstr.Substring(indx + 5, endHsp - indx - 5); - if (!tmpstr.Contains("< 0 && match == null) - { - int end = MatchingBrace(opt); - int eq = opt.IndexOf('=');// strchr(opt, '='); - int len = end + 1; //(int)((end + 1) - opt); // +1 to include the '}' - int li = eq - 1;//(int)(eq - opt) - 1; - int ld = len - li - 3;// One for '{', '=' and '}' - if (def == null || eq == 1) // (!def || eq == opt+1) - { - def = opt.Substring(eq + 1); //def=eq+1; - deflen = ld; - } - if (ls == li && opt.Substring(1).StartsWith(stat+"=")) // (stat.IndexOf(opt.Substring(1), li) > -1)) //(ls == li && !strncmp(stat, opt + 1, li)) - { - match = opt.Substring(eq + 1, ld);// match = eq + 1; - matchlen = ld; - } - opt = opt.Substring(len); //opt += len;// point to the next piece - lenopt -= len; - } - // if match process option - or process default - if (match == null) //(!match) - { - match = def.Substring(0, deflen); - matchlen = deflen; - } - return ProcessRO(match, multiRtnVal); //process(match, matchlen); - } - - private string ProcessBrace(string str, int l, ref bool nfnd, bool multiRtnVal) - { - string rtnstr = ""; - int nxt = NextDelimiter("{=", str); //nextDelimiter("{=", str, l); - if (nxt == -1) // no delimiter found - { // VarUse - //strList *found=vl->lookFor(str,l); - bool found = DictROVar.ContainsKey(str); - if (found) - rtnstr = DictROVar[str]; - //add(new seVarUse(found)); - else - nfnd = true; - } - else - { - if (str[nxt] == '{') - { // conditonal or menu - if (nxt == 0) // if (nxt == str) - { // menu - // TODO: implement Menu logic - //ml->process(str, l, vl); - //add(new seMenuUse(ml)); - //lstRoValues.Add(ProcessRO(str.Substring(0,l), true)); - ProcessMultiReturnValues(str, l); - } - else - { // conditional - rtnstr = ProcessConditional(str, str.Substring(nxt), nxt, str.Length - nxt - 1, multiRtnVal);//processCondition(str, nxt, (int)(nxt - str), l - (int)(nxt - str)); - } - } - else - { // must be variable definiton - //vl->add(str, nxt+1, (int)(nxt-str), (l - (int)(nxt-str))-1, ml); - - // 'l' is the lenght up to the matching brace of the variable definition - string tmpval = ProcessRO(str.Substring(nxt + 1, l - nxt - 1), multiRtnVal); - if (tmpval.Equals(string.Empty)) tmpval = " "; // nothing assinged to variable - if (!DictROVar.ContainsKey(str.Substring(0, nxt))) // need a try/catch here. - { - DictROVar.Add(str.Substring(0, nxt), tmpval); - if(nxt == 1) - multiRoValues.Add(str.Substring(0, nxt)); - } - else - return null; - if (multiRtnVal) - rtnstr = tmpval; - } - } - return rtnstr; - } - private Dictionary> _ValueLookupDictionary = null; - public List GetRosByValue(string value) - { - if (_ValueLookupDictionary == null) - BuildValueDictionary(); - if (value == string.Empty) - return null; - if(_ValueLookupDictionary.ContainsKey(value.ToUpper())) - return _ValueLookupDictionary[value.ToUpper()]; - return null; - } - private void BuildValueDictionary() - { - _ValueLookupDictionary = new Dictionary>(); - if (dicRos == null) - ParseIntoDictionary(_ROFst != null ? _ROFst.ROLookup : _ROFstInfo.ROLookup); - foreach (rochild child in dicRos.Values) - { - if (child.value != null) - { - string value = child.value.ToUpper().Replace("\\U160?"," "); - string key = null; - if (value.Trim().Length == 0) - continue; // do save anthing with a blank key - // B2022-037 if the RO value contains applicability information, then process it (this will give us the default RO value) - else if (value.Contains(" children = new List(); - // adding entries to this dictionary for every ro!! - children.Add(new roChild(chldForDictionary)); // B2022-037 save the process RO information - _ValueLookupDictionary.Add(key, children); - } - } - } - } - private Dictionary _dicROAPID = null; - public rochild? GetROChildByAccPageID(string accPageID, string spDefault, string igDefault) - { - rochild? child = GetRoChildByAccPagID(accPageID, spDefault, igDefault); - if (child == null) - { - if(Regex.IsMatch(accPageID, @".*\.[A-Z]")) - { - string accpage = accPageID.Substring(0, accPageID.Length - 3); - int index = accPageID.Substring(accPageID.Length - 2, 1)[0] - 'A'; - child = GetRoChildByAccPagID(accpage.TrimStart("<".ToCharArray()), spDefault, igDefault); - if (child == null) return null; - if (((rochild)child).children != null && ((rochild)child).children.Length > 0 && ((rochild)child).children.Length > index) - return ((rochild)child).children[index]; - } - return null; - } - if (((rochild)child).children != null && ((rochild)child).children.Length > 0) - return ((rochild)child).children[0]; - return (rochild)child; - } - public string GetROValueByAccPagID(string accPageID, string spDefault, string igDefault) - { - rochild? child = GetROChildByAccPageID(accPageID, spDefault, igDefault); - if (child == null) return null; - return GetParentChildROValue((rochild)child); // C2021-026 get the P/C value if it exists, otherwise get the non-P/C value - } - public int? GetROTypeByAccPagID(string accPageID, string spDefault, string igDefault) - { - rochild? child = GetROChildByAccPageID(accPageID, spDefault, igDefault); - if (child == null) return null; - return ((rochild)child).type; - } - public string GetROIDByAccPagID(string accPageID, string spDefault, string igDefault) - { - rochild? child = GetROChildByAccPageID(accPageID, spDefault, igDefault); - if (child == null) return null; - return ((rochild)child).roid; - } - public rochild? GetRoChildByAccPagID(string accPageID, string spDefault, string igDefault) - { - if (_dicROAPID == null) - BuildROAPIDDictionary(); - accPageID = accPageID.Replace("".ToCharArray()); // String < and > - string key = FormatKey(accPageID); - if (_dicROAPID.ContainsKey(key)) - return _dicROAPID[key]; - return null; - } - Regex regRoKeyHigh = new Regex("( |-|_)(HIGH|HI)([0-9])"); - Regex regRoKeyLow = new Regex("( |-|_)(LOW|LO)([0-9])"); - public string FormatKey(string keyOrig) - { - string key=keyOrig.ToUpper(); - key=regRoKeyHigh.Replace(key,"_HIGH$3"); - key=regRoKeyLow.Replace(key,"_LOW$3"); - //if (key != keyOrig) Console.WriteLine("{0}!={1}", key, keyOrig); - return key; - } - private void BuildROAPIDDictionary() - { - int profileDepth = ProfileTimer.Push(">>>> BuildROAPIDDictionary"); - if (dicRos == null) - ParseIntoDictionary(_ROFst != null ? _ROFst.ROLookup : _ROFstInfo.ROLookup); - _dicROAPID = new Dictionary(); - foreach (rodbi dbi in myHdr.myDbs) - { - if (dbi.children != null) - BuildROAPIDDictionary(dbi.dbiAP, dbi.children); - } - ProfileTimer.Pop(profileDepth); - } - private void BuildROAPIDDictionary(string prefix, rochild[] children) - { - foreach (rochild child in children) - { - if (child.appid != null && child.appid != "" && child.ID != 0) - { - string key = string.Format("{0}-{1}", prefix, FormatKey(child.appid)); - if (!_dicROAPID.ContainsKey(key)) - _dicROAPID.Add(key, child); - } - if (child.children != null) - BuildROAPIDDictionary(prefix, child.children); - } - } - private void ProcessMultiReturnValues(string str, int len) - { - string tstr = str.Substring(0, len); - while (tstr.Length > 0) - { - int idx = MatchingBrace(tstr); - string tmpVal = ProcessRO(tstr.Substring(0, idx + 1), true); - if (tmpVal != null) lstRoValues.Add(tmpVal); // duplicates get returned as null - tstr = tstr.Substring(idx + 1); - } - } - - - private int MatchingBrace(string str) - { - int level = 1; - int idx = 0; // the while will skip the first position (the first brace) - while (level > 0 && idx++ < str.Length) - { - switch (str[idx]) - { - case '{': - level++; - break; - case '}': - level--; - break; - } - } - if (level != 0) - idx = -1; // didn't find matching brace - - return idx; //length including end brace - } - - private int NextDelimiter(string delim, string str) - { - int idx; - idx = str.IndexOfAny(delim.ToCharArray()); - return idx; - } - public List GetRoChildrenByType(int type) - { - List children = new List(); - AddRoChildByType(children, type); - return children; - } - private void AddRoChildByType(List children, int type) - { - foreach (rodbi dbi in myHdr.myDbs) - { - if (dbi.children != null) - AddRoChildByType(dbi.children,children,type); - } - } - private void AddRoChildByType(rochild[] roChildren, List children, int type) - { - foreach (rochild child in roChildren) - { - if (child.type == type && child.value != null) - children.Add(child); - if (child.children != null) - AddRoChildByType(child.children,children,type); - } - } - #endregion - #region FortranFormat public static string ConvertFortranFormatToScienctificNotation(string str) { // ([+-]?|\\u8209\?) either an optional single character Plus (+) or Minus (-) or non-breaking dash (\u8209?) @@ -1397,36 +1826,37 @@ namespace VEPROMS.CSLA.Library // 0*E optional zeros (spare zeros) followed // ([+-]?|\\u8209\?) either an optional single character Plus (+) or Minus (-) or non-breaking dash (\u8209?) // ([0-9]+) a group of at least one digits - string retval = Regex.Replace(str, @"([+-]?|\\u8209\?)([0-9]+)[.]([0-9]*?)0*E([+-]?|\\u8209\?)([0-9]+)", new MatchEvaluator(FixFortranNumber)); - // don't convert # and ~ to super/subscripts, this is a DOS holdout and is done only for non-procedure step sections - //retval = Regex.Replace(retval, "[#](.*?)[#]", "\\up2 $1\\up0 ");// DOS Superscript - //retval = Regex.Replace(retval, "[~](.*?)[~]", "\\dn2 $1\\up0 ");// DOS Subscript - return retval; + + return Regex.Replace(str, @"([+-]?|\\u8209\?)([0-9]+)[.]([0-9]*?)0*E([+-]?|\\u8209\?)([0-9]+)", new MatchEvaluator(FixFortranNumber)); } - private static string FixFortranNumber(Match match) + + public static string FixFortranNumber(Match match) { - StringBuilder sb = new StringBuilder(match.Groups[1].Value.Replace("-",@"\u8209?")); + StringBuilder sb = new StringBuilder(match.Groups[1].Value.Replace("-", @"\u8209?")); + if (match.Groups[3].Length == 0) // Nothing to the right of the decimal + { if (match.Groups[2].Value != "1") // Other than "1", multiply it times 10 raised to a power + { sb.Append(match.Groups[2].Value + "x10"); + } else // The number is simply 1 so it can be ignored and 10 can be raised to a power + { sb.Append("10"); + } + } else // A number with a decimal point + { sb.Append(match.Groups[2].Value + "." + match.Groups[3].Value + "x10"); + } + // Add the exponent as superscript - return sb.ToString() + "\\up2 " + match.Groups[4].Value.Replace("-",@"\u8209?") + match.Groups[5].Value + "\\up0 "; + return sb.ToString() + "\\up2 " + match.Groups[4].Value.Replace("-", @"\u8209?") + match.Groups[5].Value + "\\up0 "; } + #endregion - } - [Flags] - public enum E_ROValueType : uint - { - All = 0, - Text = 1, - Table = 2, - Graph = 4, - Image = 8, - Video = 16, - Hologram = 32 + + #endregion + } }