logic to save word sections with resolved RO values for exporting the approved procedure

logic to create an export file with unlinked RO and Transition
Commented out debug statements to help evaluate memory usage
This commit is contained in:
2016-02-18 15:29:25 +00:00
parent 6ae1fcda1a
commit 8cd75c0c14
7 changed files with 820 additions and 734 deletions

View File

@@ -572,6 +572,13 @@ namespace VEPROMS.CSLA.Library
}
public static class MSWordToPDF
{
// used to save Word sections with resolved ROs (for export generated from Approve)
private static Dictionary<int, byte[]> _DocReplace;
public static Dictionary<int, byte[]> DocReplace
{
get { return MSWordToPDF._DocReplace; }
set { MSWordToPDF._DocReplace = value; }
}
private static bool _CloseWordWhenDone = true;
public static bool CloseWordWhenDone
{
@@ -615,7 +622,7 @@ namespace VEPROMS.CSLA.Library
string fileName = GetFileName(sect);
FileInfo fi = new FileInfo(fileName);
FileStream fs = fi.Create();
PdfInfo myPdf = PdfInfo.Get(sect);
PdfInfo myPdf = PdfInfo.Get(sect,false);
if (myPdf != null && myPdf.DocPdf != null) fs.Write(myPdf.DocPdf, 0, myPdf.DocPdf.Length);
fs.Close();
return fileName;
@@ -624,7 +631,7 @@ namespace VEPROMS.CSLA.Library
public static bool UpdateDocPdf(DocumentInfo mydoc, Color overrideColor, ItemInfo sect)
{
MSWordToPDF.OverrideColor = overrideColor;
PdfInfo myPdf = PdfInfo.Get(sect);
PdfInfo myPdf = PdfInfo.Get(sect,DocReplace!=null);
return true;
}
public static bool SetDocPdf(DocumentInfo docInfo, ItemInfo sect)
@@ -982,15 +989,32 @@ namespace VEPROMS.CSLA.Library
sel.Range.Font.Color = (LBWdColor)WordColor(OverrideColor == System.Drawing.Color.Transparent ? System.Drawing.Color.Black : OverrideColor);
sect.MSWordPageCount = myDoc.Length;
fileName = CreatePDF(fileName, openPdf,MSWordToPDF.DebugStatus);
if (DocReplace != null)
{
MyApp.ActiveDocument.SaveAs2000();
DocReplace.Add(sect.MyContent.MyEntry.DocID, GetBytes(MyApp.ActiveDocument.FullName)); // save the word document containing resolved ROs
}
CloseDocument();
if (CloseWordWhenDone)
{
CloseAppAfterWait();
}
if (statusChange != null) statusChange(VolianStatusType.Complete, 0, "");
GC.Collect(); //jsj 2-15-2016 - for memeory garbage collection
return fileName;
}
}
// Reads the Word file containing the resolved ROs
// used when adding to DocReplace
private static byte[] GetBytes(string filename)
{
FileInfo fi = new FileInfo(filename);
FileStream fs = fi.Open(FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
byte[] buf = new byte[fi.Length];
fs.Read(buf, 0, buf.Length);
fs.Close();
return buf;
}
private static void CloseDocument()
{
int attempts = 0;
@@ -1323,6 +1347,7 @@ namespace VEPROMS.CSLA.Library
VG.IVGOutput vgOut = new VG.VGOut_Graphics(grfx);
vgOut.DebugStatus = MSWordToPDF.DebugStatus;
myPlot.Process(vgOut);
GC.Collect(); // memory garbage collection (Regex bug)
grfx.Dispose();
GraphicsUnit gu = new GraphicsUnit();
retval = mf.GetBounds(ref gu);

View File

@@ -63,7 +63,7 @@ namespace VEPROMS.CSLA.Library
}
public partial class PdfInfo
{
public static PdfInfo Get(ItemInfo sect)
public static PdfInfo Get(ItemInfo sect, bool ovrride)
{
int count = 0;
while (count < 2)
@@ -81,8 +81,12 @@ namespace VEPROMS.CSLA.Library
myPdf = Get(sect.MyContent.MyEntry.DocID, ss*10 + MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopMargin, (int)myDocStyle.Layout.PageLength,
(int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth);
}
if (myPdf != null) return myPdf;
if (count > 0) return null; // Could not find or create a pdf
// ovrride forces the the printing of the word seciton, which creates a word file with resolved ROs, which is saved for an approved export
if (!ovrride || (ovrride && count ==1))
{
if (myPdf != null) return myPdf;
if (count > 0) return null; // Could not find or create a pdf
}
MSWordToPDF.SetDocPdf(sect.MyContent.MyEntry.MyDocument, sect);
count++;
}

View File

@@ -878,14 +878,16 @@ namespace VEPROMS.CSLA.Library
{
get
{
//_MyLog.WarnFormat("LatestVersion 1 - {0}",GC.GetTotalMemory(true));
if (this.RevisionVersions == null || this.RevisionVersions.Count == 0) return null;
VersionInfo latest = this.RevisionVersions[0];
foreach (VersionInfo vi in this.RevisionVersions)
{
if (vi.DTS > latest.DTS)
latest = vi;
}
return latest;
VersionInfo latest = this.RevisionVersions[0];
foreach (VersionInfo vi in this.RevisionVersions)
{
if (vi.DTS > latest.DTS)
latest = vi;
}
//_MyLog.WarnFormat("LatestVersion 2 - {0}", GC.GetTotalMemory(true));
return latest;
}
}
public override string ToString()