public static void Main()
 {
     var exporter = new MongoDbExporter();
     int recordsAffected = exporter.ExportProductSalesBefore(DateTime.Now, "");
     Console.WriteLine("Exported {0} documents...", recordsAffected);
     //var task = exporter.GetSales();
     //System.Threading.Tasks.Task.WaitAll(task);
     //foreach (var item in task.Result)
     //{
     //    Console.WriteLine(item);
     //}
 }
        private void ExportJson(object sender, EventArgs e)
        {
            string path = string.Empty;

            try
            {
                using (FolderBrowserDialog folderDialog = new FolderBrowserDialog())
                {
                    if (folderDialog.ShowDialog() == DialogResult.OK)
                    {
                        path = folderDialog.SelectedPath;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (path != string.Empty)
            {
                this.ClearInfo(null, null);

                switch ((SearchOption)comboExportOptions.SelectedItem)
                {
                    case SearchOption.ExactDate:
                        Task.Run(() =>
                        {
                            try
                            {
                                MongoDbExporter mongoExporter = new MongoDbExporter();
                                int recordsAffected = mongoExporter.ExportProductSalesOn(dateSearch.Value, path);

                                this.listInfo.Invoke(new Action(() => { ResultInformation(recordsAffected); }));
                            }
                            catch (Exception ex)
                            {
                                this.Invoke(new Action(() => { MessageBox.Show(ex.Message); }));
                            }
                        });
                        break;
                    case SearchOption.BeforeDate:
                        Task.Run(() =>
                        {
                            try
                            {
                                MongoDbExporter exportToDb = new MongoDbExporter();
                                int recordsAffected = exportToDb.ExportProductSalesBefore(dateSearch.Value, path);

                                this.listInfo.Invoke(new Action(() => { ResultInformation(recordsAffected); }));
                            }
                            catch (Exception ex)
                            {
                                this.Invoke(new Action(() => { MessageBox.Show(ex.Message); }));
                            }
                        });
                        break;
                    case SearchOption.AfterDate:
                        Task.Run(() =>
                        {
                            try
                            {
                                MongoDbExporter exportToDb = new MongoDbExporter();
                                int recordsAffected = exportToDb.ExportProductSalesAfter(dateSearch.Value, path);

                                this.listInfo.Invoke(new Action(() => { ResultInformation(recordsAffected); }));
                            }
                            catch (Exception ex)
                            {
                                this.Invoke(new Action(() => { MessageBox.Show(ex.Message); }));
                            }
                        });
                        break;
                    case SearchOption.BetweenDates:
                        Task.Run(() =>
                        {
                            try
                            {
                                MongoDbExporter exportToDb = new MongoDbExporter();
                                int recordsAffected = exportToDb.ExportProductSalesBetween(dateSearch.Value, dateHelper.Value, path);

                                this.listInfo.Invoke(new Action(() => { ResultInformation(recordsAffected); }));
                            }
                            catch (Exception ex)
                            {
                                this.Invoke(new Action(() => { MessageBox.Show(ex.Message); }));
                            }
                        });
                        break;
                    default:
                        MessageBox.Show("No such option.");
                        break;
                }
            }
        }