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

@@ -8,8 +8,9 @@ using System.Data.SqlClient;
using System.Linq;
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
{
@@ -38,7 +39,7 @@ namespace VEPROMS.CSLA.Library
#region Enums
[Flags]
public enum SearchType
public enum SearchTypes
{
StartsWith = 1,
EndsWith = 2,
@@ -46,6 +47,15 @@ namespace VEPROMS.CSLA.Library
ExactMatch = 4
}
public enum HeaderStatuses
{
Unknown = 0,
NotLoaded = 1,
InProgress = 2,
LoadComplete = 3,
LoadFailed = 4
}
#endregion
#region Structs / Internal Classes
@@ -128,6 +138,7 @@ namespace VEPROMS.CSLA.Library
}
};
#endregion
#region Fields
@@ -230,20 +241,39 @@ namespace VEPROMS.CSLA.Library
#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);
ROFSTLookup.rochild rc = RofstDataGetChildByRoid(_rofstID, ROID, loadChildren, loadAllChildren);
if (rc.ID <= 0 && ROID16.Length == 4)
{
rc.title = GetRODatabaseTitle(GetRODatabaseTitleIndex(ROID16));
}
return rc;
LoadChildren(ref child);
return child.children.Any();
}
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)
{
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;
@@ -392,22 +450,6 @@ namespace VEPROMS.CSLA.Library
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)
{
string retval = GetRoValue(ROID16);
@@ -425,6 +467,9 @@ namespace VEPROMS.CSLA.Library
return retval.Replace("\r\n", @"\par ");
}
public Dictionary<string, string> Search(string value, int searchTypeID, int? maxNumRecords = null)
{
if (string.IsNullOrEmpty(value))
@@ -523,7 +568,7 @@ namespace VEPROMS.CSLA.Library
rc = GetRoChild12(parentROID);
if (rc.ID > 0) sb.Insert(0, rc.title + " - ");
} while (rc.ID > 0);
} while (rc.ID > 0);?
return sb.ToString();
}
@@ -641,6 +686,21 @@ namespace VEPROMS.CSLA.Library
#region (Database Calls)
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
{
@@ -650,17 +710,22 @@ namespace VEPROMS.CSLA.Library
{
cmd.CommandTimeout = Database.DefaultTimeout;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "vesp_RofstDataExists";
cmd.CommandText = "vesp_RofstDataGetHeaderRofstByID";
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)
{
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)
{
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)
@@ -1428,7 +1521,7 @@ namespace VEPROMS.CSLA.Library
if (loadChildren || loadAllChildren)
{
rd.children = RofstDataGetChildrenByID(_rofstID, rd.dbiID, rd.ID, loadAllChildren);
rd.children = RofstDataGetChildrenByID(_rofstID, rd.dbiID, rd.ID, false, loadAllChildren);
}
return rd;
@@ -1451,10 +1544,9 @@ namespace VEPROMS.CSLA.Library
rc.value = (string)dr.GetValue("value");
ProcessROReturnValue(ref rc, rc.value, GetRODatabaseTitleIndex(rc.roid));
}
if (loadChildren || loadAllChildren)
else if (loadChildren || loadAllChildren)
{
rc.children = RofstDataGetChildrenByRoid(_rofstID, rc.roid, loadAllChildren);
rc.children = RofstDataGetChildrenByRoid(_rofstID, rc.roid, false, loadAllChildren);
}
return rc;
@@ -1464,6 +1556,36 @@ namespace VEPROMS.CSLA.Library
#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)
{
// 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("\x2191", @"\u8593?"); // Upwards 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("\xFF", @"\u8593?"); // Up Arrow
s2 = s2.Replace("\xD6", @"\u8595?"); // Down Arrow