Removed debug output

Added Progress Bar output
Improved RO Value Update Performance
Fix Ro Update Logic
This commit is contained in:
Rich 2015-02-10 15:51:04 +00:00
parent 7d2273d0d1
commit 2cfc430128
2 changed files with 169 additions and 71 deletions

View File

@ -174,7 +174,7 @@ namespace VEPROMS.CSLA.Library
}
lastIndex = mm.Index + mm.Length;
}
Console.WriteLine("Text: {0} NewText: {1}", Text, newText);
//Console.WriteLine("Text: {0} NewText: {1}", Text, newText);
return retval;
}
public string ConvertTransitionToText(int tranID, int tranType, string value)
@ -230,7 +230,7 @@ namespace VEPROMS.CSLA.Library
}
lastIndex = mm.Index + mm.Length;
}
Console.WriteLine("Text: {0} NewText: {1}", Text, newText);
//Console.WriteLine("Text: {0} NewText: {1}", Text, newText);
return retval;
}
private string GetMySuffix(int start)
@ -327,7 +327,7 @@ namespace VEPROMS.CSLA.Library
}
lastIndex = mm.Index + mm.Length;
}
Console.WriteLine("Text: {0} NewText: {1}", Text, newText);
//Console.WriteLine("Text: {0} NewText: {1}", Text, newText);
// see if there is a grid to update too.
if (rousg.MyContent.MyGrid != null)
{

View File

@ -21,6 +21,7 @@ using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Volian.Base.Library;
namespace VEPROMS.CSLA.Library
{
@ -127,6 +128,7 @@ namespace VEPROMS.CSLA.Library
}
public delegate List<string> ROFstInfoROTableUpdateEvent(object sender, ROFstInfoROTableUpdateEventArgs args);
public delegate void ROFstInfoProgressBarRefresh(int value, int max, string text);
public partial class ROFstInfo
{
// put in for debug
@ -214,7 +216,7 @@ namespace VEPROMS.CSLA.Library
/// 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)
public static ROFst AddRoFst(RODbInfo rdi, DocVersion docver, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{
string rofstfilepath = rdi.FolderPath + @"\ro.fst";
DirectoryInfo di = new DirectoryInfo(rdi.FolderPath);
@ -259,7 +261,7 @@ namespace VEPROMS.CSLA.Library
{
using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID))
{
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);// TODO: Need to add MyImages
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages,myProgressBarRefresh);// TODO: Need to add MyImages
}
}
}
@ -280,8 +282,9 @@ namespace VEPROMS.CSLA.Library
/// the current one.
/// <param name="docver" - hook into this doc version></param>
/// <returns>ROFst: Returns the created rofst object</returns>
public static ROFst UpdateRoFst(RODbInfo rdi, DocVersionAssociation dva, DocVersion docver, ROFstInfo origROFst)
public static ROFst UpdateRoFst(RODbInfo rdi, DocVersionAssociation dva, DocVersion docver, ROFstInfo origROFst, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{
if (myProgressBarRefresh != null) myProgressBarRefresh(0, 100, "Starting Update");
DirectoryInfo di = new DirectoryInfo(rdi.FolderPath);
string rofstfilepath = rdi.FolderPath + @"\ro.fst";
FileStream fsIn = new FileStream(rofstfilepath, FileMode.Open, FileAccess.Read, FileShare.Read);
@ -294,7 +297,7 @@ namespace VEPROMS.CSLA.Library
docver.DocVersionAssociations[0].MyROFst = rofst;
docver.Save();
if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO"))
UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID));
UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh);
return rofst;
}
@ -324,7 +327,7 @@ namespace VEPROMS.CSLA.Library
// walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8:
if (myLookup.myHdr.myDbs[i].children != null)
{
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages,myProgressBarRefresh);
}
}
}
@ -335,7 +338,7 @@ namespace VEPROMS.CSLA.Library
// Now update the usages: compare old to new rofsts and update usages accordingly, i.e. modified
// values, deleted ros, etc.
if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO"))
UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID));
UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh);
return rofst;
}
}
@ -361,8 +364,9 @@ namespace VEPROMS.CSLA.Library
}
return sb.ToString();
}
private static void UpdateROValuesText(ROFstInfo origROFstInfo, ROFst newROFst, DocVersionInfo dvi)
private static void UpdateROValuesText(ROFstInfo origROFstInfo, ROFst newROFst, DocVersionInfo dvi, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{
if (myProgressBarRefresh != null) myProgressBarRefresh(0, 100, "Update Ro Values");
string versionList = dvi.VersionID.ToString();
//DateTime dtStart = DateTime.Now;
//DateTime dtLast = DateTime.Now;
@ -375,27 +379,94 @@ namespace VEPROMS.CSLA.Library
//dtLast = ShowDuration(dtLast, "chgList");
string RoidList = GetRoidList(newROFst.RODbID, chgList);
//dtLast = ShowDuration(dtLast, "RoidList");
List<string> activeRoids = BuildActiveROIDsForRoUsages(RoidList, versionList);
if (myProgressBarRefresh != null) myProgressBarRefresh(0, chgList.Count, "Getting List of ROs Used");
List<string> activeRoids = BuildActiveROIDsForRoUsages12(RoidList, versionList);
//dtLast = ShowDuration(dtLast, "activeRoids");
foreach (string chg in chgList)
if (myProgressBarRefresh != null) myProgressBarRefresh(0, chgList.Count, "Updating RO Values");
int iCount = 0;
if (activeRoids.Count > 0)
{
if (activeRoids.Contains(chg))
foreach (string chg in chgList)
{
ROFSTLookup.rochild roch = newLU.GetRoChild(chg);
string desc = string.Format("Change in RO Values: Old value = {0}, New value = {1}", origLU.GetRoValue(chg), roch.value);
// roid's are stored in database as 16 characters long in the rousages table. They may be stored
// as 12 characters in the ro.fst.
string padroid = chg.Length <= 12 ? chg + "0000" : chg;
using (RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed", versionList))
if (myProgressBarRefresh != null) myProgressBarRefresh(++iCount, chgList.Count, "Updating RO Values");
if (activeRoids.Contains(chg.Substring(0, 12)))
{
foreach (RoUsageInfo roUsg in affected)
ROFSTLookup.rochild roch = newLU.GetRoChild(chg);
string desc = string.Format("Change in RO Values: Old value = {0}, New value = {1}", origLU.GetRoValue(chg), roch.value);
// roid's are stored in database as 16 characters long in the rousages table. They may be stored
// as 12 characters in the ro.fst.
string padroid = chg.Length <= 12 ? chg + "0000" : chg;
using (RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed", versionList))
{
using (Content content = Content.Get(roUsg.MyContent.ContentID))
foreach (RoUsageInfo roUsg in affected)
{
foreach (ItemInfo ii in roUsg.MyContent.ContentItems)
using (Content content = Content.Get(roUsg.MyContent.ContentID))
{
string val = newLU.GetTranslatedRoValue(padroid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
content.FixContentText(roUsg, val, roch.type, origROFstInfo);
foreach (ItemInfo ii in roUsg.MyContent.ContentItems)
{
string val = newLU.GetTranslatedRoValue(padroid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
content.FixContentText(roUsg, val, roch.type, origROFstInfo);
if (content.IsDirty)
{
// Update UserID and DTS when RO Value is updated.
content.UserID = Volian.Base.Library.VlnSettings.UserID;
content.DTS = DateTime.Now;
content.Save();
}
}
}
}
}
}
}
}
//dtLast = ShowDuration(dtLast, "chg loop");
if (myProgressBarRefresh != null) myProgressBarRefresh(0, chgList.Count, "Getting List of ROs Used");
List<string> activeDRoids = BuildActiveROIDsForDRoUsages12(RoidList, versionList);
//dtLast = ShowDuration(dtLast, "activeRoids Doc");
iCount = 0;
if (activeDRoids.Count > 0)
{
foreach (string chg in chgList)
{
string padroid = chg.Length <= 12 ? chg + "0000" : chg;
if (myProgressBarRefresh != null) myProgressBarRefresh(++iCount, chgList.Count, "Updating DRO Values");
if (activeDRoids.Contains(chg.Substring(0, 12)))
{
ROFSTLookup.rochild roch = newLU.GetRoChild(chg);
string desc = string.Format("Change in RO Values: Old value = {0}, New value = {1}", origLU.GetRoValue(chg), roch.value);
// roid's are stored in database as 16 characters long in the rousages table. They may be stored
// as 12 characters in the ro.fst.
using (DROUsageInfoList affected = DROUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed", versionList))
{
foreach (DROUsageInfo droUsg in affected)
{
Pdf.DeleteAll(droUsg.DocID);
}
}
}
}
}
iCount = 0;
string RoidDelList = GetRoidList(newROFst.RODbID, delList);
if (myProgressBarRefresh != null) myProgressBarRefresh(0, chgList.Count, "Getting List of ROs Used");
activeRoids = BuildActiveROIDsForRoUsages12(RoidDelList, versionList);
if (activeRoids.Count > 0)
{
foreach (string del in delList)
{
string padroiddel = del.Length <= 12 ? del + "0000" : del;
if (myProgressBarRefresh != null) myProgressBarRefresh(++iCount, chgList.Count, "Removing Old RO Values");
string desc = string.Format("Deleted RO: Value = {0}", origLU.GetRoValue(del));
if (activeRoids.Contains(del.Substring(0, 12).ToUpper()))
{
using (RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted", versionList))
{
foreach (RoUsageInfo roUsg in affected)
{
using (Content content = Content.Get(roUsg.MyContent.ContentID))
{
content.FixContentText(roUsg, "?", 0, origROFstInfo);
if (content.IsDirty)
{
// Update UserID and DTS when RO Value is updated.
@ -409,59 +480,29 @@ namespace VEPROMS.CSLA.Library
}
}
}
//dtLast = ShowDuration(dtLast, "chg loop");
activeRoids = BuildActiveROIDsForDRoUsages(RoidList, versionList);
//dtLast = ShowDuration(dtLast, "activeRoids Doc");
foreach (string chg in chgList)
if (myProgressBarRefresh != null) myProgressBarRefresh(0, chgList.Count, "Getting List of ROs Used");
activeDRoids = BuildActiveROIDsForDRoUsages12(RoidDelList, versionList);
iCount = 0;
if (activeDRoids.Count > 0)
{
if (activeRoids.Contains(chg))
foreach (string del in delList)
{
ROFSTLookup.rochild roch = newLU.GetRoChild(chg);
string desc = string.Format("Change in RO Values: Old value = {0}, New value = {1}", origLU.GetRoValue(chg), roch.value);
// roid's are stored in database as 16 characters long in the rousages table. They may be stored
// as 12 characters in the ro.fst.
string padroid = chg.Length <= 12 ? chg + "0000" : chg;
using (DROUsageInfoList affected = DROUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroid, desc, "Changed", versionList))
string padroiddel = del.Length <= 12 ? del + "0000" : del;
string desc = string.Format("Deleted RO: Value = {0}", origLU.GetRoValue(del));
if (activeDRoids.Contains(del.Substring(0, 12).ToUpper()))
{
foreach (DROUsageInfo droUsg in affected)
using (DROUsageInfoList Daffected = DROUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted", versionList))
{
Pdf.DeleteAll(droUsg.DocID);
}
}
}
}
//dtLast = ShowDuration(dtLast, "chg loop Doc");
foreach (string del in delList)
{
string desc = string.Format("Deleted RO: Value = {0}", origLU.GetRoValue(del));
string padroiddel = del.Length <= 12 ? del + "0000" : del;
using (RoUsageInfoList affected = RoUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted",versionList))
{
foreach (RoUsageInfo roUsg in affected)
{
using (Content content = Content.Get(roUsg.MyContent.ContentID))
{
content.FixContentText(roUsg, "?", 0, origROFstInfo);
if (content.IsDirty)
foreach (DROUsageInfo droUsg in Daffected)
{
// Update UserID and DTS when RO Value is updated.
content.UserID = Volian.Base.Library.VlnSettings.UserID;
content.DTS = DateTime.Now;
content.Save();
if (myProgressBarRefresh != null) myProgressBarRefresh(++iCount, chgList.Count, "Removing Old DRO Values");
Pdf.DeleteAll(droUsg.DocID);
}
}
}
}
using (DROUsageInfoList Daffected = DROUsageInfoList.GetAffected(origROFstInfo.MyRODb.RODbID, padroiddel, desc, "Deleted", versionList))
{
foreach (DROUsageInfo droUsg in Daffected)
{
Pdf.DeleteAll(droUsg.DocID);
}
}
}
//dtLast = ShowDuration(dtLast, "delList");
//dtStart = ShowDuration(dtStart, "Total");
if (myProgressBarRefresh != null) myProgressBarRefresh(100,100, "RO Values Updated");
}
private static DateTime ShowDuration(DateTime dtLast, string message)
@ -500,6 +541,34 @@ namespace VEPROMS.CSLA.Library
}
return activeRoids;
}
private static List<string> BuildActiveROIDsForRoUsages12(string RoidList)
{
List<string> activeRoids = new List<string>();
using (RoUsageInfoList activeList = RoUsageInfoList.GetROUSagesByROIDs(RoidList))
{
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> 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> BuildActiveROIDsForDRoUsages(string RoidList)
{
List<string> activeRoids = new List<string>();
@ -530,6 +599,34 @@ namespace VEPROMS.CSLA.Library
}
return activeRoids;
}
private static List<string> BuildActiveROIDsForDRoUsages12(string RoidList)
{
List<string> activeRoids = new List<string>();
using (DROUsageInfoList activeList = DROUsageInfoList.GetDROUsagesByROIDs(RoidList))
{
foreach (DROUsageInfo roui in activeList)
{
string roid = roui.ROID.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));
@ -565,15 +662,15 @@ namespace VEPROMS.CSLA.Library
retval = string.Format("{0}_{1}", roName, iSuffix + 1);
return retval;
}
private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages)
private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{
for (int i = 0; i < rochild.Length; i++)
{
if (rochild[i].type == 8) this.AddGraphic(rdi, rochild[i].value, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);
if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);
if (rochild[i].type == 8)this.AddGraphic(rdi, rochild[i].value, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages,myProgressBarRefresh);
if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages,myProgressBarRefresh);
}
}
private void AddGraphic(RODbInfo rdi, string p, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages)
private void AddGraphic(RODbInfo rdi, string p, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{
if (p == null) return;
string imgname = p.Substring(0, p.IndexOf('\n'));
@ -603,6 +700,7 @@ namespace VEPROMS.CSLA.Library
{
if (!myAddedROImages.Contains(key))
{
myProgressBarRefresh(0, 100, "Loading " + imgname);
FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length);