private void backgroundWorkerErrorSearching_DoWork(object sender, DoWorkEventArgs e) { List<string> zipfilesPaths; List<string> txtfilesPaths; DateFileFinder finder = new DateFileFinder(fileNameDate, incomingFilesPath); Dekompresor dekomp; CsvParser parser; BackgroundWorker bw = sender as BackgroundWorker; int progress; progress = 0; bw.ReportProgress(progress, "Szukam plików..." + Environment.NewLine); zipfilesPaths = finder.FilesPaths; if (zipfilesPaths.Count() == 0) { progress = 99; bw.ReportProgress(progress, "Nie znaleziono plików." + Environment.NewLine); MessageBox.Show( "W folderze " + incomingFilesPath + " nie znaleziono pliku rozliczeniowego z potencjalną datą wpłynięcia błędu.", "Nie znaleziono", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } for (int i = 0; i < zipfilesPaths.Count(); i++) { progress = 10 + (int)(40 / zipfilesPaths.Count()) * i+1; bw.ReportProgress(progress, "Wypakowuję plik (" + (i+1).ToString() + " z " + zipfilesPaths.Count().ToString() + ")..." + Environment.NewLine); dekomp = new Dekompresor(zipfilesPaths.ElementAt(i), tempDir); dekomp.uncompress(); //todo: Zwracanie progresu } txtfilesPaths = finder.findFiles(tempDir); parser = new CsvParser(delimiter, Properties.Settings.Default.ErrorLineCode); for (int i = 0; i < txtfilesPaths.Count; i++) { progress = 50 + (int)(45 / txtfilesPaths.Count()) * i + 1; bw.ReportProgress( progress, "Przetwarzam plik (" + (i + 1).ToString() + " z " + txtfilesPaths.Count.ToString() + ")..." + Environment.NewLine); parser.addFile(txtfilesPaths.ElementAt(i)); } progress = 95; bw.ReportProgress(progress, "Szukam ARN..." + Environment.NewLine); progress = 100; bw.ReportProgress(progress, getChbErrorParameters(parser, ARN)); }
/// <summary> /// Zwraca tablicę {messageText, errorCode} /// </summary> /// <param name="parser">Obiekt typu CsvParser</param> /// <param name="arn">Szukany ARN</param> /// <returns></returns> private string[] getChbErrorParameters (CsvParser parser, string arn) { int arnPosition = Properties.Settings.Default.ArnFieldPosition; int messageTextPosition = Properties.Settings.Default.MessageTextPosition; int errorCodePosition = Properties.Settings.Default.ErrorCodePosition; string messageText, errorCode; string[] result = new string[2]; for (int i = 0; i < parser.TransactionLineList.Count(); i++) { if (parser.TransactionLineList.ElementAt(i)[arnPosition].Replace("\"", "") == arn) { messageText = parser.ErrorLineList.ElementAt(i)[messageTextPosition].Replace("\"", ""); errorCode = parser.ErrorLineList.ElementAt(i)[errorCodePosition].Replace("\"", ""); result[0] = messageText; result[1] = errorCode; return result; } } return null; }