/// <summary> /// Create a complexity regulation strategy based on the provided XML config values. /// </summary> public static IComplexityRegulationStrategy CreateComplexityRegulationStrategy(XmlElement xmlConfig, string complexityElemName) { // Get root activation element. XmlNodeList nodeList = xmlConfig.GetElementsByTagName(complexityElemName, ""); if (nodeList.Count != 1) { throw new ArgumentException("Missing or invalid complexity XML config setting."); } XmlElement xmlComplexity = nodeList[0] as XmlElement; string complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlComplexity, "ComplexityRegulationStrategy"); int? complexityThreshold = XmlUtils.TryGetValueAsInt(xmlComplexity, "ComplexityThreshold"); ComplexityCeilingType ceilingType; if (!Enum.TryParse <ComplexityCeilingType>(complexityRegulationStr, out ceilingType)) { return(new NullComplexityRegulationStrategy()); } if (null == complexityThreshold) { throw new ArgumentNullException("threshold", string.Format("threshold must be provided for complexity regulation strategy type [{0}]", ceilingType)); } return(new DefaultComplexityRegulationStrategy(ceilingType, complexityThreshold.Value)); }
/// <summary> /// Read Parallel Extensions options from config XML. /// </summary> /// <param name="xmlConfig"></param> /// <returns></returns> public static ParallelOptions ReadParallelOptions(XmlElement xmlConfig) { // Get parallel options. ParallelOptions parallelOptions; int? maxDegreeOfParallelism = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxDegreeOfParallelism"); if (null != maxDegreeOfParallelism) { parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism.Value }; } else { parallelOptions = new ParallelOptions(); } return(parallelOptions); }