Added method to remove all word section PDFs during the update RO values process

More live feedback to the user when updating RO values, faster Update RO Values logic, merged the refresh ROs logic with the update ROs logic, save date/time of completed RO Update
Logic to get the RO figure file name
This commit is contained in:
John Jenko 2017-06-20 16:27:17 +00:00
parent f5dbfa12fb
commit 16133ccab1
3 changed files with 178 additions and 17 deletions

View File

@ -21,7 +21,7 @@ namespace VEPROMS.CSLA.Library
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new DbCslaException("Error on Pdf.Delete", ex); throw new DbCslaException("Error on Pdf.DeleteAll", ex);
} }
} }
[Serializable()] [Serializable()]
@ -60,6 +60,56 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Pdf.DataPortal_Delete", ex); throw new DbCslaException("Pdf.DataPortal_Delete", ex);
} }
} }
// used to remove word section PDFs to force ROs to be updated when printed or saved
public static void DeleteAllDocVersion(int versionID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Pdf");
try
{
DataPortal.Delete(new VersionIDCriteria(versionID));
}
catch (Exception ex)
{
throw new DbCslaException("Error on Pdf.DeleteAllDocVersion", ex);
}
}
[Serializable()]
protected class VersionIDCriteria
{
private int _VersionID;
public int VersionID
{ get { return _VersionID; } }
public VersionIDCriteria(int versionID)
{
_VersionID = versionID;
}
}
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(VersionIDCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Delete", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "deleteAllDocVersionPdfs";
cm.Parameters.AddWithValue("@VersionID", criteria.VersionID);
cm.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Delete", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("Pdf.DataPortal_Delete", ex);
}
}
} }
public partial class PdfInfo public partial class PdfInfo

View File

@ -262,7 +262,9 @@ namespace VEPROMS.CSLA.Library
{ {
using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID)) using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID))
{ {
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs, myProgressBarRefresh);// TODO: Need to add MyImages int cnt = rfi.CountRoFstGraphics(myLookup.myHdr.myDbs[i].children); // get the total number of RO figures
int curCnt = 0;
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs, myProgressBarRefresh, cnt, ref curCnt);// TODO: Need to add MyImages
} }
} }
} }
@ -274,6 +276,76 @@ namespace VEPROMS.CSLA.Library
} }
#endregion #endregion
#region Update Ro Values #region Update Ro Values
public static int RefreshROFst(DocVersionInfo dvi, ROFstInfoProgressBarRefresh myProgressBarRefresh, System.Windows.Forms.TextBox tbStatus)
{
int fixedROs = 0;
if (dvi.DocVersionConfig.SelectedSlave <= 0)
{
myProgressBarRefresh(1, 100, "Update MS Word ROs");
Pdf.DeleteAllDocVersion(dvi.VersionID); // remove word section PDFs to force upate of RO values when printed
int i = 0;
foreach (ProcedureInfo proc in dvi.Procedures)
{
DateTime start = DateTime.Now;
ProcedureInfo.ResetROCounters();
myProgressBarRefresh(++i, dvi.Procedures.Count, string.Format("{0} ({1}/{2} ROs {3})",proc.DisplayNumber,i,dvi.Procedures.Count,fixedROs));
ProcedureInfo.RefreshReferenceObjects(proc);
fixedROs += ProcedureInfo.ROFixCount;
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, proc.DisplayNumber, ProcedureInfo.ROCheckCount, ProcedureInfo.ROFixCount, ts.TotalSeconds));
}
}
return fixedROs;
}
// returns the path and file name with Proc Set Name and the completed date/time (used for all update RO calls except for Amin Tool from the V button)
public static string ROUpdateResultsPath (DocVersionInfo dvi)
{
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\ROUpdateReport_" + dvi.MyFolder.Name.Replace(" ", "_") + "_" + DateTime.Now.ToString("MM-dd-yyyy_HH-mm-ss") +".txt";
}
public static ROFst RefreshROFst(RODbInfo rdi, DocVersionAssociation dva, DocVersion docver, ROFstInfo origROFst, ROFstInfoProgressBarRefresh myProgressBarRefresh, System.Windows.Forms.TextBox tbStatus)
{
ROFst rofst = null;
if (docver.NewerRoFst)
{
// only load the RO.fst
Volian.Base.Library.VlnSettings.DoUpdateRO = false;
rofst = ROFstInfo.UpdateRoFst(rdi, dva, docver, origROFst, myProgressBarRefresh);
Volian.Base.Library.VlnSettings.DoUpdateRO = true;
}
else
rofst = docver.DocVersionAssociations[0].MyROFst;
DocVersionInfo dvi = DocVersionInfo.Get(docver.VersionID);
SetAssociationLastCompleted(docver,string.Empty);
int fixedROs = RefreshROFst(dvi, myProgressBarRefresh, tbStatus);
SetAssociationLastCompleted(docver, DateTime.Now.ToString()); // RO Update completed successfully and un-interrupted, save the date/time to the Doc Version Association config
myProgressBarRefresh(100, 100, "RO Update Complete"); // update the progress bar
System.Windows.Forms.Application.DoEvents();
// pop up a message window telling the user the RO Update has completed and now many ROs were updated
// If we are updating RO from the Admin Tools (from the V button) and we are updating more than on procedure set, then just append the "RO Update Complete" text
// To the MessageList. Once completed will all procedure sets, Admin Tools will display one message box with all the results in it.
if (MessageList == null)
System.Windows.Forms.MessageBox.Show(fixedROs == 0 ? "No ROs Required Updating" : string.Format("{0} ROs Updated for {1}", fixedROs, dvi.MyFolder.Name), "RO Update Complete");
else
MessageList.AppendLine((fixedROs == 0 ? "No ROs Required Updating for " : string.Format("{0} ROs Updated for ", fixedROs)) + dvi.MyFolder.Name);
return rofst;
}
// 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;
// Place the date/time of the completed RO Update in the DocVersion association config
// this witll tell us if the RO Update was completed, interrupted, or just needs done and whether to make the Update ROs button available
private static void SetAssociationLastCompleted(DocVersion docver, string value)
{
//Association asc = dva.MyAssociation;
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();
docver.Save();
}
/// <summary> /// <summary>
/// Updates an ro.fst into a sql database. /// Updates an ro.fst into a sql database.
/// </summary> /// </summary>
@ -296,10 +368,10 @@ namespace VEPROMS.CSLA.Library
if (rofst != null) if (rofst != null)
{ {
// Get a list of figures which have changed content (DTS) // Get a list of figures which have changed content (DTS)
List<string> changedFigures = GetChangedFigureROIDs(origROFst, ROFstInfo.GetJustROFst(rofst.ROFstID),DocVersionInfo.Get(docver.VersionID)); List<string> changedFigures = GetChangedFigureROIDs(origROFst, ROFstInfo.GetJustROFst(rofst.ROFstID),DocVersionInfo.Get(docver.VersionID), myProgressBarRefresh);
docver.DocVersionAssociations[0].MyROFst = rofst; docver.DocVersionAssociations[0].MyROFst = rofst;
docver.Save(); docver.Save();
if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO")) if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO") && Volian.Base.Library.VlnSettings.DoUpdateRO)
UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh,changedFigures); UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh,changedFigures);
return rofst; return rofst;
} }
@ -332,7 +404,9 @@ namespace VEPROMS.CSLA.Library
// walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8: // walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8:
if (myLookup.myHdr.myDbs[i].children != null) if (myLookup.myHdr.myDbs[i].children != null)
{ {
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh); int cnt = rfi.CountRoFstGraphics(myLookup.myHdr.myDbs[i].children); // get the total number of RO figures
int curCnt = 0;
rfi.MigrateRoFstGraphics(rdi, myLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh,cnt,ref curCnt);
} }
} }
} }
@ -342,7 +416,7 @@ namespace VEPROMS.CSLA.Library
} }
// Now update the usages: compare old to new rofsts and update usages accordingly, i.e. modified // Now update the usages: compare old to new rofsts and update usages accordingly, i.e. modified
// values, deleted ros, etc. // values, deleted ros, etc.
if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO")) if (!Volian.Base.Library.VlnSettings.GetCommandFlag("NOUPDATERO") && Volian.Base.Library.VlnSettings.DoUpdateRO)
UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh, MyChangedFigureROIDs); UpdateROValuesText(origROFst, rofst, DocVersionInfo.Get(docver.VersionID),myProgressBarRefresh, MyChangedFigureROIDs);
return rofst; return rofst;
} }
@ -355,10 +429,10 @@ namespace VEPROMS.CSLA.Library
/// <param name="rofst">Current ROFST Object</param> /// <param name="rofst">Current ROFST Object</param>
/// <param name="docver">DocVersion (Working Draft)</param> /// <param name="docver">DocVersion (Working Draft)</param>
/// <returns>List of ROIDs which can be used to refresh MSWord PDFs</returns> /// <returns>List of ROIDs which can be used to refresh MSWord PDFs</returns>
private static List<string> GetChangedFigureROIDs(ROFstInfo origROFst, ROFstInfo rofst, DocVersionInfo docver) private static List<string> GetChangedFigureROIDs(ROFstInfo origROFst, ROFstInfo rofst, DocVersionInfo docver, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{ {
// Need to create a list of ROIDs for figures which have changed // Need to create a list of ROIDs for figures which have changed
List<string> ChangedFiles = GetChangedFigures(origROFst, rofst); 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;
@ -412,24 +486,32 @@ namespace VEPROMS.CSLA.Library
/// <param name="origROFst">Original ROFST Object</param> /// <param name="origROFst">Original ROFST Object</param>
/// <param name="rofst">Current ROFST Object</param> /// <param name="rofst">Current ROFST Object</param>
/// <returns>List of Files which have changed (DTS)</returns> /// <returns>List of Files which have changed (DTS)</returns>
private static List<string> GetChangedFigures(ROFstInfo origROFst, ROFstInfo rofst) private static List<string> GetChangedFigures(ROFstInfo origROFst, ROFstInfo rofst, ROFstInfoProgressBarRefresh myProgressBarRefresh)
{ {
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;
foreach (FigureInfo fi in origROFst.ROFstFigures) foreach (FigureInfo fi in origROFst.ROFstFigures)
{ {
string key = fi.MyROImage.FileName; string key = fi.ROImage_FileName ?? fi.MyROImage.FileName;
myProgressBarRefresh(++i, origROFst.ROFstFigures.Count, "Original " + key);
if (!orig.ContainsKey(key)) orig.Add(key, fi.ImageID); if (!orig.ContainsKey(key)) orig.Add(key, fi.ImageID);
} }
i = 0;
foreach (FigureInfo fi in rofst.ROFstFigures) foreach (FigureInfo fi in rofst.ROFstFigures)
{ {
string key = fi.MyROImage.FileName; string key = fi.ROImage_FileName ?? fi.MyROImage.FileName;
myProgressBarRefresh(++i, rofst.ROFstFigures.Count, "Current " + key);
if (orig.ContainsKey(key) && orig[key] == fi.ImageID) if (orig.ContainsKey(key) && orig[key] == fi.ImageID)
orig.Remove(key); orig.Remove(key);
} }
List<string> changedFigures = new List<string>(); List<string> changedFigures = new List<string>();
i = 0;
foreach (string key in orig.Keys) foreach (string key in orig.Keys)
{
myProgressBarRefresh(++i, orig.Count, "Compare " + key);
changedFigures.Add(key); changedFigures.Add(key);
}
return changedFigures; return changedFigures;
} }
private static Dictionary<string,int> BuildROImagesList(ROImageInfoList myROImages) private static Dictionary<string,int> BuildROImagesList(ROImageInfoList myROImages)
@ -500,7 +582,7 @@ namespace VEPROMS.CSLA.Library
foreach (ItemInfo ii in roUsg.MyContent.ContentItems) foreach (ItemInfo ii in roUsg.MyContent.ContentItems)
{ {
string val = newLU.GetTranslatedRoValue(padroid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta); string val = newLU.GetTranslatedRoValue(padroid, ii.ActiveFormat.PlantFormat.FormatData.SectData.ConvertCaretToDelta);
content.FixContentText(roUsg, val, roch.type, origROFstInfo); content.FixContentText(roUsg, val, roch.type, origROFstInfo, true);
if (content.IsDirty) if (content.IsDirty)
{ {
// Update UserID and DTS when RO Value is updated. // Update UserID and DTS when RO Value is updated.
@ -759,15 +841,29 @@ namespace VEPROMS.CSLA.Library
retval = string.Format("{0}_{1}", roName, iSuffix + 1); retval = string.Format("{0}_{1}", roName, iSuffix + 1);
return retval; return retval;
} }
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) 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)
{ {
for (int i = 0; i < rochild.Length; i++) for (int i = 0; i < rochild.Length; i++)
{ {
if (rochild[i].type == 8)this.AddGraphic(rdi, rochild[i], rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh); if (rochild[i].type == 8)
if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs,myProgressBarRefresh); {
this.AddGraphic(rdi, rochild[i], rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs, myProgressBarRefresh, cnt, curCnt);
curCnt++;
}
if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages, MyChangedFigureROIDs, myProgressBarRefresh, cnt, ref curCnt);
} }
} }
private void AddGraphic(RODbInfo rdi, ROFSTLookup.rochild myRO, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages, List<string> MyChangedFigureROIDs, ROFstInfoProgressBarRefresh myProgressBarRefresh) private int CountRoFstGraphics(ROFSTLookup.rochild[] rochild)
{
int cnt = 0;
for (int i = 0; i < rochild.Length; i++)
{
if (rochild[i].type == 8) cnt++;
if (rochild[i].children != null) cnt += this.CountRoFstGraphics(rochild[i].children);
}
return cnt;
}
private void AddGraphic(RODbInfo rdi, ROFSTLookup.rochild myRO, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages, List<string> MyChangedFigureROIDs, ROFstInfoProgressBarRefresh myProgressBarRefresh, int cnt, int curCnt)
{ {
string p = myRO.value; string p = myRO.value;
if (p == null) return; if (p == null) return;
@ -798,7 +894,7 @@ namespace VEPROMS.CSLA.Library
{ {
if (!myAddedROImages.Contains(key)) if (!myAddedROImages.Contains(key))
{ {
myProgressBarRefresh(0, 100, "Loading " + imgname); myProgressBarRefresh(curCnt, cnt, "Loading " + imgname); // show progress of loading images
FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader r = new BinaryReader(fsIn); BinaryReader r = new BinaryReader(fsIn);
byte[] ab = r.ReadBytes((int)fsIn.Length); byte[] ab = r.ReadBytes((int)fsIn.Length);

View File

@ -363,6 +363,16 @@ namespace VEPROMS.CSLA.Library
_FigureID = figureID; _FigureID = figureID;
} }
} }
private string _ROImage_FileName = string.Empty;
public string ROImage_FileName
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
CanReadProperty("ROImage_FileName", true);
return _ROImage_FileName;
}
}
private void ReadData(SafeDataReader dr) private void ReadData(SafeDataReader dr)
{ {
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.ReadData", GetHashCode()); if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FigureInfo.ReadData", GetHashCode());
@ -374,6 +384,11 @@ namespace VEPROMS.CSLA.Library
_Config = dr.GetString("Config"); _Config = dr.GetString("Config");
_DTS = dr.GetDateTime("DTS"); _DTS = dr.GetDateTime("DTS");
_UserID = dr.GetString("UserID"); _UserID = dr.GetString("UserID");
for (int i = 0; i < dr.FieldCount; i++)
{
if (dr.GetName(i) == "ROImage_FileName")
_ROImage_FileName = dr.GetString("ROImage_FileName");
}
} }
catch (Exception ex) catch (Exception ex)
{ {