When saving a document to a stream, if the document was previously modified and then told to be un-modified, the save operation will revert its dirty state back to modified.
How to reproduce:
1. Load a document.
2. Check the modified state:
2.1 The modified state is un-modified.
>> Viewer.DoVerb("Documents[#" + ActiveDocumentId.ToString() + "].Modified", "get", dataIn, out dataOut);
3. Save to a stream.
4. Check the modified state.
4.1 The modified state has not changed.
5. Update the document somehow.
6. Check the modified state:
6.1 The modified state is modified.
7. Save to a stream.
8. Check the modified state.
8.1 The modified state has not changed.
9. Set the modified state to be un-modified.
>> Viewer.DoVerb("Documents[#" + ActiveDocumentId.ToString() + "].Modified", "set", 0, out dataOut);
10. Check the modified state:
10.1 The modified state is un-modified.
11. Save to a stream.
12. Check the modified state.
12.1 The modified state has has changed and is modified.
----------------------------------------
My code:
Code: Select all
public string DebugTestRoutine()
{
string output = "";
try
{
object dataIn = new object();
object dataOut = new object();
// See if we are modified or not going in...
Viewer.DoVerb("Documents[#" + ActiveDocumentId.ToString() + "].Modified", "get", dataIn, out dataOut);
Log.Write(Log.Level.Information, "---------------");
Log.Write(Log.Level.Information, "Document is {0}dirty.", dataOut.ToString() == "0" ? "NOT " : "");
MemoryStream documentStream = new MemoryStream();
StreamWrapper streamWrapper = new StreamWrapper(documentStream);
dataIn = new object[] { ActiveDocumentId, streamWrapper } ;
Viewer.DoVerb(null, "SaveDocument", dataIn, out dataOut, (int) PXCVA_Flags.PXCVA_NoUI);
Viewer.DoVerb("Documents[#" + ActiveDocumentId.ToString() + "].Modified", "get", dataIn, out dataOut);
Log.Write(Log.Level.Information, "Document is {0}dirty.", dataOut.ToString() == "0" ? "NOT " : "");
documentStream.Position = 0;
documentStream.Close();
Log.Write(Log.Level.Information, "Resetting Document to not be dirty.");
Viewer.DoVerb("Documents[#" + ActiveDocumentId.ToString() + "].Modified", "set", 0, out dataOut);
Log.Write(Log.Level.Information, "Done resetting Document to not be dirty.");
Log.Write(Log.Level.Information, "---------------");
}
catch (Exception exception)
{
Log.Write(Log.Level.Error, "BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOM.");
}
return output;
}
*** A document is loaded.
*** The code above is executed three times.
*** Notice that before and after save operation, the document is NOT dirty.
:: ---------------
:: Document is NOT dirty.
Save Operation …
:: Document is NOT dirty.
:: Resetting Document to not be dirty.
:: Done resetting Document to not be dirty.
:: ---------------
:: ---------------
:: Document is NOT dirty.
Save Operation …
:: Document is NOT dirty.
:: Resetting Document to not be dirty.
:: Done resetting Document to not be dirty.
:: ---------------
:: ---------------
:: Document is NOT dirty.
Save Operation …
:: Document is NOT dirty.
:: Resetting Document to not be dirty.
:: Done resetting Document to not be dirty.
:: ---------------
*** I now dirty the document by rotating the page or using the Pencil Tool or ….
*** The code above is executed three more times.
*** Notice that before the save operation, the document is not dirty but after, it becomes dirty. The save operation is ‘remembering’ that originally the document went dirty in its lifetime and is resetting the value back to dirty rather than honoring the current value.
:: ---------------
:: Document is dirty. ******* Note that this is dirty here because I modified the document above with the Pencil Tool.
Save Operation …
:: Document is dirty.
:: Resetting Document to not be dirty.
:: Done resetting Document to not be dirty.
:: ---------------
:: ---------------
:: Document is NOT dirty.
Save Operation …
:: Document is dirty. ******* The Save operation has changed the state of the document from NOT dirty to dirty.
:: Resetting Document to not be dirty.
:: Done resetting Document to not be dirty.
:: ---------------
:: ---------------
:: Document is NOT dirty.
Save Operation …
:: Document is dirty.
:: Resetting Document to not be dirty.
:: Done resetting Document to not be dirty.
:: ---------------