/// <summary> /// Creates an initialized instance /// </summary> /// <param name="settingsElem">Xml element containing settings</param> public InputSettings(XElement settingsElem) : this() { //Feeding type XElement feedingElem = settingsElem.Descendants().First(); if (feedingElem.Name.LocalName == "feedingContinuous") { FeedingType = CommonEnums.InputFeedingType.Continuous; //Number of booting cycles string bootCyclesAttrValue = feedingElem.Attribute("bootCycles").Value; if (bootCyclesAttrValue == "Auto") { //Automatic - will be set later BootCycles = -1; } else { BootCycles = int.Parse(bootCyclesAttrValue, CultureInfo.InvariantCulture); } //Routing of external input to readout layer RouteExternalInputToReadout = bool.Parse(feedingElem.Attribute("routeToReadout").Value); } else { FeedingType = CommonEnums.InputFeedingType.Patterned; BootCycles = 0; } //Fields Dictionary <string, string> uniquenessChecker = new Dictionary <string, string>(); //External fields foreach (XElement extFieldElem in settingsElem.Descendants("external").First().Descendants()) { string fieldName = extFieldElem.Attribute("name").Value; if (uniquenessChecker.ContainsKey(fieldName)) { throw new Exception($"Duplicit input field name {fieldName}"); } uniquenessChecker.Add(fieldName, fieldName); ExternalFieldCollection.Add(new Field(fieldName)); } //Internal fields XElement intFieldsElem = settingsElem.Descendants("internal").FirstOrDefault(); if (intFieldsElem != null) { foreach (XElement intFieldElem in intFieldsElem.Descendants("field")) { string fieldName = intFieldElem.Attribute("name").Value; if (uniquenessChecker.ContainsKey(fieldName)) { throw new Exception($"Duplicit input field name: {fieldName}"); } uniquenessChecker.Add(fieldName, fieldName); InternalFieldCollection.Add(new InternalField(fieldName, intFieldElem.Descendants().First())); } } return; }
/// <summary> /// The deep copy constructor. /// </summary> /// <param name="source">Source instance</param> public InputSettings(InputSettings source) : this() { FeedingType = source.FeedingType; BootCycles = source.BootCycles; RouteInputToReadout = source.RouteInputToReadout; foreach (ExternalField field in source.ExternalFieldCollection) { ExternalFieldCollection.Add((ExternalField)field.DeepClone()); } foreach (InternalField field in source.InternalFieldCollection) { InternalFieldCollection.Add((InternalField)field.DeepClone()); } return; }