public class MainViewModel : INotifyPropertyChanged { private List hsiRes = new(); private HashSet recordedIds = new(); public ObservableCollection RecordedIdList { get; set; } = new(); public event PropertyChangedEventHandler? PropertyChanged; private IdRecord? ParseLine(string line) { if (string.IsNullOrWhiteSpace(line)) { Logger.Log("ParseLine.result", "null (whitespace)"); return null; } var parts = line.Split('\t'); if (parts.Length < 2) { Logger.Log("ParseLine.result", "null (not enough parts)"); return null; } var rec = new IdRecord { Id = parts[0].Trim(), Status = parts[1].Trim() }; return rec; } private IEnumerable ParseLines(IEnumerable lines) { Logger.Log("ParseLines.count", lines.Count()); foreach (var line in lines) { var record = ParseLine(line); if (record != null) yield return record; } } private List ParseFile(string filePath) { Logger.Log("ParseFile.filePath", filePath); Logger.Log("ParseFile.exists", File.Exists(filePath)); if (!File.Exists(filePath)) return new List(); var records = ParseLines(File.ReadAllLines(filePath)).ToList(); Logger.Log("ParseFile.records.Count", records.Count); return records; } public void LoadHSI(string hsiPath) { Logger.Log("LoadHSI.path", hsiPath); hsiRes = ParseFile(hsiPath); Logger.Log("LoadHSI.hsiRes.Count", hsiRes.Count); } public void HandleInput(string inputId) { Logger.Log("HandleInput.inputId", inputId); var match = hsiRes.FirstOrDefault(x => string.Equals(x.Id, inputId.Trim(), StringComparison.OrdinalIgnoreCase)); Logger.Log("HandleInput.match", match == null ? "null" : $"{match.Id}|{match.Status}"); Logger.Log("HandleInput.recordedIds.Contains", recordedIds.Contains(inputId)); if (match != null) { if (recordedIds.Contains(inputId)) { MessageBox.Show($"Ez az ID már szerepel a listában: {inputId}"); Logger.Log("HandleInput.action", "MessageBox: már szerepel"); return; } recordedIds.Add(inputId); Logger.Log("HandleInput.action", $"Added to recordedIds: {inputId}"); RecordedIdList.Insert(0, match); Logger.Log("HandleInput.action", $"Inserted to RecordedIdList: {match.Id}|{match.Status}"); } else { MessageBox.Show($"Ez az ID nem rendelkezik HSI eredménnyel: {inputId}"); Logger.Log("HandleInput.action", "MessageBox: nincs HSI eredmény"); } } }