From 9ca49944e3a7e378305d21b1582c0955c651ee4a Mon Sep 17 00:00:00 2001 From: Rich Date: Tue, 14 Aug 2012 16:23:06 +0000 Subject: [PATCH] Cache ROImages so they only have to be read once. Added Page Number to DebugText.txt when printing. --- PROMS/DataLoader/RoFst.cs | 51 ++++++++++++++++------ PROMS/Volian.Print.Library/vlnParagraph.cs | 2 +- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/PROMS/DataLoader/RoFst.cs b/PROMS/DataLoader/RoFst.cs index 38e49fa9..514fccc3 100644 --- a/PROMS/DataLoader/RoFst.cs +++ b/PROMS/DataLoader/RoFst.cs @@ -159,13 +159,18 @@ namespace DataLoader FileInfo fi = new FileInfo(imgfile); frmMain.Status = "Processing Image " + fname; // if the roimage record exists, don't create a new one... - ROImage roImg = null; //Console.WriteLine("ROImage Key {0} List {1} ID {2}", ROImage.CacheCountPrimaryKey, ROImage.CacheCountList, ROImage.CacheCountByRODbID); //Console.WriteLine("ROImageInfo Key {0} List {1}", ROImageInfo.CacheCountPrimaryKey, ROImageInfo.CacheCountList); //Console.WriteLine("ROFst Key {0} List {1} ID {2}", ROFst.CacheCountPrimaryKey, ROFst.CacheCountList, ROFst.CacheCountByRODbID_DTS); //Console.WriteLine("ROFstInfo Key {0} List {1}", ROFstInfo.CacheCountPrimaryKey, ROFstInfo.CacheCountList); - using (roImg = ROImage.GetByRODbID_FileName_DTS(rodb.RODbID, imgname, fi.LastWriteTimeUtc)) + frmMain.AddInfo("Adding RO Image {0}", imgname); + //using (roImg = ROImage.GetByRODbID_FileName_DTS(rodb.RODbID, imgname, fi.LastWriteTimeUtc)) + //{ + ROImage roImg = null; + roImg = GetImageFromAvailable(rodb.RODbID, imgname, fi.LastWriteTimeUtc); + if (roImg == null) { + roImg = ROImage.GetByRODbID_FileName_DTS(rodb.RODbID, imgname, fi.LastWriteTimeUtc); if (roImg == null) { using (FileStream fsIn = new FileStream(imgfile, FileMode.Open, FileAccess.Read, FileShare.Read)) @@ -178,21 +183,41 @@ namespace DataLoader roImg = ROImage.MakeROImage(rodb, imgname, ab, null, fi.LastWriteTimeUtc, "Migration"); } } - // see if it's already linked to the current rofst.. - //Figure figure = Figure.GetByROFstID_ImageID(rofstinfo.ROFstID, roImg.ImageID); - using (Figure figure = Figure.GetByROFstID_ImageID(rofstinfo.ROFstID, roImg.ImageID)) - { - if (figure != null) return; - //using (ROFst rofst = rofstinfo.Get()) - ROFst rofst = rofstinfo.Get(); // Use the cached ROFST rather than creating and disposing - //figure = Figure.MakeFigure(rofst, roImg, null); - using (Figure tfig = Figure.MakeFigure(rofst, roImg, null)) ; - } - roImg.Dispose(); + AddToAvailable(roImg, rodb.RODbID, imgname, fi.LastWriteTimeUtc); } + // see if it's already linked to the current rofst.. + //Figure figure = Figure.GetByROFstID_ImageID(rofstinfo.ROFstID, roImg.ImageID); + using (Figure figure = Figure.GetByROFstID_ImageID(rofstinfo.ROFstID, roImg.ImageID)) + { + if (figure != null) return; + //using (ROFst rofst = rofstinfo.Get()) + ROFst rofst = rofstinfo.Get(); // Use the cached ROFST rather than creating and disposing + //figure = Figure.MakeFigure(rofst, roImg, null); + using (Figure tfig = Figure.MakeFigure(rofst, roImg, null)) ; + } + //roImg.Dispose(); } else frmMain.AddError("Cannot Find Image File {0}", imgfile); } + + private void AddToAvailable(ROImage roImg, int dbid, string imgname, DateTime dateTime) + { + string key = AvailableKey(dbid, imgname, dateTime); + _AvaiableROImages.Add(key, roImg); + } + + private string AvailableKey(int dbid, string imgname, DateTime dateTime) + { + return string.Format("{0}|{1}|{2}", dbid, imgname, dateTime.ToString("yyyyMMdd HHmmss")); + } + + private ROImage GetImageFromAvailable(int dbid, string imgname, DateTime dateTime) + { + string key = AvailableKey(dbid, imgname, dateTime); + if (_AvaiableROImages.ContainsKey(key)) return _AvaiableROImages[key]; + return null; + } + private Dictionary _AvaiableROImages = new Dictionary(); } } diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index d68c7b00..f9343d05 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -472,7 +472,7 @@ namespace Volian.Print.Library MyPageHelper.BottomMessage = new vlnText(cb, this, myMsg, myMsg, centerpos, msg_yLocation, docstyle.End.Font); } } - if (yLocalypagestart != yPageStart) DebugText.WriteLine("ToPdf-yPagestartDiff:{0},{1},{2}", MyItemInfo.ItemID, yLocalypagestart, yPageStart); + if (yLocalypagestart != yPageStart) DebugText.WriteLine("ToPdf-yPagestartDiff:{0},{1},{2},{3}", MyPageHelper.MyPdfContentByte.PdfWriter.CurrentPageNumber, MyItemInfo.ItemID, yLocalypagestart, yPageStart); return yPageStart; } private vlnParagraph TopMostChild