private bool DecodeMachineInfo(string machineInfo, DeviceElement machine) { if (string.IsNullOrEmpty(machineInfo) || machineInfo.Length != 16) return false; byte deviceGroup; if (!byte.TryParse(machineInfo.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out deviceGroup)) return false; if (deviceGroup != 2) // Agricultural devices return false; byte deviceClass; if (!byte.TryParse(machineInfo.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out deviceClass)) return false; machine.DeviceClassification = GetMachineType(deviceClass); return true; }
private DeviceElement LoadMachine(XmlNode inputNode, out string machineId) { var machine = new DeviceElement(); // Required fields. Do not proceed if they are missing machineId = inputNode.GetXmlNodeValue("@A"); if (machineId == null || !DecodeMachineInfo(inputNode.GetXmlNodeValue("@D"), machine)) return null; // Optional fields machine.Description = inputNode.GetXmlNodeValue("@B"); machine.SerialNumber = inputNode.GetXmlNodeValue("@E"); _taskDocument.LoadLinkedIds(machineId, machine.Id); return machine; }