static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; XmlDocument queryDocument = new XmlDocument(); queryDocument.Load("../../reviews-queries.xml"); using (XmlTextWriter writer = new XmlTextWriter("../../reviews-search-results.xml", Encoding.UTF8)) { InitializeWriter(writer); writer.WriteStartDocument(); writer.WriteStartElement("search-results"); ReviewsDAO reviewsDao = new ReviewsDAO(); using (LogsContext logsContext = new LogsContext()) { XmlNodeList queryNodes = queryDocument.SelectNodes("/review-queries/query"); foreach (XmlNode queryNode in queryNodes) { LogQuery(logsContext, queryNode.OuterXml); WriteResultSet(writer, reviewsDao, queryNode); } writer.WriteEndDocument(); } } Console.WriteLine("Done! See the file in project's directory."); }
static void LogQuery(LogsContext context, string queryXml) { SearchLog newLog = new SearchLog(); newLog.Date = DateTime.Now; newLog.QueryXml = queryXml; context.SearchLogs.Add(newLog); context.SaveChanges(); }