コード例 #1
0
 private void AssertQueryReturnsTrue(string query)
 {
     using (var connection = new NpgsqlConnection(FacebookDatabaseManager.ConnectionString()))
         using (var cmd = connection.CreateCommand()) {
             connection.Open();
             cmd.CommandText = query;
             Assert.True((bool)cmd.ExecuteScalar(), cmd.CommandText);
         }
 }
コード例 #2
0
 private long CountRowsOnTable(string table)
 {
     using (var connection = new NpgsqlConnection(FacebookDatabaseManager.ConnectionString()))
         using (var cmd = connection.CreateCommand()) {
             connection.Open();
             cmd.CommandText = $@"
                 SELECT COUNT(*) from {table}
             ";
             return((long)cmd.ExecuteScalar());
         }
 }
コード例 #3
0
 public override void Run()
 {
     using (var context = new ApplicationDbContext())
     {
         using (var transaction = context.Database.BeginTransaction())
             using (var connection = new NpgsqlConnection(FacebookDatabaseManager.ConnectionString()))
             {
                 connection.Open();
                 var trace = Job(context, connection);
                 trace.EndTime = DateTime.UtcNow;
                 context.Add(trace);
                 context.SaveChanges();
                 transaction.Commit();
             }
     }
 }
コード例 #4
0
 public override void Run()
 {
     using (var apContext = new ApplicationDbContext())
     {
         using (var connection = new NpgsqlConnection(FacebookDatabaseManager.ConnectionString()))
         {
             connection.Open();
             var hasNext  = true;
             K   last     = null;
             var batchNum = 0;
             while (hasNext)
             {
                 batchNum++;
                 using (var transaction = apContext.Database.BeginTransaction())
                 {
                     Logger.Debug("Starting batch {BatchNum}", batchNum);
                     var trace = CreateTrace(TargetTable);
                     last = ExecuteJob(apContext, connection, trace, last);
                     if (last == null)
                     {
                         hasNext = false;
                     }
                     trace.EndTime = DateTime.UtcNow;
                     if (trace.Modifications.Count > 0)
                     {
                         apContext.Add(trace);
                         apContext.SaveChanges();
                         transaction.Commit();
                     }
                     else
                     {
                         transaction.Rollback();
                     }
                 }
             }
         }
     }
 }