Fix MAGN-3799 Revit 2015 crash switching documents.

@pboyer 

When a document is closed, the reference hold by us to the UI document is invalid in Revit 2015. An attempt to get its document will cause a crash. I have checked the code history and found that originally we are using a document closing event to check the document because at that time the UI document is still valid.

This submission recovers some of the code that has been deleted. The document comparison is done inside the document closing handler and when the document is closed, the UI document hold by us will be reset.

This problem does not occur in Revit 2014. It is found at the time the document is closed, we can still get the document of the UI document that is closed.