Device.fromXML constructor
Device.fromXML(
- String xmlSTR
Implementation
factory Device.fromXML(String xmlSTR) {
final document = XmlDocument.parse(xmlSTR);
String deviceIndex = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "deviceIndex").value;
String deviceName = document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "deviceName").value;
String deviceParameterType =
document.firstChild!.attributes.firstWhere((element) => element.name.toString() == "deviceParameterType").value;
XmlElement? interfaceModesElement = document.firstChild!.getElement("supportedInterfaceModes");
List<XmlElement> devicesElements = document.firstChild!.findElements("device").toList();
List<XmlElement> interfacesElements = interfaceModesElement!.findElements("interfaceMode").toList();
List<InterfaceMode> interfaceModes = interfacesElements.map((e) => InterfaceMode.fromXML(e.toXmlString())).toList();
List<Device> devices = devicesElements.map((e) => Device.fromXML(e.toXmlString())).toList();
DeviceParameter deviceParameter;
XmlElement? deviceParameterElement = document.firstChild!.getElement(deviceParameterType);
String deviceParameterXML = deviceParameterElement!.toXmlString();
// print("$deviceParameterType $deviceIndex ${devices.map((e) => e.deviceIndex).toList()}");
switch (deviceParameterType) {
case "bpDeviceParameter":
deviceParameter = BpDeviceParameter.fromXML(deviceParameterXML);
BpDeviceParameter dp = BpDeviceParameter.fromXML(deviceParameterXML);
BpDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "btDeviceParameter":
deviceParameter = BtDeviceParameter.fromXML(deviceParameterXML);
BtDeviceParameter dp = BtDeviceParameter.fromXML(deviceParameterXML);
BtDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "bcDeviceParameter":
deviceParameter = BcDeviceParameter.fromXML(deviceParameterXML);
BcDeviceParameter dp = BcDeviceParameter.fromXML(deviceParameterXML);
BcDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "beDeviceParameter":
deviceParameter = BeDeviceParameter.fromXML(deviceParameterXML);
BeDeviceParameter dp = BeDeviceParameter.fromXML(deviceParameterXML);
BeDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "ocDeviceParameter":
deviceParameter = OcDeviceParameter.fromXML(deviceParameterXML);
OcDeviceParameter dp = OcDeviceParameter.fromXML(deviceParameterXML);
OcDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "msDeviceParameter":
deviceParameter = MsDeviceParameter.fromXML(deviceParameterXML);
MsDeviceParameter dp = MsDeviceParameter.fromXML(deviceParameterXML);
MsDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "prDeviceParameter":
deviceParameter = PrDeviceParameter.fromXML(deviceParameterXML);
PrDeviceParameter dp = PrDeviceParameter.fromXML(deviceParameterXML);
PrDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "bgDeviceParameter":
deviceParameter = BgDeviceParameter.fromXML(deviceParameterXML);
BgDeviceParameter dp = BgDeviceParameter.fromXML(deviceParameterXML);
BgDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "ddDeviceParameter":
deviceParameter = DdDeviceParameter.fromXML(deviceParameterXML);
DdDeviceParameter dp = DdDeviceParameter.fromXML(deviceParameterXML);
DdDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "zlDeviceParameter":
deviceParameter = ZlDeviceParameter.fromXML(deviceParameterXML);
ZlDeviceParameter dp = ZlDeviceParameter.fromXML(deviceParameterXML);
ZlDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
case "ziDeviceParameter":
deviceParameter = ZiDeviceParameter.fromXML(deviceParameterXML);
ZiDeviceParameter dp = ZiDeviceParameter.fromXML(deviceParameterXML);
ZiDevice(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: dp,
);
break;
default:
deviceParameter = BpDeviceParameter.fromXML(deviceParameterXML);
}
return Device(
deviceIndex: deviceIndex,
deviceName: deviceName,
deviceParameterType: deviceParameterType,
devices: devices,
supportedInterfaceModes: interfaceModes,
deviceParameter: deviceParameter,
socketService: SocketService(ip: deviceParameter.ipAndPort.ip, port: int.tryParse(deviceParameter.ipAndPort.port) ?? 0));
}