Beispiel #1
0
        public void InsertFileFieldValues(SqlConnection sqlConnection, IEnumerable <FileFieldValue> values)
        {
            var tableName  = "FileFieldValues";
            var bufferSize = 5000;
            var inserter   = new BulkInserter <FileFieldValue>(sqlConnection, tableName, bufferSize);

            inserter.Insert(values);
        }
Beispiel #2
0
 private static void BulkInsert(IEnumerable<Stat> stats)
 {
     using (var ctx = new Context())
     {
         using (var conn = new SqlConnection(ctx.Database.Connection.ConnectionString))
         {
             conn.Open();
             var inserter = new BulkInserter<Stat>(conn, "Stats");
             inserter.Insert(stats);
         }
     }
 }
Beispiel #3
0
 public static void Write(List<LogEntry> logs)
 {
     using (var ctx = new Context())
     {
         Output.BlankLine();
         Output.Write("Escrevendo registros no banco... ");
         var tableName = "LogEntries";
         var bufferSize = 5000;
         using (var conn = new SqlConnection(ctx.Database.Connection.ConnectionString))
         {
             conn.Open();
             var inserter = new BulkInserter<LogEntry>(conn, tableName, bufferSize);
             inserter.PostBulkInsert += (sender, args) => Output.Write((logs.Count - args.Items.Count()) + " itens restantes... ");
             inserter.Insert(logs);
         }
         Output.WriteLine(" concluído.");
     }
 }
Beispiel #4
0
        public void Test1()
        {
            const string table = "IP2.Location";

            using (var conn = new SqlConnection("server=.;database=afsx;integrated security=true"))
                using (conn.Connect())
                {
                    const SqlBulkCopyOptions opts = SqlBulkCopyOptions.KeepNulls;
                    using (var bi = new BulkInserter <Record>(conn, table, copyOptions: opts, bufferSize: 20000))
                    {
                        conn.ExecuteSql($"TRUNCATE TABLE {table}");

                        using (
                            var reader =
                                new StreamReader(
                                    @"C:\dev\webbanking\download\IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE.CSV"))
                        {
                            var records = from rec in reader.ReadCsv()
                                          select new Record
                            {
                                IpFrom      = Convert.ToInt64(rec[0]),
                                IpTo        = Convert.ToInt64(rec[1]),
                                CountryCode = rec[2],
                                CountryName = rec[3],
                                Region      = rec[4],
                                City        = rec[5],
                                Latitude    = rec[6].ConvertTo <decimal?>(),
                                Longitude   = rec[7].ConvertTo <decimal?>(),
                                ZipCode     = rec[8]
                            };


                            bi.PostBulkInsert += (sender, args) => Console.WriteLine(args.Items.Length);

                            bi.Insert(records);
                        }
                    }
                }
        }
Beispiel #5
0
        public void Test1()
        {
            const string table = "IP2.Location";
            using (var conn = new SqlConnection("server=.;database=afsx;integrated security=true"))
            using(conn.Connect())
            {
                const SqlBulkCopyOptions opts = SqlBulkCopyOptions.KeepNulls;
                using (var bi = new BulkInserter<Record>(conn, table, copyOptions: opts, bufferSize:20000))
                {
                    conn.ExecuteSql($"TRUNCATE TABLE {table}");

                    using (
                        var reader =
                            new StreamReader(
                                @"C:\dev\webbanking\download\IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE.CSV"))
                    {
                        var records = from rec in reader.ReadCsv()
                            select new Record
                            {
                                IpFrom = Convert.ToInt64(rec[0]),
                                IpTo = Convert.ToInt64(rec[1]),
                                CountryCode = rec[2],
                                CountryName = rec[3],
                                Region = rec[4],
                                City = rec[5],
                                Latitude = rec[6].ConvertTo<decimal?>(),
                                Longitude = rec[7].ConvertTo<decimal?>(),
                                ZipCode = rec[8]
                            };

                        bi.PostBulkInsert += (sender, args) => Console.WriteLine(args.Items.Length);

                        bi.Insert(records);

                    }
                }
            }
        }