Ejemplo n.º 1
0
        public static void AddLog(string xml)
        {
            LogsContext context = new LogsContext();

            SearchLog myLog = new SearchLog();
            myLog.Date = DateTime.Now;
            myLog.QueryXml = xml.ToString();

            context.SearchLogs.Add(myLog);
            context.SaveChanges();
        }
Ejemplo n.º 2
0
 public DB(bool resetBookstore, bool resetLog, LogsContext log)
 {
     if (resetBookstore)
     {
         ResetDbData();                       
     }
     if (resetLog)
     {
         log.Database.ExecuteSqlCommand("DELETE Logs");
         log.SaveChanges();
     }
     this.log = log;
 }
Ejemplo n.º 3
0
    public static void AddLog(DateTime date, string query)
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion
            <LogsContext, Logs.Data.Migrations.Configuration>());

        LogsContext context = new LogsContext();
        using (context)
        {
            SearchLog log = new SearchLog();
            log.Date = date;
            log.QueryXml = query;
            context.SearchLogs.Add(log);
            context.SaveChanges();
        }
    }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
            bool resetBookstore = true;
            bool resetLog = true;
            ShowLog destination = ShowLog.InTextFile;
            LogsContext log = new LogsContext();                
            DB dbManager = new DB(resetBookstore, resetLog,log);

            //Problem 3.	Simple Books Import from XML File
            String inputPath = "../../XML/simple-books.xml";
            dbManager.ProcessBooks(inputPath, false);

            //Problem 4.	Complex Books Import from XML File
            inputPath = "../../XML/complex-books.xml";
            dbManager.ProcessBooks(inputPath, true);

            //Problem 5.	Simple Search for Books
            inputPath = "../../XML/simple-query1.xml";
            string output = dbManager.ExecuteSimpleQuery(inputPath);
            Console.WriteLine(output);

            //Problem 6.	Search for Reviews
            inputPath = "../../XML/reviews-queries.xml";
            String outputPath = "../../XML/reviews-search-results.xml";
        dbManager.ExecuteReviewsQueries(inputPath, outputPath);

            //Problem 7.	Search Logs (Code First)
            switch (destination)
            {
                case ShowLog.InConsole:
                    foreach (Log item in log.Logs)
                        Console.WriteLine("{0} - {1}", item.LogDate, item.QueryXml);
                    break;
                case ShowLog.InTextFile:
                    using (StreamWriter writer = new StreamWriter(
                        "../../LogOutput.txt", false, Encoding.UTF8))
                    {
                        foreach (Log item in log.Logs)
                            writer.Write("{0}\n{1}\n{2}\n{3}\n",
                                item.Id, item.LogDate, item.QueryXml, new String('-', 20));
                    }
                    break;
            }
        }