public static void Main(string[] args) { try { BulkLoader inserter; Console.WriteLine(); Console.Title = "StackOverflow Data Dump Import v1.5"; Console.WriteLine(Console.Title); Console.WriteLine(); if (args.ToList().Find(a => a.ToLowerInvariant() == "help" || a.ToLowerInvariant() == "?") != null) { RenderUsage(); return; } Configuration.Configuration config = new Configuration.Configuration(args); Console.WriteLine(config.ToString(false)); if (config.GUI || args.Length == 0) { Application.EnableVisualStyles(); Application.Run(new FrmUI(config)); // or whatever } else { inserter = BulkLoader.Create(config); inserter.RowsInserted += (s, e) => { if (e.Type == CopyEventType.Error) { Console.WriteLine(e.Message); } }; Stopwatch sw = new Stopwatch(); sw.Start(); inserter.ProcessJobs(config); sw.Stop(); long count = inserter.Jobs.Select(j => j.Tasks.Sum(t => t.Count)).Sum(); Console.WriteLine(Resources.Rs_ImpComplete + "\r\n", count.ToString("#,##0"), sw.ElapsedMilliseconds / 1000f / 60f); } } catch (Exception ex) { Console.WriteLine("\r\n{0}\r\n", ex.Message); Console.WriteLine(ex.StackTrace); var inner = ex.InnerException; while (inner != null) { Console.WriteLine(); Console.WriteLine(inner.Message); Console.WriteLine(inner.StackTrace); inner = inner.InnerException; } RenderUsage(); } }
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(); }