src/Misc/EFTools/DesignXmlCore/Model/VisualStudio/VSXmlModelProvider.cs
/// <summary>
///     Returns the Xml model for a given file token, or null
///     if there is no Xml model for the token.
/// </summary>
Returns the Xml model for a given file token, or null
if there is no Xml model for the token.
Returns the Xml model for a given file token or null if there is no Xml model for the token .
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        public override XmlModel GetXmlModel(Uri sourceUri)
        {
            Debug.Assert(_xmlDesignerPackage.IsForegroundThread, "Can't request an XmlModel on background thread");
#if DEBUG
            var skipChecks = false;
#if VS12ORNEWER
            var solution = (IVsSolution)_services.GetService(typeof (IVsSolution));
            object propertyValue;
            if(solution != null && NativeMethods.Succeeded(solution.GetProperty((int)__VSPROPID2.VSPROPID_IsSolutionOpeningDocs, out propertyValue)))
            {
                skipChecks = true;
            }
#endif
            if (!skipChecks
                && sourceUri.LocalPath.EndsWith(".edmx", StringComparison.OrdinalIgnoreCase))
            {
                IVsUIHierarchy hier;
                uint itemId;
                IVsWindowFrame windowFrame;
                var isDocumentOpen = VsShellUtilities.IsDocumentOpen(
                    _services, sourceUri.LocalPath, Guid.Empty, out hier, out itemId, out windowFrame);
                Debug.Assert(isDocumentOpen, "Running Document Table does not contain document in GetXmlModel()");
                if (isDocumentOpen)
                {
                    var frameWrapper = _xmlDesignerPackage.DocumentFrameMgr.CreateFrameWrapper(windowFrame);
                    Debug.Assert(frameWrapper != null, "Could not construct FrameWrapper for IVsWindowFrame in debug code in GetXmlModel()");
                    if (frameWrapper != null)
                    {
                        Debug.Assert(
                            frameWrapper.IsDesignerDocInDesigner,
                            "We are trying to GetXmlModel() for a document that is not owned by the designer");
                    }
                }
            }
#endif
            VSXmlModel vsXmlModel = null;
            if (!_xmlModels.TryGetValue(sourceUri, out vsXmlModel))
            {
                Microsoft.VisualStudio.XmlEditor.XmlModel xmlModel = null;
                try
                {
                    xmlModel = _xmlStore.OpenXmlModel(sourceUri);
                }
                catch (Exception)
                {
                    xmlModel = null;
                }
                if (xmlModel != null)
                {
                    vsXmlModel = new VSXmlModel(_services, xmlModel);
                    _xmlModels.Add(sourceUri, vsXmlModel);
                }
            }
            return vsXmlModel;
        }
[ SuppressMessage ( " " , " " ) ] public override XmlModel GetXmlModel ( Uri sourceUri ) { Debug . Assert ( _xmlDesignerPackage . IsForegroundThread , " " ) ; if DEBUG var skipChecks = false ; if VS12ORNEWER var solution = ( IVsSolution ) _services . GetService ( typeof ( IVsSolution ) ) ; object propertyValue ; if ( solution != null && NativeMethods . Succeeded ( solution . GetProperty ( ( int ) __VSPROPID2 . VSPROPID_IsSolutionOpeningDocs , out propertyValue ) ) ) { skipChecks = true ; } endif if ( ! skipChecks && sourceUri . LocalPath . EndsWith ( " " , StringComparison . OrdinalIgnoreCase ) ) { IVsUIHierarchy hier ; uint itemId ; IVsWindowFrame windowFrame ; var isDocumentOpen = VsShellUtilities . IsDocumentOpen ( _services , sourceUri . LocalPath , Guid . Empty , out hier , out itemId , out windowFrame ) ; Debug . Assert ( isDocumentOpen , " " ) ; if ( isDocumentOpen ) { var frameWrapper = _xmlDesignerPackage . DocumentFrameMgr . CreateFrameWrapper ( windowFrame ) ; Debug . Assert ( frameWrapper != null , " " ) ; if ( frameWrapper != null ) { Debug . Assert ( frameWrapper . IsDesignerDocInDesigner , " " ) ; } } } endif VSXmlModel vsXmlModel = null ; if ( ! _xmlModels . TryGetValue ( sourceUri , out vsXmlModel ) ) { Microsoft . VisualStudio . XmlEditor . XmlModel xmlModel = null ; try { xmlModel = _xmlStore . OpenXmlModel ( sourceUri ) ; } catch ( Exception ) { xmlModel = null ; } if ( xmlModel != null ) { vsXmlModel = new VSXmlModel ( _services , xmlModel ) ; _xmlModels . Add ( sourceUri , vsXmlModel ) ; } } return vsXmlModel ; }
Returns the Xml model for a given file token, or null
if there is no Xml model for the token.
Returns the Xml model for a given file token or null if there is no Xml model for the token .
// assert that an entry already exists in the RDT for this document and confirm with the designer package that the entry // is owned by the designer.  If this is not the case, the xml editor will create a doc data, and this may not be the doc  // data we want.  This can result in failure to open the document in the desired designer because the editor is incorrect. // The behaviour of VsShellUtilities.IsDocumentOpen changed in VS2013. In VS2012 IsDocumentOpen would return true if the document // has been loaded even though loading the solution has not finished yet. In VS2013 IsOpenDocument returns false if the solution  // is still being loaded. This caused multiple asserts when opening a project after VS was closed when edmx file was active/opened // See http://entityframework.codeplex.com/workitem/1163 for more details and repro steps. // Alert: when we try to load the XmlModel for diagram file, the document is not opened in VS. //  The If statement is added to skip the check for diagram files.
sourceUri
Uri