CSLA - Extension

This commit is contained in:
2026-09-01 08:21:41 -04:00
parent dcd2fbc294
commit dab65dbfb6
30 changed files with 2703 additions and 5680 deletions
+111 -208
View File
@@ -10,12 +10,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.XPath;
using System.Text.RegularExpressions;
using System.Data;
using System.Data.SqlClient;
@@ -30,9 +26,6 @@ namespace VEPROMS.CSLA.Library
{
public static ROFst GetJustROFst(int rOFstID)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a ROFst");
try
{
ROFst tmp = GetCachedByPrimaryKey(rOFstID);
@@ -59,14 +52,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteriaJustROFst
{
private int _ROFstID;
public int ROFstID
{ get { return _ROFstID; } }
public PKCriteriaJustROFst(int rOFstID)
{
_ROFstID = rOFstID;
}
}
private readonly int _ROFstID;
public int ROFstID => _ROFstID;
public PKCriteriaJustROFst(int rOFstID) => _ROFstID = rOFstID;
}
private void DataPortal_Fetch(PKCriteriaJustROFst criteria)
{
@@ -111,30 +100,22 @@ namespace VEPROMS.CSLA.Library
public partial class ROFstInfo
{
#region Log4Net
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
[Serializable()]
protected class PKCriteriaJustROFst
{
private int _ROFstID;
public int ROFstID
{ get { return _ROFstID; } }
public PKCriteriaJustROFst(int rOFstID)
{
_ROFstID = rOFstID;
}
}
private readonly int _ROFstID;
public int ROFstID => _ROFstID;
public PKCriteriaJustROFst(int rOFstID) => _ROFstID = rOFstID;
}
#region Fields
// this is used by the frmBatchRefresh which is the Adim Tools so that one message is display for a group of procedure sets processed
public static StringBuilder MessageList = null;
private static List<int> DocVersionsNeedingROUpdate = new List<int>();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<int> DocVersionsNeedingROUpdate = new List<int>();
#endregion
@@ -142,23 +123,19 @@ namespace VEPROMS.CSLA.Library
public event ROFstInfoROTableUpdateEvent ROTableUpdate;
#endregion
#endregion
#region Public Methods
#region Public Methods
// B2022-107: Display Progress Bar Messages/Statuses when a new ROFST binary file is loaded into the database
public ROFSTLookup GetROFSTLookup(DocVersionInfo dvi, string ovrrideChild = null, bool showLoadingStatus = true) => new ROFSTLookup(this.ROFstID, dvi, ovrrideChild, showLoadingStatus);
public ROFSTLookup GetROFSTLookup(DocVersionInfo dvi, string ovrrideChild = null, bool showLoadingStatus = true)
{
// B2022-107: Display Progress Bar Messages/Statuses when a new ROFST binary file is loaded into the database
return new ROFSTLookup(this.ROFstID, dvi, ovrrideChild, showLoadingStatus);
}
/// <summary>
/// Adds an ro.fst into a sql database.
/// </summary>
/// <param name="rdi" - the Rodb to use as the path for updating the ro.fst, i.e. import from there.
/// <param name="docver" - hook into this doc version></param>
/// <returns>ROFst: Returns the created rofst object</returns>
public static ROFst AddRoFst(RODbInfo rdi, DocVersion docver, ROFstInfoProgressBarRefresh myProgressBarRefresh)
/// <summary>
/// Adds an ro.fst into a sql database.
/// </summary>
/// <param name="rdi" - the Rodb to use as the path for updating the ro.fst, i.e. import from there.
/// <param name="docver" - hook into this doc version></param>
/// <returns>ROFst: Returns the created rofst object</returns>
public static ROFst AddRoFst(RODbInfo rdi, DocVersion docver, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{
string rofstfilepath = rdi.FolderPath + @"\ro.fst";
DirectoryInfo di = new DirectoryInfo(rdi.FolderPath);
@@ -218,9 +195,11 @@ namespace VEPROMS.CSLA.Library
}
if (myUnChangedROImages.Count > 0)
using (FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID, buildImageIDString(myUnChangedROImages))) ;
#pragma warning disable CS0642 // Possible mistaken empty statement - valid - keeps scope of add
using (FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID, buildImageIDString(myUnChangedROImages))) ;
#pragma warning restore CS0642 // Possible mistaken empty statement
return rofst;
return rofst;
}
}
}
@@ -252,8 +231,7 @@ namespace VEPROMS.CSLA.Library
TimeSpan ts = DateTime.Now - start;
if (tbStatus != null)
tbStatus.AppendText(string.Format("Procedure: {1}{0}, Checked {2} Referenced Objects{0}, Fixed {3} Referenced Objects{0}, Elapsed Seconds:{4}{0}{0}", Environment.NewLine, itm.MyProcedure.DisplayNumber, ItemInfo.ROCheckCount, ItemInfo.ROFixCount, ts.TotalSeconds));
tbStatus?.AppendText(string.Format("Procedure: {1}{0}, Checked {2} Referenced Objects{0}, Fixed {3} Referenced Objects{0}, Elapsed Seconds:{4}{0}{0}", Environment.NewLine, itm.MyProcedure.DisplayNumber, ItemInfo.ROCheckCount, ItemInfo.ROFixCount, ts.TotalSeconds));
}
//Update the DocVersion Associations to link to the new RO FST id and current date/time
@@ -288,8 +266,7 @@ namespace VEPROMS.CSLA.Library
DocVersionInfo dvi = DocVersionInfo.Get(proc.MyDocVersion.VersionID);
if (dvi.DocVersionConfig.SelectedSlave <= 0)
{
int i = 0;
DateTime start = DateTime.Now;
DateTime start = DateTime.Now;
ProcedureInfo.ResetCheckROLinkCounters();
ProcedureInfo.CheckReferenceObjectsLinks(proc);
@@ -297,8 +274,7 @@ namespace VEPROMS.CSLA.Library
TimeSpan ts = DateTime.Now - start;
if (tbStatus != null)
tbStatus.AppendText(string.Format("Procedure: {1}{0}, Checked {2} Referenced Objects Links{0}, Found {3} Bad RO Links{0} Elapsed Seconds:{5}{0}{0}", Environment.NewLine, proc.DisplayNumber, ProcedureInfo.CheckROLinksCount, ProcedureInfo.BadROLinksCount, ProcedureInfo.FixedROLinksCount, ts.TotalSeconds));
tbStatus?.AppendText(string.Format("Procedure: {1}{0}, Checked {2} Referenced Objects Links{0}, Found {3} Bad RO Links{0} Elapsed Seconds:{5}{0}{0}", Environment.NewLine, proc.DisplayNumber, ProcedureInfo.CheckROLinksCount, ProcedureInfo.BadROLinksCount, ProcedureInfo.FixedROLinksCount, ts.TotalSeconds));
/*** keep for now - incase we decide to fix RO links later on, this will show the number of RO Links that we fixed
//tbStatus.AppendText(string.Format("Procedure: {1}{0}, Checked {2} Referenced Objects Links{0}, Found {3} Bad RO Links{0}, Fixed {4} Bad RO Links{0} Elapsed Seconds:{5}{0}{0}", Environment.NewLine, proc.DisplayNumber, ProcedureInfo.CheckROLinksCount, ProcedureInfo.BadROLinksCount, ProcedureInfo.FixedROLinksCount, ts.TotalSeconds));
***/
@@ -330,9 +306,9 @@ namespace VEPROMS.CSLA.Library
{
ROWorkingDraftAsk.ClearWorkingDrafts();
if (myProgressBarRefresh != null) myProgressBarRefresh(0, 100, "Starting Update");
myProgressBarRefresh?.Invoke(0, 100, "Starting Update");
int origFSTid = origROFst.ROFstID;
int origFSTid = origROFst.ROFstID;
DirectoryInfo di = new DirectoryInfo(rdi.FolderPath);
string rofstfilepath = rdi.FolderPath + @"\ro.fst";
@@ -346,16 +322,15 @@ namespace VEPROMS.CSLA.Library
if (rofst != null)
{
// Get a list of figures which have changed content (DTS)
List<string> MyChangedFigureROIDs = null;
if (docver.ROfstLoadingFigures) // B2017-125 see if loading figures was completed
{
ROFSTLookup myLookup = new ROFSTLookup(rofst.ROFstID, DocVersionInfo.Get(docver.VersionID));
MyChangedFigureROIDs = UpdateROFigures(rdi, myProgressBarRefresh, rofst, RODb.GetJustRoDb(rdi.RODbID), myLookup, docver);
_ = UpdateROFigures(rdi, myProgressBarRefresh, rofst, RODb.GetJustRoDb(rdi.RODbID), myLookup, docver);
}
else
{
MyChangedFigureROIDs = GetChangedFigureROIDs(origROFst, ROFstInfo.GetJustROFst(rofst.ROFstID), DocVersionInfo.Get(docver.VersionID), myProgressBarRefresh);
_ = GetChangedFigureROIDs(origROFst, ROFstInfo.GetJustROFst(rofst.ROFstID), DocVersionInfo.Get(docver.VersionID), myProgressBarRefresh);
}
docver.DocVersionAssociations[0].MyROFst = rofst;
@@ -404,18 +379,11 @@ namespace VEPROMS.CSLA.Library
return false;
}
public ROFst GetJustROFst()
{
return ROFst.GetJustROFst(ROFstID);
}
public ROFst GetJustROFst() => ROFst.GetJustROFst(ROFstID);
public List<string> OnROTableUpdate(object sender, ROFstInfoROTableUpdateEventArgs args)
{
if (ROTableUpdate != null) return ROTableUpdate(sender, args);
return null;
}
public List<string> OnROTableUpdate(object sender, ROFstInfoROTableUpdateEventArgs args) => ROTableUpdate != null ? ROTableUpdate(sender, args) : null;
public static ROFstInfo GetJustROFst(int rOFstID)
public static ROFstInfo GetJustROFst(int rOFstID)
{
try
{
@@ -433,11 +401,6 @@ namespace VEPROMS.CSLA.Library
tmp = null;
}
if (tmp != null)
{
tmp.ClearROLookupBytes();
}
return tmp;
}
catch (Exception ex)
@@ -481,9 +444,11 @@ namespace VEPROMS.CSLA.Library
{
string cfg = docver.DocVersionAssociations[0].Config;
AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg);
ac.ROUpdate_LastCompleted = value;
docver.DocVersionAssociations[0].Config = ac.ToString();
AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg)
{
ROUpdate_LastCompleted = value
};
docver.DocVersionAssociations[0].Config = ac.ToString();
docver.Save();
}
@@ -494,9 +459,11 @@ namespace VEPROMS.CSLA.Library
if (docver.DocVersionAssociations[0]?.MyROFst != null && value != -1)
{
string cfg = docver.DocVersionAssociations[0].Config;
AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg);
ac.ROUpdate_PrevROFSTID = value.ToString();
docver.DocVersionAssociations[0].Config = ac.ToString();
AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg)
{
ROUpdate_PrevROFSTID = value.ToString()
};
docver.DocVersionAssociations[0].Config = ac.ToString();
docver.Save();
}
}
@@ -506,9 +473,11 @@ namespace VEPROMS.CSLA.Library
{
string cfg = docver.DocVersionAssociations[0].Config;
AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg);
ac.ROUpdate_LoadingFigures = value;
docver.DocVersionAssociations[0].Config = ac.ToString();
AssociationConfig ac = new AssociationConfig((cfg == null || cfg.Length == 0) ? "<Config />" : cfg)
{
ROUpdate_LoadingFigures = value
};
docver.DocVersionAssociations[0].Config = ac.ToString();
docver.Save();
}
@@ -539,8 +508,10 @@ namespace VEPROMS.CSLA.Library
// Add references for existing RO Images to the Figure table (Figure table relates ro.fst with its images)
if (myUnChangedROImages.Count > 0)
using (FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID, buildImageIDString(myUnChangedROImages))) ;
}
#pragma warning disable CS0642 // Possible mistaken empty statement - valid keeps scope of add
using (FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID, buildImageIDString(myUnChangedROImages))) ;
#pragma warning restore CS0642 // Possible mistaken empty statement
}
SetAssociationROFiguresLoading(docVer, string.Empty); // B2017-125 loading RO Figures is completed
@@ -662,12 +633,9 @@ namespace VEPROMS.CSLA.Library
return myRoImagesList;
}
private static string ROImageKey(string fileName, DateTime dts)
{
return string.Format("{0}:{1}", fileName, dts);
}
private static string ROImageKey(string fileName, DateTime dts) => string.Format("{0}:{1}", fileName, dts);
private static string buildImageIDString(List<int> myROImageIDs)
private static string buildImageIDString(List<int> myROImageIDs)
{
StringBuilder sb = new StringBuilder();
@@ -687,61 +655,6 @@ namespace VEPROMS.CSLA.Library
return sb.ToString();
}
private static DateTime ShowDuration(DateTime dtLast, string message)
{
DateTime dtNext = DateTime.Now;
Console.WriteLine("{0,10:#####0.00},'{1}'", TimeSpan.FromTicks(dtNext.Ticks - dtLast.Ticks).TotalSeconds, message);
return dtNext;
}
private static List<string> BuildActiveROIDsForRoUsages12(string RoidList, string versions)
{
List<string> activeRoids = new List<string>();
using (RoUsageInfoList activeList = RoUsageInfoList.GetROUSagesByROIDsAndVersions(RoidList, versions))
{
foreach (RoUsageInfo roui in activeList)
{
string roid = roui.ROID.ToUpper().Substring(0, 12);
if (!activeRoids.Contains(roid))
activeRoids.Add(roid);
}
}
return activeRoids;
}
private static List<string> BuildActiveROIDsForDRoUsages12(string RoidList, string versions)
{
List<string> activeRoids = new List<string>();
using (DROUsageInfoList activeList = DROUsageInfoList.GetDROUsagesByROIDsAndVersions(RoidList, versions))
{
foreach (DROUsageInfo roui in activeList)
{
string roid = roui.ROID.Substring(0, 12);
if (!activeRoids.Contains(roid))
activeRoids.Add(roid);
}
}
return activeRoids;
}
private static string GetRoidList(int dbid, List<string> chgList)
{
StringBuilder sb = new StringBuilder(string.Format("{0}", dbid));
string sep = ":";
foreach (string roid in chgList)
{
sb.Append(sep + roid);
sep = ",";
}
return sb.ToString();
}
// B2022-026 RO Memory Reduction code - all rochild types passed in are of type image (graphics)
private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages, List<string> MyChangedFigureROIDs, ROFstInfoProgressBarRefresh myProgressBarRefresh, int cnt, ref int curCnt)
{
@@ -771,64 +684,65 @@ namespace VEPROMS.CSLA.Library
}
string imgfile = rdi.FolderPath + @"\" + fname;
if (File.Exists(imgfile))
{
FileInfo fi = new FileInfo(imgfile);
ROImage roImg = null;
// if the roimage record exists, don't create a new one...
string key = ROImageKey(imgname, fi.LastWriteTimeUtc);
if (File.Exists(imgfile))
{
FileInfo fi = new FileInfo(imgfile);
if (myExistingROImages.ContainsKey(key))
{
int imageID = myExistingROImages[key];
if (!myUnChangedROImages.Contains(imageID))
myUnChangedROImages.Add(imageID);
}
else
{
if (!myAddedROImages.Contains(key))
{
myProgressBarRefresh(curCnt, cnt, "Loading " + imgname); // show progress of loading images
// if the roimage record exists, don't create a new one...
string key = ROImageKey(imgname, fi.LastWriteTimeUtc);
FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);
r.Close();
fsIn.Close();
if (myExistingROImages.ContainsKey(key))
{
int imageID = myExistingROImages[key];
if (!myUnChangedROImages.Contains(imageID))
myUnChangedROImages.Add(imageID);
}
else
{
if (!myAddedROImages.Contains(key))
{
myProgressBarRefresh(curCnt, cnt, "Loading " + imgname); // show progress of loading images
byte[] cmp = ROImageInfo.Compress(ab);
int existingImageID = FindExisting(myExistingROImages, imgname, imgfile, cmp, ab);
FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);
r.Close();
fsIn.Close();
if (existingImageID != 0)
{
if (!myUnChangedROImages.Contains(existingImageID))
{
myUnChangedROImages.Add(existingImageID);
}
byte[] cmp = ROImageInfo.Compress(ab);
int existingImageID = FindExisting(myExistingROImages, imgname, imgfile, cmp, ab);
return;
}
if (existingImageID != 0)
{
if (!myUnChangedROImages.Contains(existingImageID))
{
myUnChangedROImages.Add(existingImageID);
}
ROImageConfig rc = new ROImageConfig
{
Image_Size = ab.Length.ToString()
};
return;
}
ROImageConfig rc = new ROImageConfig();
rc.Image_Size = ab.Length.ToString();
using (roImg = ROImage.MakeROImage(rodb, imgname, ROImageInfo.Compress(ab), rc.ToString(), fi.LastWriteTimeUtc, "Migration"))
{
using (Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID))
{
if (figure != null) return;
Figure.MakeFigure(rofst, roImg, null).Dispose();
myAddedROImages.Add(key);
MyChangedFigureROIDs.Add(myRO.roid); // Save the roid so that the related documents will be refeshed. (PDF will be deleted)
}
}
}
}
}
}
ROImage roImg;
using (roImg = ROImage.MakeROImage(rodb, imgname, ROImageInfo.Compress(ab), rc.ToString(), fi.LastWriteTimeUtc, "Migration"))
{
using (Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID))
{
if (figure != null) return;
Figure.MakeFigure(rofst, roImg, null).Dispose();
myAddedROImages.Add(key);
MyChangedFigureROIDs.Add(myRO.roid); // Save the roid so that the related documents will be refeshed. (PDF will be deleted)
}
}
}
}
}
}
private int FindExisting(Dictionary<string, int> myExistingROImages, string imgname, string imgfile, byte[] cmpFileContents, byte[] fileContents)
{
@@ -940,22 +854,12 @@ namespace VEPROMS.CSLA.Library
public class ROFstInfoROTableUpdateEventArgs
{
private string _ROText;
public string ROText
public string ROText { get; set; }
public string OldGridXml { get; set; }
public ROFstInfoROTableUpdateEventArgs(string rotext, string oldgridxml)
{
get { return _ROText; }
set { _ROText = value; }
}
private string _OldGridXml;
public string OldGridXml
{
get { return _OldGridXml; }
set { _OldGridXml = value; }
}
public ROFstInfoROTableUpdateEventArgs(string rotext, string oldgridxml)
{
_ROText = rotext;
_OldGridXml = oldgridxml;
ROText = rotext;
OldGridXml = oldgridxml;
}
}
@@ -1045,7 +949,6 @@ namespace VEPROMS.CSLA.Library
}
}
//GC.Collect();
return isDifferent;
}
catch (Exception ex)