From 8567b1e7bf07a043f4ba942e62bd8163a4e27723 Mon Sep 17 00:00:00 2001 From: Rich Date: Tue, 15 Sep 2015 21:41:17 +0000 Subject: [PATCH] Bug B2015-126 Fixed When Referenced Objects are updated, the RO values embedded in Step Text is updated. Word sections are "flagged" (the temporary PDF records are deleted) which will cause the ROs to be "refreshed" when the procedure is printed. Unfortunately, the process did not account for changes to RoImage content, with no change to the embedded "value." PROMs has been changed to identify the Referenced Objects (ROIDs) which have been impacted by changes to the ROImages. ROFSTs can be updated in one of two ways. When an RO.FST is created in the ROEditor, this is a "new" RO.FST which can be used to create a unique ROFST record in the PROMS database. When this happens, any "new" figures are also added to the PROMS database. So, the first time this RO.FST is associated with PROMS database all of the figures are also created. If you then associate the this RO.FST PROMS record with other procedure sets, the only change is the addition of an association record. The important thing to remember is that the temporary PDF files used to improve performance with MS Word sections, have to be deleted when changes are made to the information used to describe the section, which can include RO Values and the RO Image Files. This change automates the process of refreshing the temporary PDF --- .../Extension/ROFSTExt.cs | 110 ++++++++++++++++-- 1 file changed, 101 insertions(+), 9 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs index 6f2599bb..439d88d7 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs @@ -247,6 +247,7 @@ namespace VEPROMS.CSLA.Library Dictionary myExistingROImages = BuildROImagesList(myROImages); List myUnChangedROImages = new List(); List myAddedROImages = new List(); + List MyChangedFigureROIDs = new List(); rofst = ROFst.MakeROFst(rodb, ab, null, di.LastWriteTimeUtc, rdi.UserID); // Hook this into the current docversion by replacing the rofstid field in the doc version // association object: @@ -261,7 +262,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,myProgressBarRefresh);// TODO: Need to add MyImages + rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs, myProgressBarRefresh);// TODO: Need to add MyImages } } } @@ -294,10 +295,12 @@ namespace VEPROMS.CSLA.Library ROFst rofst = ROFst.GetByRODbID_DTS(rdi.RODbID, rofstFI.LastWriteTimeUtc); if (rofst != null) { + // Get a list of figures which have changed content (DTS) + List changedFigures = GetChangedFigureROIDs(origROFst, ROFstInfo.GetJustROFst(rofst.ROFstID),DocVersionInfo.Get(docver.VersionID)); docver.DocVersionAssociations[0].MyROFst = rofst; docver.Save(); if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO")) - UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh); + UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh,changedFigures); return rofst; } @@ -314,6 +317,8 @@ namespace VEPROMS.CSLA.Library dva.MyROFst = rofst; docver.Save(); ROFSTLookup myLookup = ROFstInfo.GetJustROFst(rofst.ROFstID).GetROFSTLookup(DocVersionInfo.Get(docver.VersionID)); + // Keep a list of ROIDs for Images that have changed. + List MyChangedFigureROIDs = new List(); // Now load any images in... type 8 - integrated graphics ro type using (ROImageInfoList myROImages = ROImageInfoList.GetByRODbIDNoData(rdi.RODbID)) { @@ -327,7 +332,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,myProgressBarRefresh); + rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh); } } } @@ -338,10 +343,91 @@ 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),myProgressBarRefresh); + UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh, MyChangedFigureROIDs); return rofst; } } + /// + /// Get a list of ROIDs for figures that have changed content. This is only used when the contents of a figure + /// is changed without changing the filename. + /// + /// Original ROFST Object + /// Current ROFST Object + /// DocVersion (Working Draft) + /// List of ROIDs which can be used to refresh MSWord PDFs + private static List GetChangedFigureROIDs(ROFstInfo origROFst, ROFstInfo rofst, DocVersionInfo docver) + { + // Need to create a list of ROIDs for figures which have changed + List ChangedFiles = GetChangedFigures(origROFst, rofst); + // Get ROID associated with FileNames + List ROIDs = GetROIDsFromLookup(rofst,ChangedFiles,docver); + return ROIDs; + } + /// + /// Find all of the ROIDs associated with files that have changed + /// + /// Current ROFST Object + /// List of Changed Files + /// DocVersion (Working Draft) + /// List of FIleNames with changed content + private static List GetROIDsFromLookup(ROFstInfo rofst, List ChangedFiles, DocVersionInfo docver) + { + List roids = new List(); + ROFSTLookup myLookup = rofst.GetROFSTLookup(docver); + for (int i = 0; i < myLookup.myHdr.myDbs.Length; i++) + { + if (myLookup.myHdr.myDbs[i].children != null) + { + FindChangedFiles(myLookup.myHdr.myDbs[i].children,ChangedFiles,roids); + } + } + return roids; + } + /// + /// Find the ROIDs in the ROLookup + /// + /// an RO or RO Group + /// List of Files that have changed + /// List of ROIDs with changed figures + private static void FindChangedFiles(ROFSTLookup.rochild[] rochild,List ChangedFiles, List roids) + { + for (int i = 0; i < rochild.Length; i++) + { + if (rochild[i].type == 8 && rochild[i].value != null) + { + string filename = rochild[i].value; + filename = filename.Substring(0, filename.IndexOf('\n')); + if(ChangedFiles.Contains(filename)) + roids.Add(rochild[i].roid); + } + if (rochild[i].children != null) FindChangedFiles(rochild[i].children,ChangedFiles, roids); + } + } + /// + /// Get a List of figures which have changed + /// + /// Original ROFST Object + /// Current ROFST Object + /// List of Files which have changed (DTS) + private static List GetChangedFigures(ROFstInfo origROFst, ROFstInfo rofst) + { + Dictionary orig = new Dictionary(); + foreach (FigureInfo fi in origROFst.ROFstFigures) + { + string key = fi.MyROImage.FileName; + if (!orig.ContainsKey(key)) orig.Add(key, fi.ImageID); + } + foreach (FigureInfo fi in rofst.ROFstFigures) + { + string key = fi.MyROImage.FileName; + if (orig.ContainsKey(key) && orig[key] == fi.ImageID) + orig.Remove(key); + } + List changedFigures = new List(); + foreach (string key in orig.Keys) + changedFigures.Add(key); + return changedFigures; + } private static Dictionary BuildROImagesList(ROImageInfoList myROImages) { Dictionary myRoImagesList = new Dictionary(); @@ -364,7 +450,7 @@ namespace VEPROMS.CSLA.Library } return sb.ToString(); } - private static void UpdateROValuesText(ROFstInfo origROFstInfo, ROFst newROFst, DocVersionInfo dvi, ROFstInfoProgressBarRefresh myProgressBarRefresh) + private static void UpdateROValuesText(ROFstInfo origROFstInfo, ROFst newROFst, DocVersionInfo dvi, ROFstInfoProgressBarRefresh myProgressBarRefresh, List MyChangedFigureROIDs) { if (myProgressBarRefresh != null) myProgressBarRefresh(0, 100, "Update Ro Values"); string versionList = dvi.VersionID.ToString(); @@ -376,6 +462,10 @@ namespace VEPROMS.CSLA.Library //dtLast = ShowDuration(dtLast, "newLU"); List delList = new List(); List chgList = newLU.GetValueDifferences(origLU, ref delList); + // Any figures which have been changed will be included in the list of values that have changed. + foreach (string roid in MyChangedFigureROIDs) + if (!chgList.Contains(roid)) + chgList.Add(roid); //dtLast = ShowDuration(dtLast, "chgList"); string RoidList = GetRoidList(newROFst.RODbID, chgList); //dtLast = ShowDuration(dtLast, "RoidList"); @@ -662,16 +752,17 @@ 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 myExistingROImages, List myUnChangedROImages, List myAddedROImages, ROFstInfoProgressBarRefresh myProgressBarRefresh) + private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild, RODb rodb, ROFst rofst, Dictionary myExistingROImages, List myUnChangedROImages, List myAddedROImages, List MyChangedFigureROIDs, 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,myProgressBarRefresh); - if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages,myProgressBarRefresh); + if (rochild[i].type == 8)this.AddGraphic(rdi, rochild[i], rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh); + if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh); } } - private void AddGraphic(RODbInfo rdi, string p, RODb rodb, ROFst rofst, Dictionary myExistingROImages, List myUnChangedROImages, List myAddedROImages, ROFstInfoProgressBarRefresh myProgressBarRefresh) + private void AddGraphic(RODbInfo rdi, ROFSTLookup.rochild myRO, RODb rodb, ROFst rofst, Dictionary myExistingROImages, List myUnChangedROImages, List myAddedROImages, List MyChangedFigureROIDs, ROFstInfoProgressBarRefresh myProgressBarRefresh) { + string p = myRO.value; if (p == null) return; string imgname = p.Substring(0, p.IndexOf('\n')); int thedot = imgname.LastIndexOf('.'); @@ -723,6 +814,7 @@ namespace VEPROMS.CSLA.Library 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) } } }