public void addShareListing(Share theShare) { SharesList.Add(theShare); this.share_count++; }
/// <summary> /// Use HTML-Parsing utilities to gather desired data /// </summary> private void populateSharesList() { HTMLDocument htmlDoc = new HTMLDocument(); IHTMLDocument2 iHtmlDoc2 = null; int FIELDS_EXPECTED = 5; if (FIELDS_EXPECTED == 5) { List<String> field_names = new List<String>(); field_names.Add("Group"); field_names.Add("Path"); field_names.Add("Percent Free"); field_names.Add("Space Free"); field_names.Add("Total Space"); SpcSentShares.field_names = field_names; } else { showErrorMessageBox("Error Parsing HTML ", "Unexpected Field Count: " + FIELDS_EXPECTED); return; } string html = readHTML(@"\\fiosfile\it\Storage Space Monitor\SpcSenGroup.htm"); if (html.Length < 1) { return; } List<string> desired_pats = new List<string>(); desired_pats.Add("Inventroy Share"); desired_pats.Add("Archive Share"); desired_pats.Add("Conversion Share"); desired_pats.Add("Library Share"); int html_tbl_ind = 0; int desired_tbl_ind = 5; // get the IHTMLDocument2 interface iHtmlDoc2 = (IHTMLDocument2)htmlDoc; // Put the document in design mode so we don't execute scripts while loading iHtmlDoc2.designMode = "On"; // Have to put some HTML in the DOM before using it iHtmlDoc2.write(html); iHtmlDoc2.close(); /// Get just the information we want (which is inside of <CODE> tags inside of <TR> tags /// inside of the nth <TABLE> where n = desired_tbl_ind) /// And add it to the list of Shares foreach (IHTMLElement htmlElem in (IHTMLElementCollection)iHtmlDoc2.body.all) { if (htmlElem is IHTMLTable) { html_tbl_ind++; continue; } if ((htmlElem is IHTMLTableRow) && (html_tbl_ind == desired_tbl_ind)) { HTMLTableRow table_row = htmlElem as HTMLTableRow; if (table_row != null) { try { foreach (string share_pat in desired_pats) if (table_row.innerHTML.IndexOf(share_pat) > -1) { string[] fields = new string[FIELDS_EXPECTED]; int fields_ind = 0; foreach (IHTMLElement codeElem in table_row.getElementsByTagName("CODE")) { if (fields_ind < FIELDS_EXPECTED && codeElem.innerText.Length > 0) { fields.SetValue(codeElem.innerText, fields_ind++); } } Share share = new Share(fields[0], fields[1] + "\\", fields[2], fields[3], fields[4]); SpcSentShares.addShareListing(share); } } catch (Exception ex) { showErrorMessageBox("Error Parsing HTML", ex.Message); return; } continue; } } } }