/// <summary> /// Generates xml element containing the settings. /// </summary> /// <param name="rootElemName">Name to be used as a name of the root element.</param> /// <param name="suppressDefaults">Specifies whether to ommit optional nodes having set default values</param> /// <returns>XElement containing the settings</returns> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName, new XAttribute("targetPool", TargetPoolName), new XAttribute("targetConnDensity", TargetConnectionDensity.ToString(CultureInfo.InvariantCulture)), new XAttribute("sourcePool", SourcePoolName), new XAttribute("sourceConnDensity", SourceConnectionDensity.ToString(CultureInfo.InvariantCulture)) ); if (!suppressDefaults || !IsDefaultConstantNumOfConnections) { rootElem.Add(new XAttribute("constantNumOfConnections", ConstantNumOfConnections.ToString(CultureInfo.InvariantCulture).ToLowerInvariant())); } Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (TargetPoolName.Length == 0) { throw new ArgumentException($"TargetPoolName can not be empty.", "TargetPoolName"); } if (TargetConnectionDensity < 0 || TargetConnectionDensity > 1) { throw new ArgumentException($"Invalid TargetConnectionDensity {TargetConnectionDensity.ToString(CultureInfo.InvariantCulture)}. Density must be GE to 0 and LE to 1.", "TargetConnectionDensity"); } if (SourcePoolName.Length == 0) { throw new ArgumentException($"SourcePoolName can not be empty.", "SourcePoolName"); } if (SourceConnectionDensity < 0 || SourceConnectionDensity > 1) { throw new ArgumentException($"Invalid SourceConnectionDensity {SourceConnectionDensity.ToString(CultureInfo.InvariantCulture)}. Density must be GE to 0 and LE to 1.", "SourceConnectionDensity"); } if (SourcePoolName == TargetPoolName) { throw new ArgumentException($"SourcePoolName and TargetPoolName can not be the same.", "SourcePoolName"); } return; }