private static void ParseSession(XmlReader r, List <CaptureHistoryEntry> entries) { r.MoveToContent(); if (!(r.Name == "KinoveaCaptureHistory")) { return; } r.ReadStartElement(); r.ReadElementContentAsString("FormatVersion", ""); while (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "Entry": CaptureHistoryEntry entry = ParseEntry(r); if (entry != null) { entries.Add(entry); } break; default: r.ReadOuterXml(); break; } } r.ReadEndElement(); }
public static void ImportDirectory(string dir) { // Import all files from the directory into corresponding entries. // Used for debugging and as a conveniency for first time use. List <CaptureHistoryEntry> entries = new List <CaptureHistoryEntry>(); foreach (string file in Directory.GetFiles(dir)) { string extension = Path.GetExtension(file); if (!VideoTypeManager.IsSupported(extension)) { continue; } CaptureHistoryEntry entry = CreateEntryFromFile(file); entries.Add(entry); } entries.Sort((e1, e2) => e1.Start.CompareTo(e2.Start)); foreach (CaptureHistoryEntry entry in entries) { AddEntry(entry); } }
public static void RemoveEntry(string session, CaptureHistoryEntry entry) { string sessionFile = Path.Combine(directory, session + ".xml"); if (!sessions.ContainsKey(sessionFile)) { return; } if (sessions[sessionFile].Contains(entry)) { sessions[sessionFile].Remove(entry); } }
private static CaptureHistoryEntry CreateEntryFromFile(string file) { FileInfo info = new FileInfo(file); string captureFile = file; DateTime start = info.CreationTime; DateTime end = info.LastWriteTime; string cameraAlias = ""; string cameraIdentifier = ""; double configuredFramerate = 0; double receivedFramerate = 0; int drops = 0; CaptureHistoryEntry entry = new CaptureHistoryEntry(captureFile, start, end, cameraAlias, cameraIdentifier, configuredFramerate, receivedFramerate, drops); return(entry); }
public static void AddEntry(CaptureHistoryEntry entry) { string session = string.Format("{0:yyyyMMdd}.xml", entry.Start); string sessionFile = Path.Combine(directory, session); if (!sessions.ContainsKey(sessionFile)) { List <CaptureHistoryEntry> entries = new List <CaptureHistoryEntry>(); if (!File.Exists(sessionFile)) { File.Create(sessionFile).Close(); } else { entries = ImportEntries(sessionFile); } sessions.Add(sessionFile, entries); } bool known = false; foreach (CaptureHistoryEntry existingEntry in sessions[sessionFile]) { if (entry.CaptureFile != existingEntry.CaptureFile) { continue; } known = true; break; } if (known) { return; } sessions[sessionFile].Add(entry); ExportEntries(sessionFile); }
private static CaptureHistoryEntry ParseEntry(XmlReader r) { string captureFile = ""; DateTime start = DateTime.MinValue; DateTime end = DateTime.MinValue; string cameraAlias = ""; string cameraIdentifier = ""; double configuredFramerate = 0; double receivedFramerate = 0; int drops = 0; r.ReadStartElement(); while (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "CaptureFile": captureFile = r.ReadElementContentAsString(); break; case "Start": string startDateTimeString = r.ReadElementContentAsString(); start = DateTime.ParseExact(startDateTimeString, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture); break; case "End": string endDateTimeString = r.ReadElementContentAsString(); end = DateTime.ParseExact(endDateTimeString, "yyyyMMddTHHmmss", CultureInfo.InvariantCulture); break; case "CameraAlias": cameraAlias = r.ReadElementContentAsString(); break; case "CameraIdentifier": cameraIdentifier = r.ReadElementContentAsString(); break; case "ConfiguredFramerate": configuredFramerate = double.Parse(r.ReadElementContentAsString(), CultureInfo.InvariantCulture); break; case "ReceivedFramerate": receivedFramerate = double.Parse(r.ReadElementContentAsString(), CultureInfo.InvariantCulture); break; case "Drops": drops = int.Parse(r.ReadElementContentAsString(), CultureInfo.InvariantCulture); break; default: string outerXml = r.ReadOuterXml(); log.DebugFormat("Unparsed content in capture history entry XML: {0}", outerXml); break; } } r.ReadEndElement(); CaptureHistoryEntry entry = new CaptureHistoryEntry(captureFile, start, end, cameraAlias, cameraIdentifier, configuredFramerate, receivedFramerate, drops); return(entry); }