/// <summary> /// Searches through files being fed to the StreamReader and adds them to the Dictionary if they match the pattern for reagents being created. /// </summary> /// <param name="reagentName">The reagent being searched for.</param> /// <param name="sr">The StreamReader going through the files.</param> protected void DoLines(string reagentName, StreamReader sr) { string line; while ((line = sr.ReadLine()) != null) { line = FileAccessing.HtmlToPlainText(line); if (RegexHandler.MatchFilter(line, RegexPatterns.Reagent(reagentName))) { _name = RegexHandler.MatchCkey(line); //_name = MatchString(line, patternName).ToLower(); //match name _dose = RegexHandler.MatchDose(line); //_dose = MatchString(line, patternDose); //match reagent dose //add to dic if (Int32.TryParse(_dose, out int doseInt)) { if (!_ckeyDic.ContainsKey(_name)) { _ckeyDic.Add(_name, doseInt); } else { _ckeyDic[_name] = _ckeyDic[_name] + doseInt; } } } } }
/// <summary> /// Compiles chemistry logs through a StreamReader into a sorted list of strings. /// </summary> public void CompileChems() { //get folder name and files within from user string path = FileAccessing.GetFolderPath(); string[] files = Directory.GetFiles(path); //ask user for reagent name _reagentName = GetReagentName(); foreach (string file in files) { _sr = new StreamReader(file); DoLines(_reagentName, _sr); _sr.Close(); } Console.WriteLine("Streams closed."); //write to file DictionaryToOrderedList(); FileAccessing.WriteToFile(_resultList); //empty used collections EmptyCollections(); Console.WriteLine("File written to."); }
/// <summary> /// Compiles chemistry logs through a StreamReader into a sorted list of strings. /// </summary> public void CompileChems() { //get file name from user _sr = FileAccessing.GetFilePath(); //get reagent name from user _reagentName = GetReagentName(); //process reagents DoLines(_reagentName, _sr); _sr.Close(); Console.WriteLine("Streams closed."); DictionaryToOrderedList(); //write to file FileAccessing.WriteToFile(_resultList); //empty used collections EmptyCollections(); Console.WriteLine("File written."); }