B2022-026 RO Memory reduction coding (Jakes Merge)

This commit is contained in:
Jake 2022-06-03 19:45:42 +00:00
parent 7e0f04207c
commit 3f7cbc10bc
8 changed files with 1114 additions and 877 deletions

View File

@ -1090,7 +1090,7 @@ namespace VEPROMS
this.displayRO.Location = new System.Drawing.Point(1, 1); this.displayRO.Location = new System.Drawing.Point(1, 1);
this.displayRO.Margin = new System.Windows.Forms.Padding(4); this.displayRO.Margin = new System.Windows.Forms.Padding(4);
this.displayRO.MyROFST = null; this.displayRO.MyROFST = null;
this.displayRO.MyROFSTLookup = null; //this.displayRO.MyROFSTLookup = null;
this.displayRO.MyRTB = null; this.displayRO.MyRTB = null;
this.displayRO.Name = "displayRO"; this.displayRO.Name = "displayRO";
this.displayRO.ProgressBar = null; this.displayRO.ProgressBar = null;

File diff suppressed because it is too large Load Diff

View File

@ -8,8 +8,9 @@ using System.Data.SqlClient;
using System.Linq; using System.Linq;
using Csla.Data; using Csla.Data;
using System.Threading;
using System.Threading.Tasks;
// B2022-026 New code for RO Memory reduction - now use SQL tables instead of building dictionarys to get RO values
namespace VEPROMS.CSLA.Library namespace VEPROMS.CSLA.Library
{ {
@ -38,7 +39,7 @@ namespace VEPROMS.CSLA.Library
#region Enums #region Enums
[Flags] [Flags]
public enum SearchType public enum SearchTypes
{ {
StartsWith = 1, StartsWith = 1,
EndsWith = 2, EndsWith = 2,
@ -46,6 +47,15 @@ namespace VEPROMS.CSLA.Library
ExactMatch = 4 ExactMatch = 4
} }
public enum HeaderStatuses
{
Unknown = 0,
NotLoaded = 1,
InProgress = 2,
LoadComplete = 3,
LoadFailed = 4
}
#endregion #endregion
#region Structs / Internal Classes #region Structs / Internal Classes
@ -128,6 +138,7 @@ namespace VEPROMS.CSLA.Library
} }
}; };
#endregion #endregion
#region Fields #region Fields
@ -230,20 +241,39 @@ namespace VEPROMS.CSLA.Library
#region (RO Info) #region (RO Info)
public ROFSTLookup.rochild GetRoChild12(string ROID16, bool loadChildren = false, bool loadAllChildren = false) public bool HasChildren(ref ROFSTLookup.rochild child)
{ {
string ROID = (ROID16.Length < 12) ? ROID16 : ROID16.Substring(0, 12); LoadChildren(ref child);
return child.children.Any();
ROFSTLookup.rochild rc = RofstDataGetChildByRoid(_rofstID, ROID, loadChildren, loadAllChildren);
if (rc.ID <= 0 && ROID16.Length == 4)
{
rc.title = GetRODatabaseTitle(GetRODatabaseTitleIndex(ROID16));
} }
return rc; public bool HasChildren(ref ROFSTLookup.rodbi db)
{
LoadChildren(ref db);
return db.children.Any();
} }
public void LoadChildren(ref ROFSTLookup.rochild child)
{
// If Children is null then it hasn't been loaded yet
if (child.children == null || child.children.Length <= 0)
{
if (!string.IsNullOrEmpty(child.appid))
child = GetRoChild12(child.roid, true);
else
child.children = GetRoChildrenByRoid(child.roid, true);
}
}
public void LoadChildren(ref ROFSTLookup.rodbi db)
{
// If Children is null then it hasn't been loaded yet
if (db.children == null || db.children.Length <= 0)
db.children = GetRoChildrenByID(db.ID, db.dbiID, true);
}
public ROFSTLookup.rochild GetRoChild(string ROID, bool loadChildren = false, bool loadAllChildren = false) public ROFSTLookup.rochild GetRoChild(string ROID, bool loadChildren = false, bool loadAllChildren = false)
{ {
ROFSTLookup.rochild rc = new ROFSTLookup.rochild() { ID = -1 }; ROFSTLookup.rochild rc = new ROFSTLookup.rochild() { ID = -1 };
@ -280,6 +310,34 @@ namespace VEPROMS.CSLA.Library
} }
} }
} }
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<string> GetROReturnValue(string roval)
{
_lstRoValues = new List<string>();
_multiRoValues = new List<string>();
_dicRoVars = new Dictionary<string, string>();
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 rc; return rc;
@ -392,22 +450,6 @@ namespace VEPROMS.CSLA.Library
return sb.ToString(); return sb.ToString();
} }
public List<string> GetROReturnValue(string roval)
{
_lstRoValues = new List<string>();
_multiRoValues = new List<string>();
_dicRoVars = new Dictionary<string, string>();
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) public string GetTranslatedRoValue(string ROID16, bool DoCaret, bool DoDOSSuperSubScript)
{ {
string retval = GetRoValue(ROID16); string retval = GetRoValue(ROID16);
@ -425,6 +467,9 @@ namespace VEPROMS.CSLA.Library
return retval.Replace("\r\n", @"\par "); return retval.Replace("\r\n", @"\par ");
} }
public Dictionary<string, string> Search(string value, int searchTypeID, int? maxNumRecords = null) public Dictionary<string, string> Search(string value, int searchTypeID, int? maxNumRecords = null)
{ {
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
@ -523,7 +568,7 @@ namespace VEPROMS.CSLA.Library
rc = GetRoChild12(parentROID); rc = GetRoChild12(parentROID);
if (rc.ID > 0) sb.Insert(0, rc.title + " - "); if (rc.ID > 0) sb.Insert(0, rc.title + " - ");
} while (rc.ID > 0); } while (rc.ID > 0);?
return sb.ToString(); return sb.ToString();
} }
@ -641,6 +686,21 @@ namespace VEPROMS.CSLA.Library
#region (Database Calls) #region (Database Calls)
private bool RofstDataExists(int rofstID) private bool RofstDataExists(int rofstID)
{
int headerStatusID = RofstDataGetHeaderLoadStatus(rofstID);
while (headerStatusID == (int)HeaderStatuses.InProgress)
{
// Wait 5 sec(s) then Check Header Status Again
Thread.Sleep(5000);
headerStatusID = RofstDataGetHeaderLoadStatus(rofstID);
}
return (headerStatusID == (int)HeaderStatuses.LoadComplete); // false includes [NotLoaded = 1 || LoadFailed = 4 || Unknown = 0]
}
private int RofstDataGetHeaderLoadStatus(int rofstID)
{ {
try try
{ {
@ -650,17 +710,22 @@ namespace VEPROMS.CSLA.Library
{ {
cmd.CommandTimeout = Database.DefaultTimeout; cmd.CommandTimeout = Database.DefaultTimeout;
cmd.CommandType = CommandType.StoredProcedure; cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "vesp_RofstDataExists"; cmd.CommandText = "vesp_RofstDataGetHeaderRofstByID";
cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID; cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID;
return Convert.ToBoolean(cmd.ExecuteScalar()); using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader()))
{
if (dr.Read()) return Convert.ToInt32(dr.GetValue("RofstHeaderStatusID"));
} }
} }
} }
return 0; // Unknown Status
}
catch (Exception ex) catch (Exception ex)
{ {
throw new DbCslaException("RofstData.vesp_RofstDataExists", ex); throw new DbCslaException("RofstData.vesp_RofstDataGetHeaderRofstByID", ex);
} }
} }
@ -759,6 +824,30 @@ namespace VEPROMS.CSLA.Library
} }
} }
private void RofstHeaderFinalizeLoad(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_RofstHeaderFinalizeLoad";
cmd.Parameters.Add(new SqlParameter("@RofstID", SqlDbType.Int)).Value = rofstID;
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
throw new DbCslaException("RofstData.vesp_RofstHeaderFinalizeLoad", ex);
}
}
private void RofstDatabaseInsert(int rofstID, int dbiID, int dbiType, int dbiAW, string dbiTitle, string dbiAP, int id, int parentID) private void RofstDatabaseInsert(int rofstID, int dbiID, int dbiType, int dbiAW, string dbiTitle, string dbiAP, int id, int parentID)
{ {
try try
@ -1369,6 +1458,10 @@ namespace VEPROMS.CSLA.Library
} }
} }
} }
//Finalized Load for Rofst Header / Rebuild Indexes
RofstHeaderFinalizeLoad(rofstID);
} }
private void LoadChild(int rofstID, int dbiID, ROFSTLookup.rochild child) private void LoadChild(int rofstID, int dbiID, ROFSTLookup.rochild child)
@ -1428,7 +1521,7 @@ namespace VEPROMS.CSLA.Library
if (loadChildren || loadAllChildren) if (loadChildren || loadAllChildren)
{ {
rd.children = RofstDataGetChildrenByID(_rofstID, rd.dbiID, rd.ID, loadAllChildren); rd.children = RofstDataGetChildrenByID(_rofstID, rd.dbiID, rd.ID, false, loadAllChildren);
} }
return rd; return rd;
@ -1451,10 +1544,9 @@ namespace VEPROMS.CSLA.Library
rc.value = (string)dr.GetValue("value"); rc.value = (string)dr.GetValue("value");
ProcessROReturnValue(ref rc, rc.value, GetRODatabaseTitleIndex(rc.roid)); ProcessROReturnValue(ref rc, rc.value, GetRODatabaseTitleIndex(rc.roid));
} }
else if (loadChildren || loadAllChildren)
if (loadChildren || loadAllChildren)
{ {
rc.children = RofstDataGetChildrenByRoid(_rofstID, rc.roid, loadAllChildren); rc.children = RofstDataGetChildrenByRoid(_rofstID, rc.roid, false, loadAllChildren);
} }
return rc; return rc;
@ -1464,6 +1556,36 @@ namespace VEPROMS.CSLA.Library
#region (RO Values) #region (RO Values)
private 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;
}
private List<string> GetROReturnValue(string roval)
{
_lstRoValues = new List<string>();
_multiRoValues = new List<string>();
_dicRoVars = new Dictionary<string, string>();
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;
}
private void ProcessROReturnValue(ref ROFSTLookup.rochild child, string rawvalue, int tableID) 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, // This function will take the raw RO return value and resolve any macros, conditionals,
@ -1773,7 +1895,7 @@ namespace VEPROMS.CSLA.Library
s2 = s2.Replace("\x2190", @"\u8592?"); // Leftwards Arrow s2 = s2.Replace("\x2190", @"\u8592?"); // Leftwards Arrow
s2 = s2.Replace("\x2191", @"\u8593?"); // Upwards Arrow s2 = s2.Replace("\x2191", @"\u8593?"); // Upwards Arrow
s2 = s2.Replace("\x2193", @"\u8595?"); // Downwards Arrow s2 = s2.Replace("\x2193", @"\u8595?"); // Downwards Arrow
s2 = s2.Replace("\x2207", @"\u8711?"); // Nabla (?) s2 = s2.Replace("\x2207", @"\u8711?"); // Nabla
s2 = s2.Replace("\x2591", @"\'b0"); // Degree Symbol s2 = s2.Replace("\x2591", @"\'b0"); // Degree Symbol
s2 = s2.Replace("\xFF", @"\u8593?"); // Up Arrow s2 = s2.Replace("\xFF", @"\u8593?"); // Up Arrow
s2 = s2.Replace("\xD6", @"\u8595?"); // Down Arrow s2 = s2.Replace("\xD6", @"\u8595?"); // Down Arrow

View File

@ -449,7 +449,7 @@ namespace VEPROMS.CSLA.Library
{ {
string cfg = docver.DocVersionAssociations[0].Config; string cfg = docver.DocVersionAssociations[0].Config;
AssociationConfig ac = new AssociationConfig((cfg== null || cfg.Length == 0) ? "<Config />" : cfg); AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg);
ac.ROUpdate_LastCompleted = value; ac.ROUpdate_LastCompleted = value;
docver.DocVersionAssociations[0].Config = ac.ToString(); docver.DocVersionAssociations[0].Config = ac.ToString();
docver.Save(); docver.Save();
@ -460,7 +460,7 @@ namespace VEPROMS.CSLA.Library
{ {
string cfg = docver.DocVersionAssociations[0].Config; string cfg = docver.DocVersionAssociations[0].Config;
AssociationConfig ac = new AssociationConfig((cfg== null || cfg.Length == 0) ? "<Config />" : cfg); AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg);
ac.ROUpdate_LoadingFigures = value; ac.ROUpdate_LoadingFigures = value;
docver.DocVersionAssociations[0].Config = ac.ToString(); docver.DocVersionAssociations[0].Config = ac.ToString();
docver.Save(); docver.Save();
@ -515,7 +515,7 @@ namespace VEPROMS.CSLA.Library
List<string> ChangedFiles = GetChangedFigures(origROFst, rofst, myProgressBarRefresh); List<string> ChangedFiles = GetChangedFigures(origROFst, rofst, myProgressBarRefresh);
// Get ROID associated with FileNames // Get ROID associated with FileNames
List<string> ROIDs = GetROIDsFromLookup(rofst,ChangedFiles,docver); List<string> ROIDs = GetROIDsFromLookup(rofst, ChangedFiles, docver);
return ROIDs; return ROIDs;
} }
@ -562,7 +562,7 @@ namespace VEPROMS.CSLA.Library
{ {
if (origROFst.ROFstFigures == null) return null; if (origROFst.ROFstFigures == null) return null;
Dictionary<string,int> orig = new Dictionary<string,int>(); Dictionary<string, int> orig = new Dictionary<string, int>();
int i = 0; int i = 0;
foreach (FigureInfo fi in origROFst.ROFstFigures) foreach (FigureInfo fi in origROFst.ROFstFigures)
@ -596,9 +596,9 @@ namespace VEPROMS.CSLA.Library
return changedFigures; return changedFigures;
} }
private static Dictionary<string,int> BuildROImagesList(ROImageInfoList myROImages) private static Dictionary<string, int> BuildROImagesList(ROImageInfoList myROImages)
{ {
Dictionary<string,int> myRoImagesList = new Dictionary<string,int>(); Dictionary<string, int> myRoImagesList = new Dictionary<string, int>();
foreach (ROImageInfo myROImage in myROImages) foreach (ROImageInfo myROImage in myROImages)
{ {
@ -790,7 +790,7 @@ namespace VEPROMS.CSLA.Library
} }
} }
if (myProgressBarRefresh != null) myProgressBarRefresh(100,100, "RO Values Updated"); if (myProgressBarRefresh != null) myProgressBarRefresh(100, 100, "RO Values Updated");
} }
private static DateTime ShowDuration(DateTime dtLast, string message) private static DateTime ShowDuration(DateTime dtLast, string message)
@ -837,7 +837,7 @@ namespace VEPROMS.CSLA.Library
private static string GetRoidList(int dbid, List<string> chgList) private static string GetRoidList(int dbid, List<string> chgList)
{ {
StringBuilder sb = new StringBuilder(string.Format("{0}", dbid)); StringBuilder sb = new StringBuilder(string.Format("{0}", dbid));
string sep=":"; string sep = ":";
foreach (string roid in chgList) foreach (string roid in chgList)
{ {

View File

@ -82,7 +82,7 @@ namespace VEPROMS.CSLA.Library
ROFSTLookup lu = MyDocVersion.DocVersionAssociations[0].MyROFst.GetROFSTLookup(MyDocVersion); ROFSTLookup lu = MyDocVersion.DocVersionAssociations[0].MyROFst.GetROFSTLookup(MyDocVersion);
foreach (ROCheck roc in MyDifferences.ROConsistency.MyROChecks) foreach (ROCheck roc in MyDifferences.ROConsistency.MyROChecks)
{ {
ROFSTLookup.rochild rocc = lu.GetRoChild12(roc.ROID); ROFSTLookup.rochild rocc = lu.GetRoChild(roc.ROID);
if (rocc.ID == -1) // B2020-125: View of Consistency check report displaying error message and crashing. if (rocc.ID == -1) // B2020-125: View of Consistency check report displaying error message and crashing.
{ {
sb.Append(string.Format(" {0}\r\n", lu.GetROTitle(roc.ROID))); sb.Append(string.Format(" {0}\r\n", lu.GetROTitle(roc.ROID)));

View File

@ -135,11 +135,6 @@ namespace VEPROMS.CSLA.Library
get get
{ {
CanReadProperty("ROLookup", true); CanReadProperty("ROLookup", true);
//if (_ROLookup == null)
//{
// _ROLookup = ROFSTLookup.GetRofstLookupBytes(_ROFstID);
//}
//return _ROLookup;
// B2022-026 RO Memory reduction // B2022-026 RO Memory reduction
return null; return null;

File diff suppressed because it is too large Load Diff

View File

@ -339,7 +339,7 @@ namespace Volian.Print.Library
{ {
foreach (ROCheck roc in pi.MyDifferences.ROConsistency.MyROChecks) foreach (ROCheck roc in pi.MyDifferences.ROConsistency.MyROChecks)
{ {
ROFSTLookup.rochild rocc = lu.GetRoChild12(roc.ROID); ROFSTLookup.rochild rocc = lu.GetRoChild(roc.ROID);
if (rocc.type == 1) if (rocc.type == 1)
{ {
string newROValue = lu.GetRoValue(roc.ROID).Replace('`', '\xb0'); string newROValue = lu.GetRoValue(roc.ROID).Replace('`', '\xb0');