public async static void GetAllContent(string SectionContent, Node_1 n1_iteration) { string n1_andderivatives = SectionContent; //Get N1 title and content string n1_pattern = @"(^=|\n=)=([^=]?.+?)==((.|\n)*?)(?=($|\n===))"; Regex regex_select_n1 = new Regex(n1_pattern); Match m_n1 = regex_select_n1.Match(SectionContent); if (m_n1.Success) { n1_iteration.Title = m_n1.Groups[2].Value; string n1_content = m_n1.Groups[3].Value; n1_iteration.Content = n1_content; } string n2_pattern_and_deriv = @"(^=|\n=)==([^=]?.+?)===((\n|.)*?)(?=($|\n={3}(\w|\d|\s)))"; Regex regex_select_n2_and_deriv = new Regex(n2_pattern_and_deriv); MatchCollection n2_match_collection = regex_select_n2_and_deriv.Matches(SectionContent); int n_2_match_collection_count = n2_match_collection.Count; if (n_2_match_collection_count > 0) { List <Node_2> n2_list = new List <Node_2>(); foreach (Match match_n2 in n2_match_collection) { Node_2 node_2_interation = new Node_2(); string n2_only = @"(^=|\n=)==([^=]?.+?)===((.|\n)*?)(?=($|\n={3,5}(\w|\d|\s)))"; Regex regex_select_n2 = new Regex(n2_only); Match m_n2 = regex_select_n2.Match(match_n2.Value); node_2_interation.Title = m_n2.Groups[2].Value; string n2_content = m_n2.Groups[3].Value; node_2_interation.Content = n2_content; string n3_pattern_and_deriv = @"(^=|\n=)===([^=].+?)====((\n|.)*?)(?=($|\n={4}(\w|\d|\s)))"; Regex regex_select_n3_and_deriv = new Regex(n3_pattern_and_deriv); MatchCollection n3_match_collection = regex_select_n3_and_deriv.Matches(m_n2.Value); int n_3_match_collection_count = n3_match_collection.Count; if (n_3_match_collection_count > 0) { List <Node_3> n3_list = new List <Node_3>(); foreach (Match m_n3 in n3_match_collection) { Node_3 node_3_iteration = new Node_3(); node_3_iteration.Title = m_n3.Groups[2].Value; string n3_content = m_n2.Groups[3].Value; node_3_iteration.Content = n3_content; string n4_pattern_and_deriv = @"(^=|\n=)====([^=].+?)=====((\n|.)*?)(?=($|\n={5}(\w|\d|\s)))"; Regex regex_select_n4_and_deriv = new Regex(n4_pattern_and_deriv); MatchCollection n4_match_collection = regex_select_n4_and_deriv.Matches(m_n3.Value); int n_4_match_collection_count = n4_match_collection.Count; if (n_4_match_collection_count > 0) { List <Node_4> n4_list = new List <Node_4>(); foreach (Match m_n4 in n4_match_collection) { Node_4 node_4_iteration = new Node_4(); node_4_iteration.Title = m_n4.Groups[2].Value; string n4_content = m_n4.Groups[3].Value; node_4_iteration.Content = n4_content; //Add n4 iteration to list n4_list.Add(node_4_iteration); } //Add n4 list to n3 iteration node_3_iteration.Node_4_list = n4_list; } //Add n3 iteration to n3 list n3_list.Add(node_3_iteration); } //Add n3 list to n2 iteration node_2_interation.Node_3_list = n3_list; } //Add n2 iteration to n2 list n2_list.Add(node_2_interation); } //add n2 list to n1 iteration n1_iteration.Node_2_list = n2_list; } }
public async Task <WikiContent_Rootobject> PutSectionsIntoNodes(Rootobject rootobject) { WikiContent_Rootobject wikiContent = new WikiContent_Rootobject(); List <Node_1> n1_list = new List <Node_1>(); wikiContent.Node_1_list = n1_list; List <Node_2> n2_list = new List <Node_2>(); List <Node_3> n3_list = new List <Node_3>(); List <Node_4> n4_list = new List <Node_4>(); int n1 = -1; int n2 = -1; int n3 = -1; int n4 = 0; foreach (Section section in rootobject.parse.sections) { string section_title = section.anchor; string section_index = section.index; string section_num = section.number; string input = section.number; //n1 string pattern_n1 = @"^\d{1,3}$"; Regex regex_n1 = new Regex(pattern_n1); Match m_n1 = regex_n1.Match(input); //n2 string pattern_n2 = @"^\d{1,3}\.\d{1,3}$"; Regex regex_n2 = new Regex(pattern_n2); Match m_n2 = regex_n2.Match(input); //n3 string pattern_n3 = @"^\d{1,3}\.\d{1,3}\.\d{1,3}$"; Regex regex_n3 = new Regex(pattern_n3); Match m_n3 = regex_n3.Match(input); //n4 string pattern_n4 = @"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"; Regex regex_n4 = new Regex(pattern_n4); Match m_n4 = regex_n1.Match(input); if (m_n1.Success) { n2 = -1; n3 = -1; n4 = -1; //Add everything added previously Node_1 n1_iteration = new Node_1(); List <Node_2> n2list = new List <Node_2>(); n1_iteration.Node_2_list = n2list; n1_iteration.SectionTitle = section_title; n1_iteration.SectionNum = section_num; n1_iteration.SectionIndex = section_index; //string n1_and_derivative_content = rootobject.query.pages[0].revisions[0].content; Rootobject n1_rootobject = await GetPageContent(searchQuery.Text, section_index); string SectionContent = n1_rootobject.query.pages[0].revisions[0].content; //And Saves value in N1 GetAllContent(SectionContent, n1_iteration); wikiContent.Node_1_list.Add(n1_iteration); //Now empty the node so we add the current val into it Node_1 n1_empty = new Node_1(); n1_iteration = n1_empty; n1++; } else { } } return(wikiContent); }