/// <summary> /// <para>Actual Main trigger. populate the collections with the regex matches</para> /// </summary> /// <param name="regexString">The regex string.</param> /// <param name="fileLocation">The file location.</param> /// <returns></returns> private int LoadDataTask(string regexString, string fileLocation) { try { _rgx = new Regex(regexString, RegexOptions.ExplicitCapture); } catch (ArgumentException) { //invalid regex return(2); } // Add group names from regex to RegexGroupsCollection foreach (string name in _rgx.GetGroupNames()) { if (name.Equals("0")) // 0 will be All { RegexGroupsCollection.Add("All"); } else { RegexGroupsCollection.Add(name); } } // Read the file //string line; using (var reader = new StreamReader(fileLocation)) { string line; while ((line = reader.ReadLine()) != null) { FullTextCollection.Add(line); // add the line to the list foreach (Match match in _rgx.Matches(line)) { foreach (int group in _rgx.GetGroupNumbers()) { /* for each group in every match, * append text to the dictionary with the group number as a key and text as the value */ if (group == 0) { ; //if group = 0 than it's the full text, and we already have it. } AddToDict(group, match.Groups[group].ToString(), match.ToString()); } } } } if (DataDictionary.Count == 0) { ClearData(); return(1); } // all ok return(0); }
/// <summary> /// <para>Clears the data.</para> /// </summary> private void ClearData() { if (FullTextCollection != null) { FullTextCollection.Clear(); } if (DataDictionary != null) { DataDictionary.Clear(); } if (RegexGroupsCollection != null) { RegexGroupsCollection.Clear(); } }