Ejemplo n.º 1
0
        private void StartImport(Configuration.Configuration config)
        {
            // clean the plate
            TasksListView.Items.Clear();
            TasksListView.Groups.Clear();

            // build the configuration object and then the loader

            BulkLoader loader = BulkLoader.Create(config);


            // since we want to track progress of tasks, lets
            // get an aggregated list of tasks from the loader's jobs
            List <BulkCopyTask> tasks = new List <BulkCopyTask>();

            loader.Jobs.ForEach(j => j.Tasks.ForEach(tasks.Add));

            // add a list group for each site being loaded.
            // TODO: relocate targets to the loader
            config.Targets.ForEach(t => TasksListView.Groups.Add(new ListViewGroup(t.Name, t.Name)));

            // create the list items and event handler
            tasks.ForEach(t =>
            {
                ListViewItem item = new ListViewItem();

                item.SubItems.Add(t.Table);
                item.SubItems.Add("");
                item.SubItems.Add("");
                item.SubItems.Add("");

                TasksListView.Items.Add(item);
                item.Group = TasksListView.Groups[t.Site];

                t.RowsInserted += (ss, eee) => TasksListView.Invoke(() => UpdateTaskItem(t, item, eee));
            });


            // set up the import completion handler
            loader.Jobs.Complete += (ss, ee) => ImportButton.Invoke(() =>
            {
                ImportButton.Text    = "Import";
                ImportButton.Enabled = true;
                panel1.Enabled       = true;
                _timer.Stop();
                long count = loader.Jobs.Select(j => j.Tasks.Sum(t => t.Count)).Sum();


                StatusLabel.Text =
                    string.Format((_abort ? Resources.Rs_ImpAbort : Resources.Rs_ImpComplete) + "\r\n",
                                  count.ToString("#,##0"),
                                  _timer.ElapsedMilliseconds / 1000f / 60f);
            });


            // start the job

            _timer.Reset();
            _timer.Start();
            ImportButton.Text = "Abort";
            new Thread(() => loader.ProcessJobs(config)).Start();
        }