public void LoadXmlFragment()

in vsintegration/src/FSharp.ProjectSystem.Base/Project/ProjectNode.cs [4439:4513]


        public void LoadXmlFragment(IPersistXMLFragment persistXmlFragment, string configName)
        {
            if (xmlFragments == null)
            {
                // Retrieve the xml fragments from MSBuild
                xmlFragments = new XmlDocument();
                xmlFragments.XmlResolver = null;
                var ext = GetProjectExtensions();
                string fragments = ext != null ? ext[ProjectFileConstants.VisualStudio] : null; 
                if (!String.IsNullOrEmpty(fragments))
                {
                    fragments = String.Format(CultureInfo.InvariantCulture, "<root>{0}</root>", fragments);
                    using(StringReader stream = new StringReader(fragments))
                    using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings() { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }))
                    {
                        xmlFragments.Load(reader);
                    }
                }
            }

            // We need to loop through all the flavors
            string flavorsGuid;
            ErrorHandler.ThrowOnFailure(((IVsAggregatableProject)this).GetAggregateProjectTypeGuids(out flavorsGuid));
            foreach (Guid flavor in Utilities.GuidsArrayFromSemicolonDelimitedStringOfGuids(flavorsGuid))
            {
                // Look for a matching fragment
                string flavorGuidString = flavor.ToString("B");
                string fragment = null;
                XmlNode node = null;
                if (xmlFragments.FirstChild != null)
                {
                    foreach (XmlNode child in xmlFragments.FirstChild.ChildNodes)
                    {
                        if (child.Attributes.Count > 0)
                        {
                            string guid = String.Empty;
                            string configuration = String.Empty;
                            if (child.Attributes[ProjectFileConstants.Guid] != null)
                                guid = child.Attributes[ProjectFileConstants.Guid].Value;
                            if (child.Attributes[ProjectFileConstants.Configuration] != null)
                                configuration = child.Attributes[ProjectFileConstants.Configuration].Value;

                            if (String.Compare(child.Name, ProjectFileConstants.FlavorProperties, StringComparison.OrdinalIgnoreCase) == 0
                                    && String.Compare(guid, flavorGuidString, StringComparison.OrdinalIgnoreCase) == 0
                                    && ((String.IsNullOrEmpty(configName) && String.IsNullOrEmpty(configuration))
                                        || (String.Compare(configuration, configName, StringComparison.OrdinalIgnoreCase) == 0)))
                            {
                                // we found the matching fragment
                                fragment = child.InnerXml;
                                node = child;
                                break;
                            }
                        }
                    }
                }

                Guid flavorGuid = flavor;
                if (String.IsNullOrEmpty(fragment))
                {
                    // the fragment was not found so init with default values
                    ErrorHandler.ThrowOnFailure(persistXmlFragment.InitNew(ref flavorGuid, (uint)_PersistStorageType.PST_PROJECT_FILE));
                    // While we don't yet support user files, our flavors might, so we will store that in the project file until then
                    // TODO: Refactor this code when we support user files
                    ErrorHandler.ThrowOnFailure(persistXmlFragment.InitNew(ref flavorGuid, (uint)_PersistStorageType.PST_USER_FILE));
                }
                else
                {
                    ErrorHandler.ThrowOnFailure(persistXmlFragment.Load(ref flavorGuid, (uint)_PersistStorageType.PST_PROJECT_FILE, fragment));
                    // While we don't yet support user files, our flavors might, so we will store that in the project file until then
                    // TODO: Refactor this code when we support user files
                    if (node.NextSibling != null && node.NextSibling.Attributes[ProjectFileConstants.User] != null)
                        ErrorHandler.ThrowOnFailure(persistXmlFragment.Load(ref flavorGuid, (uint)_PersistStorageType.PST_USER_FILE, node.NextSibling.InnerXml));
                }
            }
        }