コード例 #1
0
ファイル: Program.cs プロジェクト: HannaHarr/WorkWithDatabase
        static void Main(string[] args)
        {
            var recordsPath      = @$ "{Environment.CurrentDirectory}/text.csv";
            var dataSource       = @"(LocalDB)\MSSQLLocalDB";
            var databaseFilename = @$ "{Directory.GetCurrentDirectory()}\WorkDatabase.mdf";
            var connString       = $@"Data Source={dataSource};AttachDbFilename={databaseFilename};Integrated Security=True;MultipleActiveResultSets=True";

            CreateRecords(recordsPath);

            using (var csvRecords = new CsvEnumerable <Record>(recordsPath))
            {
                var consoleLogger = new Logger();

                using (IRepository <Record> repository = LoggingProxy <IRepository <Record> > .CreateInstance(new MSSQLLocalDBRepository(connString), consoleLogger))
                {
                    var tasks = new List <Task <int> >();

                    foreach (var record in csvRecords)
                    {
                        Console.WriteLine($"Name = {record.Name}, Number = {record.Number}");
                        tasks.Add(repository.CreateAsync(record));
                    }

                    Task.WaitAll(tasks.ToArray());
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            IRepository <Person> repository = LoggingProxy <IRepository <Person> > .CreateInstance(new Repository <Person>());

            CsvEnumerable <Person> csvList
                = new CsvEnumerable <Person>(AppSettingsProvider.GetInstance().Settings.CsvFileName);

            try
            {
                foreach (Person p in csvList)
                {
                    repository.Add(p);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }