Example #1
0
        XElement XmlValue(SettingsSection section, Property prop)
        {
            string name = prop.Name;

            if (KnownSettings.ShouldSkip(section, name))
            {
                return(null);
            }

            object value;

            try {
                value = prop.Value;
            } catch (COMException ex) {
                logger.Log((string)("An error occurred while saving " + section + "#" + name + ": " + ex.Message));
                return(null);
            }
            var collection = value as ICollection;

            if (collection == null)
            {
                return(new XElement("PropertyValue", new XAttribute("name", name), value));
            }

            return(new XElement("PropertyValue",
                                new XAttribute("name", name),
                                new XAttribute("ArrayType", "VT_VARIANT"),
                                new XAttribute("ArrayElementCount", collection.Count),
                                ((IEnumerable <object>)value)
                                .Select((v, i) => new XElement("PropertyValue", new XAttribute("name", i), v))
                                ));
        }
Example #2
0
        ///<summary>Reads settings from the XML file into Visual Studio's global settings.</summary>
        private void LoadSettings()
        {
            var xml = XDocument.Load(SettingsPath, LoadOptions.PreserveWhitespace);

            foreach (var section in SettingsSection.FromXmlSettingsFile(xml.Root))
            {
                if (!KnownSettings.IsAllowed(section.Item1))
                {
                    logger.Log("Warning: Not loading unsafe category " + section.Item1 + ".  You may have a malicious Rebracer.xml file.");
                    continue;
                }

                Properties container;
                try {
                    container = dte.Properties(section.Item1);
                } catch (Exception ex) {
                    logger.Log("Warning: Not loading unsupported category " + section.Item1 + " from settings file; you may be missing an extension.  Error: " + ex.Message);
                    continue;
                }

                foreach (var property in section.Item2.Elements("PropertyValue"))
                {
                    string name = property.Attribute("name").Value;
                    if (KnownSettings.ShouldSkip(section.Item1, name))
                    {
                        continue;
                    }
                    try {
                        container.Item(name).Value = VsValue(property);
                    } catch (Exception ex) {
                        logger.Log("An error occurred while reading the setting " + section.Item1 + "#" + name + " from settings file.  Error: " + ex.Message);
                    }
                }
            }
        }
Example #3
0
        XElement XmlValue(SettingsSection section, Property prop)
        {
            string name = prop.Name;

            if (KnownSettings.ShouldSkip(section, name))
            {
                return(null);
            }

            object value;

            try {
                value = prop.Value;
            } catch (COMException ex) {
                logger.Log((string)("An error occurred while saving " + section + "#" + name + ": " + ex.Message));
                return(null);
            } catch (InvalidOperationException) {
                // The InvalidOperationException is thrown when property is internal, read only or write only, so
                // property value cannot be set or get.
                return(null);
            }
            var collection = value as ICollection;

            if (collection == null)
            {
                return(new XElement("PropertyValue", new XAttribute("name", name), value));
            }

            return(new XElement("PropertyValue",
                                new XAttribute("name", name),
                                new XAttribute("ArrayType", "VT_VARIANT"),
                                new XAttribute("ArrayElementCount", collection.Count),
                                ((IEnumerable <object>)value)
                                .Select((v, i) => new XElement("PropertyValue", new XAttribute("name", i), v))
                                ));
        }
Example #4
0
        ///<summary>Reads settings from the XML file into Visual Studio's global settings.</summary>
        private void LoadSettings()
        {
            var  xml      = XDocument.Load(SettingsPath, LoadOptions.PreserveWhitespace);
            bool modified = false;

            foreach (var section in SettingsSection.FromXmlSettingsFile(xml.Root))
            {
                if (!KnownSettings.IsAllowed(section.Item1))
                {
                    logger.Log("Warning: Not loading unsafe category " + section.Item1 + ".  You may have a malicious Rebracer.xml file.");
                    continue;
                }

                Properties container;
                try {
                    container = dte.Properties(section.Item1);
                } catch (Exception ex) {
                    logger.Log("Warning: Not loading unsupported category " + section.Item1 + " from settings file; you may be missing an extension.  Error: " + ex.Message);
                    continue;
                }

                List <XElement> elements = section.Item2.Elements("PropertyValue").ToList();

                foreach (var property in elements)
                {
                    string name = property.Attribute("name").Value;
                    if (KnownSettings.ShouldSkip(section.Item1, name))
                    {
                        continue;
                    }
                    try {
                        Property p;

                        try {
                            p = container.Item(name);
                        } catch (ArgumentException ex) {
                            if ((uint)ex.HResult == 0x80070057)                             // E_INVALIDARG, Property does not exists.
                            {
                                // This error occurs when the IDE property does not exist at this time.

                                continue;
                            }
                            logger.Log("An error occurred while reading the setting " + section.Item1 + "#" + name + " from settings file.  Error: " + ex.Message);
                            continue;
                        }

                        p.Value = VsValue(property);
                    } catch (COMException ex) {
                        if ((uint)ex.HResult == 0x80020003)                         // DISP_E_MEMBERNOTFOUND
                        {
                            // MSDN: A return value indicating that the requested member does not exist, or the call to Invoke
                            // tried to set the value of a read-only property. So this is not error.

                            continue;
                        }

                        logger.Log("An error occurred while reading the setting " + section.Item1 + "#" + name + " from settings file.  Error: " + ex.Message);
                    } catch (Exception ex) {
                        logger.Log("An error occurred while reading the setting " + section.Item1 + "#" + name + " from settings file.  Error: " + ex.Message);
                    }
                }
            }
        }