AddCompilerInfo() private method

private AddCompilerInfo ( CompilerInfo compilerInfo ) : void
compilerInfo CompilerInfo
return void
            private static void ProcessCompilersElement(CodeDomCompilationConfiguration result, XmlNode node)
            {
                // reject attributes
                HandlerBase.CheckForUnrecognizedAttributes(node);

                String configFile = ConfigurationErrorsException.GetFilename(node);

                foreach (XmlNode child in node.ChildNodes)
                {
                    int configLineNumber = ConfigurationErrorsException.GetLineNumber(child);

                    // skip whitespace and comments
                    // reject nonelements
                    if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                    {
                        continue;
                    }

                    if (child.Name != "compiler")
                    {
                        HandlerBase.ThrowUnrecognizedElement(child);
                    }

                    String  languages    = String.Empty;
                    XmlNode languageNode = HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "language", ref languages);
                    String  extensions   = String.Empty;
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "extension", ref extensions);
                    String compilerTypeName = null;
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "type", ref compilerTypeName);

                    // Create a CompilerParameters for this compiler.
                    CompilerParameters compilerParams = new CompilerParameters();

                    int warningLevel = 0;
                    if (HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(child, "warningLevel", ref warningLevel) != null)
                    {
                        compilerParams.WarningLevel = warningLevel;

                        // Need to be false if the warning level is 0
                        compilerParams.TreatWarningsAsErrors = (warningLevel > 0);
                    }
                    String compilerOptions = null;
                    if (HandlerBase.GetAndRemoveStringAttribute(child, "compilerOptions", ref compilerOptions) != null)
                    {
                        compilerParams.CompilerOptions = compilerOptions;
                    }

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    // Create a CompilerInfo structure for this compiler
                    CompilerInfo compilerInfo = new CompilerInfo(compilerParams, compilerTypeName);
                    compilerInfo.configFileName       = configFile;
                    compilerInfo.configFileLineNumber = configLineNumber;

                    // Parse the semicolon separated lists
                    string[] languageList  = languages.Split(s_fieldSeparators);
                    string[] extensionList = extensions.Split(s_fieldSeparators);

                    for (int i = 0; i < languageList.Length; i++)
                    {
                        languageList[i] = languageList[i].Trim();
                    }

                    for (int i = 0; i < extensionList.Length; i++)
                    {
                        extensionList[i] = extensionList[i].Trim();
                    }


                    // Validate language names, language names must have length and extensions must start with a period.
                    foreach (string language in languageList)
                    {
                        if (language.Length == 0)
                        {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Language_Names_Cannot_Be_Empty));
                        }
                    }

                    foreach (string extension in extensionList)
                    {
                        if (extension.Length == 0 || extension[0] != '.')
                        {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Extension_Names_Cannot_Be_Empty_Or_Non_Period_Based));
                        }
                    }


                    compilerInfo._compilerLanguages  = languageList;
                    compilerInfo._compilerExtensions = extensionList;

                    result.AddCompilerInfo(compilerInfo);
                }
                // Allow config options to replace redundant compiler entries
                result.RemoveUnmapped();
            }
            private static void ProcessCompilersElement(CodeDomCompilationConfiguration result, XmlNode node) {

                // reject attributes
                HandlerBase.CheckForUnrecognizedAttributes(node);

                String configFile = ConfigurationErrorsException.GetFilename(node);

                foreach(XmlNode child in node.ChildNodes) {
                    int configLineNumber = ConfigurationErrorsException.GetLineNumber(child);

                    // skip whitespace and comments
                    // reject nonelements
                    if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                        continue;

                    if (child.Name != "compiler") {
                        HandlerBase.ThrowUnrecognizedElement(child);
                    }

                    String languages = String.Empty;
                    XmlNode languageNode = HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "language", ref languages);
                    String extensions = String.Empty;
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "extension", ref extensions);
                    String compilerTypeName = null;
                    HandlerBase.GetAndRemoveStringAttribute(child, "type", ref compilerTypeName);

                    // Create a CompilerParameters for this compiler.
                    CompilerParameters compilerParams = new CompilerParameters();

                    int warningLevel = 0;
                    if (HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(child, "warningLevel", ref warningLevel) != null) {
                        compilerParams.WarningLevel = warningLevel;

                        // Need to be false if the warning level is 0
                        compilerParams.TreatWarningsAsErrors = (warningLevel>0);
                    }
                    String compilerOptions = null;
                    if (HandlerBase.GetAndRemoveStringAttribute(child, "compilerOptions", ref compilerOptions) != null) {
                        compilerParams.CompilerOptions = compilerOptions;
                    }

                    IDictionary<string, string> provOptions = GetProviderOptions(child);

                    HandlerBase.CheckForUnrecognizedAttributes(child);

                    // Parse the semicolon separated lists
                    string[] languageList = languages.Split(s_fieldSeparators);
                    string[] extensionList = extensions.Split(s_fieldSeparators);

                    for( int i =0 ; i < languageList.Length; i++) {
                        languageList[i] = languageList[i].Trim();
                    }

                    for( int i =0 ; i < extensionList.Length; i++) {
                        extensionList[i] = extensionList[i].Trim();
                    }


                    // Validate language names, language names must have length and extensions must start with a period.
                    foreach (string language in languageList) {
                        if (language.Length == 0)
                            throw new ConfigurationErrorsException(SR.GetString(SR.Language_Names_Cannot_Be_Empty));
                    }

                    foreach (string extension in extensionList) {
                        if (extension.Length == 0 || extension[0] != '.')
                            throw new ConfigurationErrorsException(SR.GetString(SR.Extension_Names_Cannot_Be_Empty_Or_Non_Period_Based));
                    }

                    
                    // Create a CompilerInfo structure for this compiler, or get
                    // an existing one if no type was provided
                    CompilerInfo compilerInfo = null;
                    if (compilerTypeName != null) {
                        compilerInfo = new CompilerInfo(compilerParams, compilerTypeName);
                    } else {
                        // reconfiguring an existing entry
                        compilerInfo = result.FindExistingCompilerInfo(languageList, extensionList);

                        if (compilerInfo == null) 
                            throw new ConfigurationErrorsException();                        
                    }

                    compilerInfo.configFileName = configFile;
                    compilerInfo.configFileLineNumber = configLineNumber;


                    if (compilerTypeName != null) {
                        compilerInfo._compilerLanguages = languageList;
                        compilerInfo._compilerExtensions = extensionList;
                        compilerInfo._providerOptions = provOptions;

                        result.AddCompilerInfo(compilerInfo);
                    } else {
                        // merge in new options, replacing any previous values w/
                        // new ones.
                        foreach (KeyValuePair<string, string> kvp in provOptions) {
                            compilerInfo._providerOptions[kvp.Key] = kvp.Value;
                        }
                    }
                }
                // Allow config options to replace redundant compiler entries
                result.RemoveUnmapped();
            }
Esempio n. 3
0
            private static void ProcessCompilersElement(CodeDomCompilationConfiguration result, XmlNode node)
            {
                System.CodeDom.Compiler.HandlerBase.CheckForUnrecognizedAttributes(node);
                string filename = ConfigurationErrorsException.GetFilename(node);

                foreach (XmlNode node2 in node.ChildNodes)
                {
                    int lineNumber = ConfigurationErrorsException.GetLineNumber(node2);
                    if (!System.CodeDom.Compiler.HandlerBase.IsIgnorableAlsoCheckForNonElement(node2))
                    {
                        if (node2.Name != "compiler")
                        {
                            System.CodeDom.Compiler.HandlerBase.ThrowUnrecognizedElement(node2);
                        }
                        string val = string.Empty;
                        System.CodeDom.Compiler.HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(node2, "language", ref val);
                        string str3 = string.Empty;
                        System.CodeDom.Compiler.HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(node2, "extension", ref str3);
                        string str4 = null;
                        System.CodeDom.Compiler.HandlerBase.GetAndRemoveStringAttribute(node2, "type", ref str4);
                        CompilerParameters compilerParams = new CompilerParameters();
                        int num2 = 0;
                        if (System.CodeDom.Compiler.HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(node2, "warningLevel", ref num2) != null)
                        {
                            compilerParams.WarningLevel          = num2;
                            compilerParams.TreatWarningsAsErrors = num2 > 0;
                        }
                        string str5 = null;
                        if (System.CodeDom.Compiler.HandlerBase.GetAndRemoveStringAttribute(node2, "compilerOptions", ref str5) != null)
                        {
                            compilerParams.CompilerOptions = str5;
                        }
                        IDictionary <string, string> providerOptions = GetProviderOptions(node2);
                        System.CodeDom.Compiler.HandlerBase.CheckForUnrecognizedAttributes(node2);
                        string[] languageList  = val.Split(CodeDomCompilationConfiguration.s_fieldSeparators);
                        string[] extensionList = str3.Split(CodeDomCompilationConfiguration.s_fieldSeparators);
                        for (int i = 0; i < languageList.Length; i++)
                        {
                            languageList[i] = languageList[i].Trim();
                        }
                        for (int j = 0; j < extensionList.Length; j++)
                        {
                            extensionList[j] = extensionList[j].Trim();
                        }
                        foreach (string str6 in languageList)
                        {
                            if (str6.Length == 0)
                            {
                                throw new ConfigurationErrorsException(System.SR.GetString("Language_Names_Cannot_Be_Empty"));
                            }
                        }
                        foreach (string str7 in extensionList)
                        {
                            if ((str7.Length == 0) || (str7[0] != '.'))
                            {
                                throw new ConfigurationErrorsException(System.SR.GetString("Extension_Names_Cannot_Be_Empty_Or_Non_Period_Based"));
                            }
                        }
                        CompilerInfo compilerInfo = null;
                        if (str4 != null)
                        {
                            compilerInfo = new CompilerInfo(compilerParams, str4);
                        }
                        else
                        {
                            compilerInfo = result.FindExistingCompilerInfo(languageList, extensionList);
                            if (compilerInfo == null)
                            {
                                throw new ConfigurationErrorsException();
                            }
                        }
                        compilerInfo.configFileName       = filename;
                        compilerInfo.configFileLineNumber = lineNumber;
                        if (str4 != null)
                        {
                            compilerInfo._compilerLanguages  = languageList;
                            compilerInfo._compilerExtensions = extensionList;
                            compilerInfo._providerOptions    = providerOptions;
                            result.AddCompilerInfo(compilerInfo);
                        }
                        else
                        {
                            foreach (KeyValuePair <string, string> pair in providerOptions)
                            {
                                compilerInfo._providerOptions[pair.Key] = pair.Value;
                            }
                        }
                    }
                }
                result.RemoveUnmapped();
            }