B2017-249 Handle AutoSave feature of MSWord. Handle temporary documents which were not saved when PROMS crashed or was terminated without saving.
This commit is contained in:
@@ -175,6 +175,13 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public partial class DocumentInfo
|
||||
{
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
private bool _ContentIsDirty = false;
|
||||
public bool ContentIsDirty
|
||||
{
|
||||
get { return _ContentIsDirty; }
|
||||
set { _ContentIsDirty = value; }
|
||||
}
|
||||
public string DocumentTitle
|
||||
{
|
||||
get
|
||||
@@ -386,7 +393,8 @@ namespace VEPROMS.CSLA.Library
|
||||
get { return _MyDocument; }
|
||||
set
|
||||
{
|
||||
TryDelete();
|
||||
// B2017-249 Don't delete last DSOFile
|
||||
//TryDelete();
|
||||
_MyDocument = value;
|
||||
CreateFile();
|
||||
}
|
||||
@@ -406,7 +414,9 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
if (_MyDocument == null) return;
|
||||
if (_MyFile == null) return;
|
||||
if (_MyFile.Exists)
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
_MyFile.Refresh();
|
||||
if (_MyFile.Exists && (TimeSpan.FromTicks(_MyDocument.DTS.Ticks - _MyFile.LastWriteTimeUtc.Ticks).TotalSeconds > 1.0))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -440,24 +450,77 @@ namespace VEPROMS.CSLA.Library
|
||||
while (!_Created)
|
||||
CreateTemporaryFile();
|
||||
}
|
||||
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
public bool ContentIsDirty
|
||||
{
|
||||
get
|
||||
{
|
||||
_MyFile.Refresh();
|
||||
return _MyFile.Exists && (_MyFile.LastWriteTimeUtc > StartDTS);
|
||||
}
|
||||
}
|
||||
private DateTime _StartDTS;
|
||||
public DateTime StartDTS
|
||||
{
|
||||
get { return _StartDTS; }
|
||||
set { _StartDTS = value; }
|
||||
}
|
||||
private void CreateTemporaryFile()
|
||||
{
|
||||
_Unique = 0;
|
||||
try
|
||||
{
|
||||
if (_MyDocument != null)
|
||||
{
|
||||
_MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}{3}", VlnSettings.TemporaryFolder, MyDocument.DocID, Unique, MyDocument.FileExtension));
|
||||
FileInfo matchingFile = null;
|
||||
while (_MyFile.Exists)
|
||||
{
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
if (!Temporary)
|
||||
{
|
||||
double dtsDiff = TimeSpan.FromTicks(_MyFile.LastWriteTimeUtc.Ticks - _MyDocument.DTS.Ticks).TotalSeconds;
|
||||
if (dtsDiff > 1.0)
|
||||
{
|
||||
if (System.Windows.Forms.MessageBox.Show("Restore Unsaved version from " + String.Format("{0:MM/dd/yyyy HH:mm:ss}", _MyFile.LastWriteTime),
|
||||
"Restore Unsaved Version", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
|
||||
{
|
||||
_MyDocument.ContentIsDirty = true;
|
||||
StartDTS = _MyFile.LastWriteTimeUtc;
|
||||
_Created = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_MyFile.Delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (dtsDiff > -.5 && dtsDiff < .5)
|
||||
{
|
||||
matchingFile = _MyFile;
|
||||
}
|
||||
}
|
||||
_MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}{3}", VlnSettings.TemporaryFolder, MyDocument.DocID, Unique, MyDocument.FileExtension));
|
||||
}
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
if (matchingFile != null)
|
||||
{
|
||||
_MyFile = matchingFile;
|
||||
_MyDocument.ContentIsDirty = false;
|
||||
StartDTS = _MyFile.LastWriteTimeUtc;
|
||||
_Created = true;
|
||||
return;
|
||||
}
|
||||
FileStream fs = _MyFile.Create();
|
||||
if (MyDocument.DocContent != null) fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length);
|
||||
fs.Close();
|
||||
_MyFile.CreationTimeUtc = _MyDocument.DTS;
|
||||
_MyFile.LastWriteTimeUtc = _MyDocument.DTS;
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
StartDTS = _MyFile.LastWriteTimeUtc;
|
||||
_Created = true;
|
||||
_MyDocument.ContentIsDirty = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -551,6 +614,18 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
MyDocument = myDocument;
|
||||
}
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
private bool _Temporary = false;
|
||||
public bool Temporary
|
||||
{
|
||||
get { return _Temporary; }
|
||||
set { _Temporary = value; }
|
||||
}
|
||||
public DSOFile(DocumentInfo myDocument, bool temporary)
|
||||
{
|
||||
Temporary = temporary;
|
||||
MyDocument = myDocument;
|
||||
}
|
||||
#endregion
|
||||
#region Destructor
|
||||
~DSOFile()
|
||||
@@ -568,7 +643,8 @@ namespace VEPROMS.CSLA.Library
|
||||
if (!_IsDisposed)
|
||||
{
|
||||
_IsDisposed = true;
|
||||
TryDelete();
|
||||
// B2017-249 Don't Delete last DSOFile
|
||||
//TryDelete();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -709,7 +785,8 @@ namespace VEPROMS.CSLA.Library
|
||||
spPrefix = dvi.DocVersionConfig.RODefaults_setpointprefix;
|
||||
}
|
||||
// string AccPageID = string.Format("<{0}-{1}>", accPrefix, roch.appid);
|
||||
using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument))
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument,true))
|
||||
{
|
||||
// Increase the priority of the Word Process so that the pdf creation happens quickly
|
||||
Process[] myProcessess = Process.GetProcessesByName("winword");
|
||||
@@ -992,6 +1069,8 @@ namespace VEPROMS.CSLA.Library
|
||||
DocReplace.Add(sect.MyContent.MyEntry.DocID, GetBytes(MyApp.ActiveDocument.FullName)); // save the word document containing resolved ROs
|
||||
}
|
||||
CloseDocument();
|
||||
// B2017-249 Delete Temporary file
|
||||
myFile.MyFile.Delete();
|
||||
if (CloseWordWhenDone)
|
||||
{
|
||||
CloseAppAfterWait();
|
||||
|
Reference in New Issue
Block a user