using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FluentNHibernate.Cfg; using FluentNHibernate.Cfg.Db; using NHibernate; using NHibernate.Cfg; using Results; using Results.Entities; using System.IO; namespace ResultsParser { class Program { static ISessionFactory sessionFactory; static void Main(string[] args) { Console.WriteLine("Bench: [WR15]"); string bench = Console.ReadLine(); if (bench == string.Empty) bench = "WR15"; string connStr = GetConnectionString(bench); IList strangeWMs = new List(); try { var session = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(connStr)) .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) .ExposeConfiguration(BuildSchema) .BuildSessionFactory() .OpenSession(); var mtrs1 = session.QueryOver() .Where(mtr => mtr.Error < -2) .And(mtr => mtr.Passed == true) .List(); var mtrs2 = session.QueryOver() .Where(mtr => mtr.Error > 2) .And(mtr => mtr.Passed == true) .List(); foreach (var lst in new IList[] { mtrs1, mtrs2 }) { foreach (var mtr in lst) { if (mtr.TestRslt.Name() == "Q2" && mtr.WaterMeter.Passed && !string.IsNullOrEmpty(mtr.WaterMeter.SerialNr) && mtr.WaterMeter.WaterMeterData.MetrologicalClass == "R800") { strangeWMs.Add(mtr.WaterMeter); } } } using (TextWriter writer = new StreamWriter(string.Format("strangeWMs-{0}.csv", bench))) { foreach (var wm in strangeWMs) { writer.WriteLine(string.Format("'{0};{1};{2};{3};{4:dd.MM.yyyy HH:mm};{5:dd.MM.yyyy HH:mm};v.{6};{7}", wm.SerialNr, bench, wm.WMPosition, wm.Batch.BatchNr, wm.Batch.StartTime, wm.Batch.EndTime, wm.Batch.ProgramVersion, wm.Batch.ProcedureName)); } } session.Close(); } catch (Exception exc) { Console.WriteLine("Exception occured:"); Console.WriteLine(exc.Message); if (exc.InnerException != null) { Console.WriteLine("Inner exception:"); Console.WriteLine(exc.InnerException.Message); } Console.ReadLine(); Console.WriteLine(exc.StackTrace); } Console.WriteLine(string.Format("{0} strange water meters found", strangeWMs.Count)); Console.WriteLine("Press ENTER to close"); Console.ReadLine(); } static string GetConnectionString(string bench = "WR15") { Console.WriteLine("Server: [localhost]"); var server = Console.ReadLine(); if (server == string.Empty) server = "localhost"; Console.WriteLine(string.Format("Database: [st-{0}-r]", bench.ToLower())); var db = Console.ReadLine(); if (db == string.Empty) db = string.Format("st-{0}-r", bench.ToLower()); Console.WriteLine("User: [root]"); var uid = Console.ReadLine(); if (uid == string.Empty) uid = "root"; Console.WriteLine("Password:"); var pw = Console.ReadLine(); var connStr = string.Format("SERVER={0}; DATABASE={1}; UID={2}; PASSWORD={3}; CHARSET=utf8;", server, db, uid, pw); Console.WriteLine("Connection string is\r\n {0}", connStr); Console.WriteLine(); return connStr; } static void BuildSchema(Configuration config) { /// This NHibernate tool takes a configuration with mapping info and exports a database schema new NHibernate.Tool.hbm2ddl.SchemaExport(config).SetOutputFile("db_schema"); } } }