Esempio n. 1
0
 public SettingsMerger(Settings localSettings, StyleCopEnvironment environment)
 {
     Param.RequireNotNull(localSettings, "localSettings");
     Param.RequireNotNull(environment, "environment");
     this.localSettings = localSettings;
     this.environment = environment;
 }
Esempio n. 2
0
 public StyleCopCore(StyleCopEnvironment environment, object hostTag)
 {
     this.writeResultsCache = true;
     this.displayUI = true;
     this.parsers = new Dictionary<string, SourceParser>();
     this.analyzers = new Dictionary<string, SourceAnalyzer>();
     this.registry = new RegistryUtils();
     this.coreParser = new CoreParser();
     this.environment = environment;
     this.hostTag = hostTag;
     if (this.environment == null)
     {
         this.environment = new FileBasedEnvironment();
     }
     this.environment.Core = this;
     this.log = new Log(this);
     try
     {
         using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.StyleCop.CoreParser.xml"))
         {
             using (StreamReader reader = new StreamReader(stream))
             {
                 string xml = reader.ReadToEnd();
                 XmlDocument initializationXml = new XmlDocument();
                 initializationXml.LoadXml(xml);
                 this.coreParser.Initialize(this, initializationXml, true, true);
             }
         }
     }
     catch (XmlException)
     {
         AlertDialog.Show(this, null, Strings.StyleCopUnableToLoad, Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
     catch (ArgumentException exception)
     {
         AlertDialog.Show(this, null, string.Format(CultureInfo.CurrentUICulture, Strings.StyleCopUnableToLoad, new object[] { exception.Message }), Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
 }
Esempio n. 3
0
        public StyleCopCore(StyleCopEnvironment environment, object hostTag)
        {
            Param.Ignore(environment);
            Param.Ignore(hostTag);

            this.environment = environment;
            this.hostTag = hostTag;

            // If no environment was provided, use the file based environment.
            if (this.environment == null)
            {
                this.environment = new FileBasedEnvironment();
            }

            this.environment.Core = this;

            // Set up the logger.
            this.log = new Log(this);

            // Load the core xml initialization document.
            try
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.StyleCop.CoreParser.xml"))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string xml = reader.ReadToEnd();
                    XmlDocument parserXml = new XmlDocument();
                    parserXml.LoadXml(xml);
                    this.coreParser.Initialize(this, parserXml, true, true);
                }
            }
            catch (XmlException)
            {
                AlertDialog.Show(
                    this,
                    null,
                    Strings.StyleCopUnableToLoad,
                    Strings.Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            catch (ArgumentException argex)
            {
                AlertDialog.Show(
                    this,
                    null,
                    string.Format(CultureInfo.CurrentUICulture, Strings.StyleCopUnableToLoad, argex.Message),
                    Strings.Title,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the StyleCopCore class.
 /// </summary>
 /// <param name="environment">The environment that StyleCop is running under.</param>
 public StyleCopCore(StyleCopEnvironment environment)
     : this(environment, null)
 {
     Param.Ignore(environment);
 }
        public XmlDocument WriteSettingsToDocument(StyleCopEnvironment environment)
        {
            Param.RequireNotNull(environment, "environment");

            // Create a new document for the settings.
            XmlDocument document = WritableSettings.NewDocument();

            // Get the parent settings if there are any.
            SettingsMerger merger = new SettingsMerger(this, environment);
            Settings parentSettings = merger.ParentMergedSettings;

            // Add the global settings if there are any.
            if (this.GlobalSettings != null && this.GlobalSettings.Count > 0)
            {
                // Get the global settings from the parent.
                PropertyCollection parentGlobalSettings = null;
                if (parentSettings != null)
                {
                    parentGlobalSettings = parentSettings.GlobalSettings;
                }

                SavePropertyCollection(document.DocumentElement, "GlobalSettings", this.GlobalSettings, parentGlobalSettings, true, null);
            }

            // Add the parser settings if there are any.
            if (this.ParserSettings.Count > 0)
            {
                bool parserSettingsAdded = false;
                XmlElement parsersNode = document.CreateElement("Parsers");

                foreach (AddInPropertyCollection parserSettings in this.ParserSettings)
                {
                    // Add the settings for this parser if there are any.
                    if (parserSettings.Count > 0)
                    {
                        // Create a node for this parser.
                        XmlElement parserNode = document.CreateElement("Parser");
                        XmlAttribute parserIdAttribute = document.CreateAttribute("ParserId");
                        parserIdAttribute.Value = parserSettings.AddIn.Id;
                        parserNode.Attributes.Append(parserIdAttribute);

                        // Get the parser settings from the parent.
                        PropertyCollection parentParserSettings = null;
                        if (parentSettings != null)
                        {
                            parentParserSettings = parentSettings.GetAddInSettings(parserSettings.AddIn);
                        }

                        if (SavePropertyCollection(parserNode, "ParserSettings", parserSettings, parentParserSettings, true, null))
                        {
                            parsersNode.AppendChild(parserNode);
                            parserSettingsAdded = true;
                        }
                    }
                }

                if (parserSettingsAdded)
                {
                    document.DocumentElement.AppendChild(parsersNode);
                }
            }

            // Add the analyzer settings if there are any.
            if (this.AnalyzerSettings.Count > 0)
            {
                bool analyzerSettingsAdded = false;
                XmlElement analyzersNode = document.CreateElement("Analyzers");

                foreach (AddInPropertyCollection analyzerSettings in this.AnalyzerSettings)
                {
                    // Add the settings for this analyzer if there are any.
                    if (analyzerSettings.Count > 0)
                    {
                        // Create a node for this analzyer.
                        XmlElement analyzerNode = document.CreateElement("Analyzer");
                        XmlAttribute analyzerIdAttribute = document.CreateAttribute("AnalyzerId");
                        analyzerIdAttribute.Value = analyzerSettings.AddIn.Id;
                        analyzerNode.Attributes.Append(analyzerIdAttribute);

                        // Get the analyzer settings from the parent.
                        PropertyCollection parentAnalyzerSettings = null;
                        if (parentSettings != null)
                        {
                            parentAnalyzerSettings = parentSettings.GetAddInSettings(analyzerSettings.AddIn);
                        }

                        if (SavePropertyCollection(analyzerNode, "AnalyzerSettings", analyzerSettings, parentAnalyzerSettings, true, null))
                        {
                            analyzersNode.AppendChild(analyzerNode);
                            analyzerSettingsAdded = true;
                        }
                    }
                }

                if (analyzerSettingsAdded)
                {
                    document.DocumentElement.AppendChild(analyzersNode);
                }
            }

            return document;
        }
Esempio n. 6
0
        /// <summary>
        /// Determines the type of merge to perform, based on the local settings file.
        /// </summary>
        /// <param name="settings">The settings file</param>
        /// <param name="environment">The environment.</param>
        /// <returns>Returns the merge type.</returns>
        private static string DetermineMergeType(Settings settings, StyleCopEnvironment environment)
        {
            Param.AssertNotNull(settings, "settings");
            Param.Ignore(environment);

            StringProperty mergeTypeProperty = settings.GlobalSettings.GetProperty(SettingsMerger.MergeSettingsFilesProperty) as StringProperty;

            string mergeType = SettingsMerger.MergeStyleParent;
            if (mergeTypeProperty != null)
            {
                mergeType = mergeTypeProperty.Value;
            }

            // If the merge style is set to link but the current environment doesn't support linking, change it to parent.
            if ((environment == null || !environment.SupportsLinkedSettings) &&
                string.CompareOrdinal(mergeType, SettingsMerger.MergeStyleLinked) == 0)
            {
                mergeType = SettingsMerger.MergeStyleParent;
            }

            return mergeType;
        }
Esempio n. 7
0
 public StyleCopCore(StyleCopEnvironment environment)
     : this(environment, null)
 {
 }
 public XmlDocument WriteSettingsToDocument(StyleCopEnvironment environment)
 {
     Param.RequireNotNull(environment, "environment");
     XmlDocument document = NewDocument();
     SettingsMerger merger = new SettingsMerger(this, environment);
     Settings parentMergedSettings = merger.ParentMergedSettings;
     if ((base.GlobalSettings != null) && (base.GlobalSettings.Count > 0))
     {
         PropertyCollection parentProperties = null;
         if (parentMergedSettings != null)
         {
             parentProperties = parentMergedSettings.GlobalSettings;
         }
         SavePropertyCollection(document.DocumentElement, "GlobalSettings", base.GlobalSettings, parentProperties, true, null);
     }
     if (base.ParserSettings.Count > 0)
     {
         bool flag = false;
         XmlElement newChild = document.CreateElement("Parsers");
         foreach (AddInPropertyCollection propertys2 in base.ParserSettings)
         {
             if (propertys2.Count > 0)
             {
                 XmlElement rootNode = document.CreateElement("Parser");
                 XmlAttribute node = document.CreateAttribute("ParserId");
                 node.Value = propertys2.AddIn.Id;
                 rootNode.Attributes.Append(node);
                 PropertyCollection addInSettings = null;
                 if (parentMergedSettings != null)
                 {
                     addInSettings = parentMergedSettings.GetAddInSettings(propertys2.AddIn);
                 }
                 if (SavePropertyCollection(rootNode, "ParserSettings", propertys2, addInSettings, true, null))
                 {
                     newChild.AppendChild(rootNode);
                     flag = true;
                 }
             }
         }
         if (flag)
         {
             document.DocumentElement.AppendChild(newChild);
         }
     }
     if (base.AnalyzerSettings.Count > 0)
     {
         bool flag2 = false;
         XmlElement element3 = document.CreateElement("Analyzers");
         foreach (AddInPropertyCollection propertys4 in base.AnalyzerSettings)
         {
             if (propertys4.Count > 0)
             {
                 XmlElement element4 = document.CreateElement("Analyzer");
                 XmlAttribute attribute2 = document.CreateAttribute("AnalyzerId");
                 attribute2.Value = propertys4.AddIn.Id;
                 element4.Attributes.Append(attribute2);
                 PropertyCollection propertys5 = null;
                 if (parentMergedSettings != null)
                 {
                     propertys5 = parentMergedSettings.GetAddInSettings(propertys4.AddIn);
                 }
                 if (SavePropertyCollection(element4, "AnalyzerSettings", propertys4, propertys5, true, null))
                 {
                     element3.AppendChild(element4);
                     flag2 = true;
                 }
             }
         }
         if (flag2)
         {
             document.DocumentElement.AppendChild(element3);
         }
     }
     return document;
 }