示例#1
0
        /// <summary>
        /// Open the document. Either returns a document or throws.
        /// </summary>
        public CadKit.Interfaces.IDocument open(string name, ChooseBestOpenerDelegate del, object caller)
        {
            // Re-entrant! Do not lock the mutex!

            // Look for existing document with this name.
            CadKit.Interfaces.IDocument document = this.findDocument(name);
            if (null != document)
            {
                this.windowsForward(document, caller);
                return(document);
            }

            // Determine the opener that handles this extension.
            CadKit.Interfaces.IDocumentOpen opener = this._findBestOpener(name, del, caller);
            if (null == opener)
            {
                System.IO.FileInfo info = new System.IO.FileInfo(name);
                throw new System.Exception("Error 4027629339: Failed to find plugin that opens files with extension '" + info.Extension + "'");
            }

            // Open the document. This may throw.
            document = (CadKit.Interfaces.IDocument)(opener.open(name, caller));

            // If we get to here then add the new document.
            this.addDocument(document);

            // Return new document.
            return(document);
        }
示例#2
0
        /// <summary>
        /// Determine appropriate opener. Pass null for the delegate to get first one.
        /// </summary>
        private CadKit.Interfaces.IDocumentOpen _findBestOpener(string name, ChooseBestOpenerDelegate del, object caller)
        {
            // Re-entrant! Do not lock the mutex! When opening plugins they may
            // call back to this class and try to lock the mutex.

            CadKit.Interfaces.IDocumentOpen[] openers = this._findOpeners(name);
            if (null == openers || 0 == openers.Length)
            {
                return(null);
            }
            return((null != del) ? openers[del(openers, caller)] : openers[0]);
        }