public bool Write(SetupProfile profile, XmlNode root, XmlDocument target) { if (profile == null) { throw new ArgumentNullException("profile"); } if (target == null) { throw new ArgumentNullException("target"); } if (root == null) { throw new ArgumentNullException("root"); } foreach (int i in profile.TrackerIndexes) { EquipmentSettings settings = profile.GetTracker(i); XmlNode node = WriteCap3Point(i, settings, target); if (node != null) { root.AppendChild(node); } } return(true); }
public bool Read(SetupProfile result, XmlNode root) { foreach (XmlNode node in root.ChildNodes) { VirtualDeviceType deviceType; if (!Enum.TryParse(node.Name, out deviceType)) { continue; } if (node.Attributes["CommonIndex"] == null || node.Attributes["ClassifiedIndex"] == null) { return(false); } int commonIndex = JsonString.ParseInt(node.Attributes["CommonIndex"].InnerText, -1); int classifiedIndex = JsonString.ParseInt(node.Attributes["ClassifiedIndex"].InnerText, -1); if (commonIndex < 0 || classifiedIndex < 0) { return(false); } var settings = new VirtualDeviceSettings() { DeviceType = deviceType, ClassifiedDeviceIndex = classifiedIndex }; settings = ReadDevice(settings, node); if (settings == null) { return(false); } result.AddDevice(commonIndex, settings); } return(true); }
public XmlNode Write(SetupProfile profile, XmlNode root, XmlDocument target) { if (profile == null) { throw new ArgumentNullException("profile"); } if (target == null) { throw new ArgumentNullException("target"); } if (root == null) { throw new ArgumentNullException("root"); } foreach (int i in profile.VideoCaptureIndexes) { EquipmentSettings settings = profile.GetVideoCapture(i); XmlNode node = WriteStream(i, settings, target); if (node != null) { root.AppendChild(node); } } return(root); }
public bool Write(SetupProfile profile, XmlNode root, XmlDocument target) { if (profile == null) { throw new ArgumentNullException("profile"); } if (target == null) { throw new ArgumentNullException("target"); } if (root == null) { throw new ArgumentNullException("root"); } var indexes = new List <int>(profile.VideoCaptureIndexes); foreach (int i in profile.DeviceIndexes) { VirtualDeviceSettings settings = profile.GetDevice(i); XmlNode node = WriteDevice(i, settings, target); if (node != null) { root.AppendChild(node); } } return(true); }
public bool Write(SetupProfile profile, XmlNode root, XmlDocument document) { if (profile == null) { throw new ArgumentNullException("profile"); } if (root == null) { throw new ArgumentNullException("root"); } if (document == null) { throw new ArgumentNullException("document"); } foreach (int index in profile.BindingIndexes) { CapInputRelay settings = profile.GetBindings(index); XmlNode node = WriteRelay(index, settings, document); if (node != null) { root.AppendChild(node); } } return(true); }
public bool Read(SetupProfile profile, XmlNode root) { foreach (XmlNode node in root) { if (node.Name.Equals("Cap3Point")) { if (node.Attributes["Index"] == null) { return(false); } int index = JsonString.ParseInt(node.Attributes["Index"].InnerText, -1); if (index < 0) { return(false); } EquipmentSettings settings = ReadCap3Point(node); if (settings == null) { return(false); } profile.AddTracker(index, settings); } } return(true); }
public bool Read(SetupProfile profile, XmlNode root) { if (profile == null) { throw new ArgumentNullException("profile"); } if (root == null) { throw new ArgumentNullException("root"); } foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("Bindings")) { if (node.Attributes["Index"] == null) { return(false); } int index = JsonString.ParseInt(node.Attributes["Index"].InnerText, -1); if (index < 0) { return(false); } CapInputRelay settings = ReadRelay(node); if (settings == null) { return(false); } profile.AddBindings(index, settings); } } return(true); }
public SetupProfile LoadDefaultProfile() { if (!Loaded) { throw new InvalidOperationException("not loaded"); } string filePath = Path.Combine(settings.ResourceDirectory, "profiles", "Default.xml"); var document = new XmlDocument(); try { using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) { document.Load(stream); } } catch (FileNotFoundException) { return(null); } catch (System.Reflection.TargetInvocationException) { return(null); } var result = new SetupProfile("Default"); foreach (XmlNode root in document.DocumentElement.ChildNodes) { if (root.Name.Equals("VideoCapture")) { if (!new CaptureProfileReader().Read(result, root)) { return(null); } } else if (root.Name.Equals("VirtualDevices")) { if (!new DeviceProfileReader().Read(result, root)) { return(null); } } else if (root.Name.Equals("Tracking")) { if (!new TrackingProfileReader().Read(result, root)) { return(null); } } else if (root.Name.Equals("TrackerBindings")) { if (!new BindingsProfileReader().Read(result, root)) { return(null); } } } return(result); }
public void SafeActiveProfile(SetupProfile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } if (!Loaded) { throw new InvalidOperationException("not loaded"); } string filePath = Path.Combine(settings.ResourceDirectory, "profiles", profile.Name + ".xml"); XmlDocument document = new XmlDocument(); XmlDeclaration decl = document.CreateXmlDeclaration("1.0", "UTF-8", null); document.InsertBefore(decl, document.DocumentElement); XmlElement root = document.CreateElement("Profile"); document.AppendChild(root); XmlElement capture = document.CreateElement("VideoCapture"); root.AppendChild(capture); new CaptureProfileWriter().Write(profile, capture, document); XmlElement tracking = document.CreateElement("Tracking"); root.AppendChild(tracking); new TrackingProfileWriter().Write(profile, tracking, document); XmlElement devices = document.CreateElement("VirtualDevices"); root.AppendChild(devices); new DeviceProfileWriter().Write(profile, devices, document); XmlElement bindings = document.CreateElement("TrackerBindings"); root.AppendChild(bindings); new BindingsProfileWriter().Write(profile, bindings, document); using (FileStream stream = File.Open(filePath, FileMode.Create, FileAccess.Write)) { document.Save(stream); } }
/// <summary> /// Reads all stream settings from the given node. /// </summary> /// <returns><c>true</c>, if operation was successful, <c>false</c> otherwise.</returns> /// <param name="profile">Target profile.</param> /// <param name="root">Root node.</param> public bool Read(SetupProfile profile, XmlNode root) { foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("Webcam")) { string sIndex; if (node.Attributes["Index"] != null) { sIndex = node.Attributes["Index"].InnerText; } else { sIndex = "-1"; } int index = -1; if (sIndex != null) { index = JsonString.ParseInt(node.Attributes["Index"].InnerText, -1); } string name; if (node.Attributes["Name"] != null) { name = node.Attributes["Name"].InnerText; } else { name = "Webcam"; } if (!ReadWebcam(name, index, profile, node)) { return(false); } } } return(true); }
/// <summary> /// Reads stream settings from the given node. /// </summary> /// <returns><c>true</c>, if operation was successful, <c>false</c> otherwise.</returns> /// <param name="index">Capture index.</param> /// <param name="profile">Target profile.</param> /// <param name="root">Root node.</param> public bool ReadWebcam(string name, int index, SetupProfile profile, XmlNode root) { var settings = new EquipmentSettings(typeof(SensorProperty)); // TODO read name from data settings.SetText(SensorProperty.Name, name); settings.SetText(SensorProperty.Type, "Webcam"); // first parse the node foreach (XmlNode node in root.ChildNodes) { if (node.Name.Equals("Camera")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } if (!auto) { int camera = JsonString.ParseInt(node.InnerText, -1); if (camera < 0) { return(false); } settings.SetInteger(SensorProperty.CameraId, camera); } } else if (node.Name.Equals("Width")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } if (!auto) { int width = JsonString.ParseInt(node.InnerText, 640); if (width < 1) { return(false); } settings.SetInteger(SensorProperty.FrameWidth, width); } } else if (node.Name.Equals("Height")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } if (!auto) { int height = JsonString.ParseInt(node.InnerText, 480); if (height < 1) { return(false); } settings.SetInteger(SensorProperty.FrameHeight, height); } } else if (node.Name.Equals("FPS")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } if (!auto) { int fps = JsonString.ParseInt(node.InnerText, 30); if (fps < 0) { return(false); } settings.SetInteger(SensorProperty.FrameRate, fps); } } else if (node.Name.Equals("Exposure")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } decimal exposure = JsonString.ParseDecimal(node.InnerText, 0.0m); if (!auto) { settings.SetDecimal(SensorProperty.Exposure, exposure); } } else if (node.Name.Equals("Brightness")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } decimal bright = JsonString.ParseDecimal(node.InnerText, 0.0m); if (!auto) { settings.SetDecimal(SensorProperty.Brightness, bright); } } else if (node.Name.Equals("Contrast")) { bool auto = true; if (node.Attributes["Auto"] != null) { auto = JsonString.ParseBool(node.Attributes["Auto"].InnerText, true); } decimal contrast = JsonString.ParseDecimal(node.InnerText, 0.0m); if (!auto) { settings.SetDecimal(SensorProperty.Contrast, contrast); } } } // add the settings if successful profile.AddVideoCapture(index, settings); return(true); }