/// <summary> /// Parse the provided XML input stream with the provided parser. /// Gather the new TaggedDevices and OWPaths into the global vectors /// 'taggedDevices' and 'paths'. /// </summary> /// <param name="parser"> parser to parse 1-Wire XML files </param> /// <param name="stream"> XML file stream </param> /// <param name="currentPath"> OWPath that was opened to get to this file </param> /// <param name="autoSpawnFrames"> true if new DeviceFrames are spawned with /// new taggedDevices discovered </param> /// <returns> true an XML file was successfully parsed. </returns> public static bool parseStream(TAGParser parser, Stream stream, OWPath currentPath, bool autoSpawnFrames) { bool rslt = false; OWPath tempPath; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); try { // parse the file List <TaggedDevice> new_devices = parser.parse(stream); // get the new paths List <OWPath> new_paths = parser.OWPaths; Debug.WriteLine("Success, XML parsed with " + new_devices.Count + " devices " + new_paths.Count + " paths"); // add the new devices to the old list for (int i = 0; i < new_devices.Count; i++) { TaggedDevice current_device = new_devices[i]; // update this devices OWPath depending on where we got it if its OWPath is empty tempPath = current_device.OWPath; if (!tempPath.AllOWPathElements.MoveNext()) { // replace this devices path with the current path tempPath.copy(currentPath); current_device.OWPath = tempPath; } // add the new device to the device list taggedDevices.Add(current_device); } // add the new paths for (int i = 0; i < new_paths.Count; i++) { paths.Add(new_paths[i]); } rslt = true; } catch (Exception e) { Debug.WriteLine("Error: " + e); } stopWatch.Stop(); Debug.WriteLine("Parsed in " + stopWatch.ElapsedMilliseconds + "ms"); return(rslt); }
/// <summary> /// Parse the provided XML input stream with the provided parser. /// Gather the new TaggedDevices and OWPaths into the global vectors /// 'taggedDevices' and 'paths'. /// </summary> /// <param name="parser"> parser to parse 1-Wire XML files </param> /// <param name="stream"> XML file stream </param> /// <param name="currentPath"> OWPath that was opened to get to this file </param> /// <param name="autoSpawnFrames"> true if new DeviceFrames are spawned with /// new taggedDevices discovered </param> /// <returns> true an XML file was successfully parsed. </returns> public static bool parseStream(TAGParser parser, Stream stream, OWPath currentPath, bool autoSpawnFrames) { bool rslt = false; OWPath tempPath; try { // parse the file List <TaggedDevice> new_devices = parser.parse(stream); // get the new paths List <OWPath> new_paths = parser.OWPaths; main_Renamed.Status = "Success, XML parsed with " + new_devices.Count + " devices " + new_paths.Count + " paths"; // add the new devices to the old list for (int i = 0; i < new_devices.Count; i++) { TaggedDevice current_device = (TaggedDevice)new_devices[i]; // update this devices OWPath depending on where we got it if its OWPath is empty tempPath = current_device.OWPath; if (!tempPath.AllOWPathElements.MoveNext()) { // replace this devices path with the current path tempPath.copy(currentPath); current_device.OWPath = tempPath; } // check if spawning frames if (autoSpawnFrames) { if (current_device is TaggedSensor) { main_Renamed.Status = "Spawning Sensor: " + current_device.Label; deviceFrames.Add(new DeviceMonitorSensor(current_device, logFile)); } else if (current_device is TaggedActuator) { main_Renamed.Status = "Spawning Actuator: " + current_device.Label; deviceFrames.Add(new DeviceMonitorActuator(current_device, logFile)); } } // add the new device to the device list taggedDevices.Add(current_device); } // add the new paths for (int i = 0; i < new_paths.Count; i++) { paths.Add(new_paths[i]); } rslt = true; } catch (org.xml.sax.SAXException se) { main_Renamed.Status = "XML error: " + se; } catch (IOException ioe) { main_Renamed.Status = "IO error: " + ioe; } return(rslt); }