public void OnProgressChanged(object sender, ProgressReport report)
 {
     if (report.PercentComplete == 0)
     {
         _hubContext.Clients.All.taskRunning(report.Message, report.PercentComplete);
     }
     else if (report.PercentComplete == 100)
     {
         _hubContext.Clients.All.TaskCompleted(report.Message);
     }
     else
     {
         _hubContext.Clients.All.ProgressChanged(report.Message, report.PercentComplete);
     }
 }
        public async Task<List<Report>> GenerateReports(IProgress<ProgressReport> progress, Action<List<ReportError>> errorWriter)
        {
            var result = new List<Report>();

            var progressReport = new ProgressReport { PercentComplete = 0, Message = "Loading projects..." };
            progress.Report(progressReport);

            var porjects = await Task.Run(() => _uow.ProjectRepository.GetAll().ToList());
            Report(progress, progressReport, 25, "Loading persons...");

            var allPersons = await Task.Run(() => _uow.PersonRepository.GetAll().ToList());
            Report(progress, progressReport, 50, "Generating reports...");

            var projectCount = porjects.Count;
            var projectNumber = 0;
            foreach (var project in porjects)
            {
                projectNumber++;
                var cuurentProject = project;

                var percentComplete = projectNumber * 50 / projectCount + 50 - 1;
                var message = "Generating report for " + cuurentProject.Name;
                Report(progress, progressReport, percentComplete, message);

                var persons = allPersons.Where(s => s.Project.Id == cuurentProject.Id).ToList();
                List<PersonWorkMonth> personWorkMonths = await Task.Run(() => persons.Select(person => _uow.PersonWorkMonthRepository.GetPersonWorkMonth(person, DateTime.Today.Year, DateTime.Today.Month)).ToList());

                var report = await Task.Run(() => _reportGenerator.GenerateReport(personWorkMonths, _personTimeManager));
                report.Project = cuurentProject;

                result.Add(report);
                SaveErrors(report, errorWriter);
            }

            Report(progress, progressReport, 100, "Finishing...");

            return result;
        }
 private static void Report(IProgress<ProgressReport> progress, ProgressReport progressReport, int percentComplete, string message)
 {
     progressReport.PercentComplete = percentComplete;
     progressReport.Message = message;
     progress.Report(progressReport);
 }