/// <summary> /// Creates a new component /// </summary> internal Component(XElement xmlComponent) { Type = xmlComponent.Name.ToString() ?? String.Empty; id = ParseUtility.GetAttribute(xmlComponent, "id"); Name = ParseUtility.GetAttribute(xmlComponent, "name") == String.Empty ? id : ParseUtility.GetAttribute(xmlComponent, "name"); NativeName = ParseUtility.GetAttribute(xmlComponent, "nativeName"); dataItems = ParseUtility.GetDataItems(xmlComponent); components = ParseUtility.GetComponents(xmlComponent); }
/// <summary> /// Creates a new device from an MTConnect XML device node /// </summary> /// <param name="xElem">The MTConnect XML node which defines the device</param> internal Device(XElement xElem) { if (xElem.Name.LocalName == "Device") { // Populate basic fields id = ParseUtility.GetAttribute(xElem, "id"); Name = ParseUtility.GetAttribute(xElem, "name"); XElement desc = xElem.Descendants().First(x => x.Name.LocalName == "Description"); Description = desc.Value ?? String.Empty; Manufacturer = ParseUtility.GetAttribute(desc, "manufacturer"); SerialNumber = ParseUtility.GetAttribute(desc, "serialNumber"); dataItems = ParseUtility.GetDataItems(xElem); components = ParseUtility.GetComponents(xElem); } }
/// <summary> /// Creates a new component /// </summary> internal Component(XElement xmlComponent) { Type = xmlComponent.Name?.ToString() ?? string.Empty; Id = ParseUtility.GetAttribute(xmlComponent, "id"); Name = ParseUtility.GetAttribute(xmlComponent, "name"); if (string.IsNullOrEmpty(Name)) { Name = Id; } NativeName = ParseUtility.GetAttribute(xmlComponent, "nativeName"); _dataItems = new ObservableCollection <DataItem>(ParseUtility.GetDataItems(xmlComponent)); DataItems = new ReadOnlyObservableCollection <DataItem>(_dataItems); _components = new ObservableCollection <Component>(ParseUtility.GetComponents(xmlComponent)); Components = new ReadOnlyObservableCollection <Component>(_components); }
/// <summary> /// Creates a new device from an MTConnect XML device node /// </summary> /// <param name="xElem">The MTConnect XML node which defines the device</param> internal Device(XElement xElem = null) { DataItems = new ReadOnlyObservableCollection <DataItem>(_dataItems); Components = new ReadOnlyObservableCollection <Component>(_components); if (xElem?.Name.LocalName == "Device") { // Populate basic fields Id = ParseUtility.GetAttribute(xElem, "id"); Name = ParseUtility.GetAttribute(xElem, "name"); var descXml = xElem.Descendants().First(x => x.Name.LocalName == "Description"); Description = descXml.Value ?? string.Empty; Manufacturer = ParseUtility.GetAttribute(descXml, "manufacturer"); SerialNumber = ParseUtility.GetAttribute(descXml, "serialNumber"); _dataItems.AddRange(ParseUtility.GetDataItems(xElem)); _components.AddRange(ParseUtility.GetComponents(xElem)); } }