public void StartGeneration(ReportGenerationContext context)
        {
            if (reportWorker.IsBusy)
            {
                return;
            }

            var fileName = OpenFileSelection();
            if (!string.IsNullOrEmpty(fileName))
            {
                context.ReportFileName = fileName;
                generationForm.Show();
                currentGenerationContext = context;
                reportWorker.RunWorkerAsync();
            }
            else
            {
                if (context.EndGeneration != null)
                {
                    context.EndGeneration();
                }
            }
        }
        private void bGenerate_Click(object sender, EventArgs e)
        {
            //var chatgs = chatRepository.GetCalls(DateTime.Now.AddMonths(-2), DateTime.Now);

            //if (this.cblReports.CheckedItems.Count == 0)
            //{
            //    MessageBox.Show("You should at least one report", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    return;
            //}
            this.bGenerate.Enabled = false;

            IReportGenerator[] selectedReports = timerangeReports;

            this.reportManager.Setup(selectedReports.Length - 1);

            var context = new ReportGenerationContext
            {
                StartGeneration = (c) => this.GenerateReport(c.ReportFileName, selectedReports),
                EndGeneration = () => { this.bGenerate.Enabled = true; }
            };

            this.reportManager.StartGeneration(context);
        }
        private void bGenerate_Click(object sender, EventArgs e)
        {
            if (this.cblReports.CheckedItems.Count == 0)
            {
                MessageBox.Show("You should at least one report", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            this.bGenerate.Enabled = false;

            IReportGenerator[] selectedReports =
                this.reports.Where(rep => this.cblReports.CheckedItems.OfType<string>().Any(n => rep.Name == n)).ToArray();

            this.reportManager.Setup(selectedReports.Length - 1);

            var context = new ReportGenerationContext
                {
                    StartGeneration = (c) => this.GenerateReport(c.ReportFileName, selectedReports),
                    EndGeneration = () => { this.bGenerate.Enabled = true; }
                };

            this.reportManager.StartGeneration(context);
        }
        private void ReportWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (currentGenerationContext != null && currentGenerationContext.EndGeneration != null)
            {
                currentGenerationContext.EndGeneration();
            }

            var fileName = currentGenerationContext.ReportFileName;
            currentGenerationContext = null;
            generationForm.Hide();
            Process.Start(fileName);
        }