/// <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("attempts", NumOfAttempts.ToString(CultureInfo.InvariantCulture)), new XAttribute("attemptEpochs", NumOfAttemptEpochs.ToString(CultureInfo.InvariantCulture))); if (!suppressDefaults || !IsDefaultZeroTolerance) { rootElem.Add(new XAttribute("zeroTolerance", ZeroTolerance.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultPositiveEta) { rootElem.Add(new XAttribute("positiveEta", PositiveEta.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultNegativeEta) { rootElem.Add(new XAttribute("negativeEta", NegativeEta.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultIniDelta) { rootElem.Add(new XAttribute("iniDelta", IniDelta.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultMinDelta) { rootElem.Add(new XAttribute("minDelta", MinDelta.ToString(CultureInfo.InvariantCulture))); } if (!suppressDefaults || !IsDefaultMaxDelta) { rootElem.Add(new XAttribute("maxDelta", MaxDelta.ToString(CultureInfo.InvariantCulture))); } Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (NumOfAttempts < 1) { throw new ArgumentException($"Invalid NumOfAttempts {NumOfAttempts.ToString(CultureInfo.InvariantCulture)}. NumOfAttempts must be GE to 1.", "NumOfAttempts"); } if (NumOfAttemptEpochs < 1) { throw new ArgumentException($"Invalid NumOfAttemptEpochs {NumOfAttemptEpochs.ToString(CultureInfo.InvariantCulture)}. NumOfAttemptEpochs must be GE to 1.", "NumOfAttemptEpochs"); } if (ZeroTolerance < 0 || ZeroTolerance >= 1) { throw new ArgumentException($"Invalid ZeroTolerance {ZeroTolerance.ToString(CultureInfo.InvariantCulture)}. ZeroTolerance must be GE to 0 and LT 1.", "ZeroTolerance"); } if (PositiveEta <= 1) { throw new ArgumentException($"Invalid PositiveEta {PositiveEta.ToString(CultureInfo.InvariantCulture)}. PositiveEta must be GT 1.", "PositiveEta"); } if (NegativeEta < 0 || NegativeEta >= 1) { throw new ArgumentException($"Invalid NegativeEta {NegativeEta.ToString(CultureInfo.InvariantCulture)}. NegativeEta must be GE to 0 and LT 1.", "NegativeEta"); } if (IniDelta < 0) { throw new ArgumentException($"Invalid IniDelta {IniDelta.ToString(CultureInfo.InvariantCulture)}. IniDelta must be GE to 0.", "IniDelta"); } if (MinDelta < 0) { throw new ArgumentException($"Invalid MinDelta {MinDelta.ToString(CultureInfo.InvariantCulture)}. MinDelta must be GE to 0.", "MinDelta"); } if (MaxDelta < 0) { throw new ArgumentException($"Invalid MinDelta {MaxDelta.ToString(CultureInfo.InvariantCulture)}. MaxDelta must be GE to 0.", "MaxDelta"); } if (MaxDelta <= MinDelta) { throw new ArgumentException($"Invalid MinDelta or MaxDelta. MaxDelta must be GT MinDelta.", "MaxDelta/MinDelta"); } return; }