コード例 #1
0
        // 'Safe' in the sense that all exceptions are caught (and reported via OnOpenException).
        private IDocument SafeOpen(IDocumentClient client, Uri uri)
        {
            IDocument document = null;

            try
            {
                if (client.CanOpen(uri))
                {
                    if (OnDocumentOpening(uri))
                    {
                        document = client.Open(uri);
                        if (document != null)
                        {
                            OnDocumentOpened(document);
                            DocumentOpened.Raise(this, new DocumentEventArgs(document, DocumentEventType.Opened));

                            DocumentRegistry.ActiveDocument = document;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // DAN: Added this - if an exception occurs during line:
                // DocumentRegistry.ActiveDocument = document;
                // then we need to remove it
                if (DocumentRegistry.ActiveDocument == document)
                {
                    DocumentRegistry.Remove(document);
                }

                document = null;

                // Let's share the exception directly. We used to wrap it in another Exception
                //  object but this hides the actual exception in the error dialog.
                OnOpenException(ex);
            }

            return(document);
        }
コード例 #2
0
        // 'Safe' in the sense that all exceptions are caught (and reported via OnOpenException).
        private IDocument SafeOpen(IDocumentClient client, Uri uri)
        {
            IDocument document = null;
            try
            {
                if (client.CanOpen(uri))
                {
                    if (OnDocumentOpening(uri))
                    {
                        document = client.Open(uri);
                        if (document != null)
                        {
                            OnDocumentOpened(document);
                            DocumentOpened.Raise(this, new DocumentEventArgs(document, DocumentEventType.Opened));

                            DocumentRegistry.ActiveDocument = document;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // DAN: Added this - if an exception occurs during line:
                // DocumentRegistry.ActiveDocument = document; 
                // then we need to remove it
                if (DocumentRegistry.ActiveDocument == document)
                    DocumentRegistry.Remove(document);

                document = null;

                // Let's share the exception directly. We used to wrap it in another Exception
                //  object but this hides the actual exception in the error dialog.
                OnOpenException(ex);
            }

            return document;
        }