public static void SaveRunHistory(DateTime beforeDate, string filename) { XmlDocument doc = new XmlDocument(); XmlElement parent = doc.CreateElement("execution-histories"); int count = 0; foreach (RunSummary item in SyncServer.GetRunSummary()) { if (!item.StartTime.HasValue || !item.EndTime.HasValue) { continue; } if (item.EndTime < beforeDate) { count++; RunDetails d = SyncServer.GetRunDetail(item); parent.AppendChild(doc.ImportNode(d.XmlNode, true)); } } doc.AppendChild(parent); if (count == 0) { return; } using (XmlWriter w = XmlWriter.Create(filename, new XmlWriterSettings() { Indent = true })) { doc.WriteTo(w); w.Close(); } }