Пример #1
0
        public override void CreateBulkInsertTask(string table, EnumerableDataReader reader, ImportTarget target)
        {
            BulkCopyTask task =
                new BulkCopyTask(new MySqlBulkInserter(Config.Provider.ConnectionString, table, target.Schema), table,
                                 reader, target.Name, Config.BatchSize, target.Schema);

            Jobs.Find(j => j.Tag == table).Tasks.Add(task);
        }
Пример #2
0
        public override void CreateBulkInsertTask(string table, EnumerableDataReader reader, ImportTarget target)
        {
            BulkCopyTask task =
                new BulkCopyTask(new MsSqlBulkCopy(Config.Provider.ConnectionString, SqlBulkCopyOptions.TableLock),
                                 table, reader, target.Name, Config.BatchSize, target.Schema);

            Jobs.Find(j => j.Tag == table).Tasks.Add(task);
        }
Пример #3
0
 public override void CreateBulkInsertTask(string table, EnumerableDataReader reader, ImportTarget target)
 {
     BulkCopyTask task = new BulkCopyTask(new SQLiteBulkInserter(_targetPath, target.Schema, table), table,
                                          reader, target.Name, Config.BatchSize, target.Schema);
     task.PostProcess += PostProcess; // when the task is complete, merge into main file
     _locks[task.Schema] = new object();
     Jobs.Find(j => j.Tag == target.Schema).Tasks.Add(task);
 }
Пример #4
0
        public override void CreateBulkInsertTask(string table, EnumerableDataReader reader, ImportTarget target)
        {
            BulkCopyTask task = new BulkCopyTask(new SQLiteBulkInserter(_targetPath, target.Schema, table), table,
                                                 reader, target.Name, Config.BatchSize, target.Schema);

            task.PostProcess   += PostProcess; // when the task is complete, merge into main file
            _locks[task.Schema] = new object();
            Jobs.Find(j => j.Tag == target.Schema).Tasks.Add(task);
        }
Пример #5
0
        private void PostProcess(object sender, EventArgs e)
        {
            const string transferFormat = "INSERT INTO main.{0} ({1} ) SELECT {1} from tmp{0}.{0}_tmp;";
            BulkCopyTask task           = (BulkCopyTask)sender;

            if (task.State != CopyEventType.Processing)
            {
                // dont want to merge suspect results
                return;
            }

            task.OnRowsInserted(CopyEventType.Processing, "Waiting to merge...");

            string table = task.Table;

            string sourcePath = Path.Combine(_targetPath, string.Format("{0}.{1}.db3", task.Schema, table));

            lock (_locks[task.Schema])
            {
                task.OnRowsInserted(CopyEventType.Processing, "Merging...");

                using (SQLiteConnection conn = new SQLiteConnection(GetConnectionString(_targetPath, task.Schema)))
                {
                    conn.Open();
                    SQLiteCommand cmd = conn.CreateCommand();
                    cmd.CommandText = Pragma;
                    cmd.ExecuteNonQuery();
                    try
                    {
                        cmd.CommandText = string.Format("ATTACH DATABASE \"{1}\" as [tmp{0}]", table, sourcePath);
                        cmd.ExecuteNonQuery();
                        using (SQLiteTransaction tx = conn.BeginTransaction())
                        {
                            DataTable tableInfo  = conn.GetSchema("Columns", new[] { "tmp" + table, null, table + "_tmp" });
                            string    columnList = string.Join(",",
                                                               tableInfo.Select().Select(r => r["COLUMN_NAME"]).Cast
                                                               <string>().
                                                               ToArray());
                            cmd.CommandText = string.Format(transferFormat, table, columnList);
                            cmd.ExecuteNonQuery();
                            tx.Commit();
                        }

                        cmd.CommandText = string.Format("DETACH DATABASE [tmp{0}]", table);
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        task.OnRowsInserted(CopyEventType.Error, ex.Message);
                        return;
                    }

                    Thread.Sleep(100);
                    File.Delete(sourcePath);
                }
            }
        }
Пример #6
0
        public BulkCopyTask FindTask(Guid id)
        {
            BulkCopyTask task = null;

            foreach (BulkLoadJob job in this)
            {
                task = job.Tasks.Find(t => t.Id == id);
                if (task != null)
                {
                    break;
                }
            }
            return(task);
        }
Пример #7
0
        private void UpdateTaskItem(BulkCopyTask task, ListViewItem listViewItem, BulkCopyEventArgs args)
        {
            args.Abort = _abort;

            listViewItem.SubItems[2].Text = task.Count.ToString();
            listViewItem.SubItems[3].Text = task.State.ToString();
            listViewItem.SubItems[4].Text = args.Message;

            switch (args.Type)
            {
            case CopyEventType.Active:
                listViewItem.BackColor = Color.GhostWhite;
                listViewItem.ForeColor = Color.DarkGreen;
                break;

            case CopyEventType.Processing:
                listViewItem.BackColor = Color.LightCyan;
                listViewItem.ForeColor = Color.DarkBlue;
                break;

            case CopyEventType.Complete:

                if (_abort)
                {
                    listViewItem.BackColor        = Color.Pink;
                    listViewItem.ForeColor        = Color.DarkRed;
                    listViewItem.SubItems[4].Text = "Aborted";
                }
                else
                {
                    listViewItem.BackColor = Color.LightGreen;
                    listViewItem.ForeColor = Color.DarkGreen;
                }
                break;

            case CopyEventType.Error:
                listViewItem.BackColor = Color.Pink;
                listViewItem.ForeColor = Color.DarkRed;
                break;

            default:
                listViewItem.BackColor = Color.Transparent;
                listViewItem.ForeColor = Color.Black;
                break;
            }
        }