private void LoadCameraBindXml() { string path = Path.Combine(Application.StartupPath, "camera_bind.xml"); if (File.Exists(path)) { SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); doc.Load(path); XmlNodeList nodes = doc.SelectNodes("//Camera/_"); for (int i = 0; i < nodes.Count; i++) { var selectSingleNode = nodes[i].SelectSingleNode("Name"); if (selectSingleNode != null && selectSingleNode.InnerText == "LeftCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); for (int j = 0; j < comboBoxLeftIp.Items.Count; j++) { if (ip.InnerText.Contains(comboBoxLeftIp.Items[j].ToString())) { comboBoxLeftIp.SelectedIndex = j; break; } } } if (selectSingleNode != null && selectSingleNode.InnerText == "RightCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); for (int j = 0; j < comboBoxRightIp.Items.Count; j++) { if (ip.InnerText.Contains(comboBoxRightIp.Items[j].ToString())) { comboBoxRightIp.SelectedIndex = j; break; } } } } } }
private void SaveCameraBindXml() { string path = Path.Combine(Application.StartupPath, "camera_bind.xml"); SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); if (File.Exists(path)) { doc.Load(path); XmlNodeList nodes = doc.SelectNodes("//Camera/_"); for (int i = 0; i < nodes.Count; i++) { var selectSingleNode = nodes[i].SelectSingleNode("Name"); if (selectSingleNode != null && selectSingleNode.InnerText == "LeftCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxLeftIp.SelectedItem.ToString() + "\""; } if (selectSingleNode != null && selectSingleNode.InnerText == "RightCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxRightIp.SelectedItem.ToString() + "\""; } } } else { XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "", ""); doc.AppendChild(declaration); XmlElement root = doc.CreateElement("opencv_storage"); XmlNode calibrationData = doc.CreateElement("calibrationData"); calibrationData.InnerText = DateTime.Now.ToLongDateString(); root.AppendChild(calibrationData); XmlNode camera = doc.CreateElement("Camera"); root.AppendChild(camera); XmlNode left = doc.CreateElement("_"); XmlNode leftName = doc.CreateElement("Name"); leftName.InnerText = "LeftCamera"; left.AppendChild(leftName); XmlNode leftIpAddress = doc.CreateElement("IPAddress"); leftIpAddress.InnerText = comboBoxLeftIp.SelectedItem.ToString(); left.AppendChild(leftIpAddress); camera.AppendChild(left); XmlNode right = doc.CreateElement("_"); XmlNode rightName = doc.CreateElement("Name"); rightName.InnerText = "RightCamera"; right.AppendChild(rightName); XmlNode rightIpAddress = doc.CreateElement("IPAddress"); rightIpAddress.InnerText = comboBoxRightIp.SelectedItem.ToString(); right.AppendChild(rightIpAddress); camera.AppendChild(right); doc.AppendChild(root); doc.Save(path); XmlNodeList nodes = doc.SelectNodes("//Camera/_"); for (int i = 0; i < nodes.Count; i++) { var selectSingleNode = nodes[i].SelectSingleNode("Name"); if (selectSingleNode != null && selectSingleNode.InnerText == "LeftCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxLeftIp.SelectedItem.ToString() + "\""; } if (selectSingleNode != null && selectSingleNode.InnerText == "RightCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxRightIp.SelectedItem.ToString() + "\""; } } } doc.Save(path); }