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:
parent
bc0504c42e
commit
543a64a4f2
@ -175,6 +175,13 @@ namespace VEPROMS.CSLA.Library
|
|||||||
}
|
}
|
||||||
public partial class DocumentInfo
|
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
|
public string DocumentTitle
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -386,7 +393,8 @@ namespace VEPROMS.CSLA.Library
|
|||||||
get { return _MyDocument; }
|
get { return _MyDocument; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
TryDelete();
|
// B2017-249 Don't delete last DSOFile
|
||||||
|
//TryDelete();
|
||||||
_MyDocument = value;
|
_MyDocument = value;
|
||||||
CreateFile();
|
CreateFile();
|
||||||
}
|
}
|
||||||
@ -406,7 +414,9 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
if (_MyDocument == null) return;
|
if (_MyDocument == null) return;
|
||||||
if (_MyFile == 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
|
try
|
||||||
{
|
{
|
||||||
@ -440,24 +450,77 @@ namespace VEPROMS.CSLA.Library
|
|||||||
while (!_Created)
|
while (!_Created)
|
||||||
CreateTemporaryFile();
|
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()
|
private void CreateTemporaryFile()
|
||||||
{
|
{
|
||||||
|
_Unique = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_MyDocument != null)
|
if (_MyDocument != null)
|
||||||
{
|
{
|
||||||
_MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}{3}", VlnSettings.TemporaryFolder, MyDocument.DocID, Unique, MyDocument.FileExtension));
|
_MyFile = new FileInfo(string.Format(@"{0}\tmp_{1}{2}{3}", VlnSettings.TemporaryFolder, MyDocument.DocID, Unique, MyDocument.FileExtension));
|
||||||
|
FileInfo matchingFile = null;
|
||||||
while (_MyFile.Exists)
|
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));
|
_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();
|
FileStream fs = _MyFile.Create();
|
||||||
if (MyDocument.DocContent != null) fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length);
|
if (MyDocument.DocContent != null) fs.Write(MyDocument.DocContent, 0, MyDocument.DocContent.Length);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
_MyFile.CreationTimeUtc = _MyDocument.DTS;
|
_MyFile.CreationTimeUtc = _MyDocument.DTS;
|
||||||
_MyFile.LastWriteTimeUtc = _MyDocument.DTS;
|
_MyFile.LastWriteTimeUtc = _MyDocument.DTS;
|
||||||
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
StartDTS = _MyFile.LastWriteTimeUtc;
|
||||||
_Created = true;
|
_Created = true;
|
||||||
|
_MyDocument.ContentIsDirty = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -551,6 +614,18 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
MyDocument = myDocument;
|
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
|
#endregion
|
||||||
#region Destructor
|
#region Destructor
|
||||||
~DSOFile()
|
~DSOFile()
|
||||||
@ -568,7 +643,8 @@ namespace VEPROMS.CSLA.Library
|
|||||||
if (!_IsDisposed)
|
if (!_IsDisposed)
|
||||||
{
|
{
|
||||||
_IsDisposed = true;
|
_IsDisposed = true;
|
||||||
TryDelete();
|
// B2017-249 Don't Delete last DSOFile
|
||||||
|
//TryDelete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -709,7 +785,8 @@ namespace VEPROMS.CSLA.Library
|
|||||||
spPrefix = dvi.DocVersionConfig.RODefaults_setpointprefix;
|
spPrefix = dvi.DocVersionConfig.RODefaults_setpointprefix;
|
||||||
}
|
}
|
||||||
// string AccPageID = string.Format("<{0}-{1}>", accPrefix, roch.appid);
|
// 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
|
// Increase the priority of the Word Process so that the pdf creation happens quickly
|
||||||
Process[] myProcessess = Process.GetProcessesByName("winword");
|
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
|
DocReplace.Add(sect.MyContent.MyEntry.DocID, GetBytes(MyApp.ActiveDocument.FullName)); // save the word document containing resolved ROs
|
||||||
}
|
}
|
||||||
CloseDocument();
|
CloseDocument();
|
||||||
|
// B2017-249 Delete Temporary file
|
||||||
|
myFile.MyFile.Delete();
|
||||||
if (CloseWordWhenDone)
|
if (CloseWordWhenDone)
|
||||||
{
|
{
|
||||||
CloseAppAfterWait();
|
CloseAppAfterWait();
|
||||||
|
@ -50,7 +50,31 @@ namespace Volian.Base.Library
|
|||||||
}
|
}
|
||||||
public static void RemoveTmpDocs()
|
public static void RemoveTmpDocs()
|
||||||
{
|
{
|
||||||
RemoveTmps("*.doc");
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
// Remove temporary Doc Files more than 2 days old so that files with changes can be recoered.
|
||||||
|
RemoveOldTmps("*.doc");
|
||||||
|
RemoveOldTmps("*.docx");
|
||||||
|
RemoveOldTmps("*.rtf");
|
||||||
|
}
|
||||||
|
private static void RemoveOldTmps(string extension)
|
||||||
|
{
|
||||||
|
string tmpFolder = VlnSettings.TemporaryFolder;
|
||||||
|
DirectoryInfo di = new DirectoryInfo(tmpFolder);
|
||||||
|
if (!di.Exists) return;
|
||||||
|
foreach (FileInfo fi in di.GetFiles(extension))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// delete any docs. If it fails, just go on to the next one becase
|
||||||
|
// it may be open from another process.
|
||||||
|
if(fi.LastWriteTimeUtc < DateTime.Now.AddDays(-2.0))
|
||||||
|
fi.Delete();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
continue; // if an error, go onto next file.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveTmps(string extension)
|
private static void RemoveTmps(string extension)
|
||||||
|
@ -86,7 +86,8 @@ namespace Volian.Controls.Library
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_MyEdWord == null) return false; // B2017-133 Edraw Is Dirty Property
|
if (_MyEdWord == null) return false; // B2017-133 Edraw Is Dirty Property
|
||||||
return _MyEdWord.IsDirty();
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
return _MyEdWord.IsDirty() || MyDSOFile.ContentIsDirty;
|
||||||
//LBDocumentClass doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
|
//LBDocumentClass doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
|
||||||
//return !doc.Saved;
|
//return !doc.Saved;
|
||||||
}
|
}
|
||||||
@ -545,7 +546,8 @@ namespace Volian.Controls.Library
|
|||||||
{
|
{
|
||||||
if (OverrideClose)
|
if (OverrideClose)
|
||||||
return false;
|
return false;
|
||||||
if (IsDirty)
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
if (IsDirty || MyDSOFile.MyDocument.ContentIsDirty)
|
||||||
{
|
{
|
||||||
// Unfortunately, the only way to handle view mode for DSO Framer is to not save.
|
// Unfortunately, the only way to handle view mode for DSO Framer is to not save.
|
||||||
if (PanelViewEditMode == E_ViewMode.View || !_AllowedToEdit)
|
if (PanelViewEditMode == E_ViewMode.View || !_AllowedToEdit)
|
||||||
@ -554,12 +556,24 @@ namespace Volian.Controls.Library
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//if (MessageBox.Show("Save changes to " + _MyDisplayTabItem.MyItemInfo.TabTitle + "\r\n" + _MyDisplayTabItem.MyItemInfo.TabToolTip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
//if (MessageBox.Show("Save changes to " + _MyDisplayTabItem.MyItemInfo.TabTitle + "\r\n" + _MyDisplayTabItem.MyItemInfo.TabToolTip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
if (MessageBox.Show("Save changes to " + _MyDisplayTabItem.Text + "\r\n" + _MyDisplayTabItem.Tooltip, "Document has Changed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
if (MessageBox.Show("Save changes to " + (MyDSOFile.MyDocument.ContentIsDirty ? "Recovered Version of " : "") + _MyDisplayTabItem.Text + "\r\n" + _MyDisplayTabItem.Tooltip,
|
||||||
|
(IsDirty ? "Document has Changed" : "Previous Changes were not saved."), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
return SaveDSO();
|
return SaveDSO();
|
||||||
|
//Console.WriteLine("Delete {0}", MyDSOFile.MyFile.Name);
|
||||||
|
DeleteOnClose = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
private bool _DeleteOnClose = false;
|
||||||
|
|
||||||
|
public bool DeleteOnClose
|
||||||
|
{
|
||||||
|
get { return _DeleteOnClose; }
|
||||||
|
set { _DeleteOnClose = value; }
|
||||||
|
}
|
||||||
public static bool IgnoreEnter = false;
|
public static bool IgnoreEnter = false;
|
||||||
private bool _In_DSOTabPanel_Enter=false;
|
private bool _In_DSOTabPanel_Enter=false;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -638,6 +652,8 @@ namespace Volian.Controls.Library
|
|||||||
components.Remove(_MyEdWord);
|
components.Remove(_MyEdWord);
|
||||||
_MyEdWord.Dispose();
|
_MyEdWord.Dispose();
|
||||||
_MyEdWord = null;
|
_MyEdWord = null;
|
||||||
|
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||||
|
if (DeleteOnClose) MyDSOFile.MyFile.Delete();
|
||||||
_Count--;
|
_Count--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user