Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("*************************************************");
            Console.WriteLine("**             Golf Score Tracker              **");
            Console.WriteLine("*************************************************");
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            using (var db = new GolfScoreContext())
            {
                logger.Debug("Ensuring database is created");
                db.Database.EnsureCreated();

                TextCSVImporter importer = new TextCSVImporter(@"Data\MyGolfNuts.csv", (ILogger)logger);
                importer.ImportRound(db, "MyGolfNuts");
            }
            Console.ReadLine();
        }
        public void ImportRound(GolfScoreContext db, string sourcename)
        {
            var sourceAlreadyExists = db.RoundSources.Find(sourcename) != null;

            if (sourceAlreadyExists)
            {
                Log.LogInformation("Source with name {0} already exists", sourcename);
                return;
            }

            RoundSource roundSource = new RoundSource
            {
                SourceName  = sourcename,
                ContentType = "text/CSV",
                Content     = File.ReadAllBytes(FileName)
            };

            db.RoundSources.Add(roundSource);
            db.SaveChanges();
        }