static public IEnumerable GetMetadata (string metafile, DateTime newer_than) { string dir_name = GetDirectory (metafile); if (dir_name == null) yield break; XmlDocument doc = new XmlDocument (); StreamReader reader = null; try { reader = new StreamReader (metafile); doc.Load (reader); } catch (Exception e) { Log.Error (e, "Error while trying to parse nautilus metadata file {0}", metafile); if (reader != null) reader.Close (); reader = null; } if (reader == null) yield break; foreach (XmlNode node in doc.SelectNodes ("/directory/file[@name]")) { XmlNode timestamp_node = node.Attributes.GetNamedItem ("timestamp"); long time_t; DateTime timestamp; // Intentionally give non-timestamped entries a // timestamp of the Unix epoch rather than // DateTime.MinValue, so that they are // processed when newer_than is. if (timestamp_node == null) time_t = 0; else time_t = Int64.Parse ((string) timestamp_node.Value); timestamp = DateTimeUtil.UnixToDateTimeUtc (time_t); if (timestamp <= newer_than) continue; NautilusMetadata nm = new NautilusMetadata (); string filename = Path.Combine (dir_name, (string) node.Attributes.GetNamedItem ("name").Value); // The filename is already escaped for us. nm.Uri = new Uri (filename, true); XmlNode notes_node = node.Attributes.GetNamedItem ("annotation"); if (notes_node != null) nm.Notes = (string) notes_node.Value; nm.Emblems = new ArrayList (); foreach (XmlNode emblem_node in node.SelectNodes ("keyword")) nm.Emblems.Add (emblem_node.Attributes.GetNamedItem ("name").Value); // If we don't have a timestamp, and have // neither notes nor an emblem, this isn't an // interesting node. if (time_t == 0 && String.IsNullOrEmpty (nm.Notes) && nm.Emblems.Count == 0) continue; yield return nm; } reader.Close (); yield break; }
static public IEnumerable GetMetadata(string metafile, DateTime newer_than) { string dir_name = GetDirectory(metafile); if (dir_name == null) { yield break; } XmlDocument doc = new XmlDocument(); StreamReader reader = null; try { reader = new StreamReader(metafile); doc.Load(reader); } catch (Exception e) { Log.Error(e, "Error while trying to parse nautilus metadata file {0}", metafile); if (reader != null) { reader.Close(); } reader = null; } if (reader == null) { yield break; } foreach (XmlNode node in doc.SelectNodes("/directory/file[@name]")) { XmlNode timestamp_node = node.Attributes.GetNamedItem("timestamp"); long time_t; DateTime timestamp; // Intentionally give non-timestamped entries a // timestamp of the Unix epoch rather than // DateTime.MinValue, so that they are // processed when newer_than is. if (timestamp_node == null) { time_t = 0; } else { time_t = Int64.Parse((string)timestamp_node.Value); } timestamp = DateTimeUtil.UnixToDateTimeUtc(time_t); if (timestamp <= newer_than) { continue; } NautilusMetadata nm = new NautilusMetadata(); string filename = Path.Combine(dir_name, (string)node.Attributes.GetNamedItem("name").Value); // The filename is already escaped for us. nm.Uri = new Uri(filename, true); XmlNode notes_node = node.Attributes.GetNamedItem("annotation"); if (notes_node != null) { nm.Notes = (string)notes_node.Value; } nm.Emblems = new ArrayList(); foreach (XmlNode emblem_node in node.SelectNodes("keyword")) { nm.Emblems.Add(emblem_node.Attributes.GetNamedItem("name").Value); } // If we don't have a timestamp, and have // neither notes nor an emblem, this isn't an // interesting node. if (time_t == 0 && String.IsNullOrEmpty(nm.Notes) && nm.Emblems.Count == 0) { continue; } yield return(nm); } reader.Close(); yield break; }