public static void AnalyzeErrors(IBackgroundContext context, LpuExecParams executorParams)
 {
     if (context.CancellationPending) return;
     context.ProgressSeparator();
     context.ReportProgress(@"АНАЛИЗ ОШИБОК");
     context.ReportProgress("");
     using (var dataContext = new ErrorsAnalyzerDataContext())
     {
         var dir = Settings.Default.DataDir;
         dataContext.Load(context, dir, dir, dir);
         if (context.CancellationPending) return;
         foreach (var errorDataSet in dataContext.Errors.TakeWhile(x => !context.CancellationPending))
         {
             analyzeErrorsDataSet(context, dataContext, errorDataSet);
         }
     }
     context.ProgressSeparator('-');
 }
        private static void analyzeErrorsDataSet(IBackgroundContext context, ErrorsAnalyzerDataContext dataContext, SmoErrorDataSet errorDataSet)
        {
            context.ProgressSeparator();
            context.ReportProgress("РЕВЬЮ {0}", errorDataSet.FileName);

            var bill =
                dataContext.Bills.FirstOrDefault(
                    x => x.LFileName == errorDataSet.SourceFileName || x.HFileName == errorDataSet.SourceFileName);

            if (bill == null)
            {
                context.ReportProgress(@"Не найден файл счета {0}", errorDataSet.SourceFileName);
                return;
            }

            if (errorDataSet.PR.Rows.Count == 0)
            {
                context.ReportProgress(@"Ошибки не обнаружены", errorDataSet.FileName);
                return;
            }

            if (errorDataSet.SourceFileName.StartsWith("L"))
            {
                /* ошибки по списку персон */
                foreach (var prRow in errorDataSet.PR)
                {
                    context.ReportError(@"{0}", prRow);
                    if(prRow.N_ZAP != "")
                    {
                        var pers = bill.Persons.PERS.FirstOrDefault(x => x.ID_PAC == prRow.N_ZAP);
                        if(pers != null)
                            context.ReportProgress(@"    -> {0}", pers);
                    }
                }
            }
            else
            {
                /* ошибки по услугам */
                foreach (var prRow in errorDataSet.PR)
                {
                    context.ReportError(@"{0}", prRow);

                    if(prRow.OSHIB == "904")
                    {
                        var doc =
                            dataContext.DoctorList.FirstOrDefault(
                                x => x.SNILS == prRow.COMMENT.Substring(prRow.COMMENT.Length - 11));
                        if(doc != null)
                            context.ReportProgress(@"    Доктор {0}", doc.ToString());
                    }

                    if (prRow.N_ZAP != "")
                    {
                        var zap = bill.Reestr.ZAP.FirstOrDefault(x => x.N_ZAP == prRow.N_ZAP);
                        if (zap != null)
                        {
                            foreach (var sluchRow in zap.GetSLUCHRows())
                            {
                                context.ReportProgress(@"    -> {0}", sluchRow.ToString());
                            }
                        }
                    }
                }
            }
        }