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
|
||||
{
|
||||
// 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();
|
||||
|
@ -50,8 +50,32 @@ namespace Volian.Base.Library
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
@ -86,7 +86,8 @@ namespace Volian.Controls.Library
|
||||
get
|
||||
{
|
||||
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());
|
||||
//return !doc.Saved;
|
||||
}
|
||||
@ -545,7 +546,8 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
if (OverrideClose)
|
||||
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.
|
||||
if (PanelViewEditMode == E_ViewMode.View || !_AllowedToEdit)
|
||||
@ -554,12 +556,24 @@ namespace Volian.Controls.Library
|
||||
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.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();
|
||||
//Console.WriteLine("Delete {0}", MyDSOFile.MyFile.Name);
|
||||
DeleteOnClose = true;
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
private bool _In_DSOTabPanel_Enter=false;
|
||||
/// <summary>
|
||||
@ -638,6 +652,8 @@ namespace Volian.Controls.Library
|
||||
components.Remove(_MyEdWord);
|
||||
_MyEdWord.Dispose();
|
||||
_MyEdWord = null;
|
||||
// B2017-249 Recover Temporary File And AutoSave support for MSWord
|
||||
if (DeleteOnClose) MyDSOFile.MyFile.Delete();
|
||||
_Count--;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user