public List<Role> GetRoles(Response response) { var document = new HtmlDocument(); document.LoadHtml(response.Content); var select = document.DocumentNode.SelectSingleNode("//select[@name='role_id']"); if (select == null) { return null; } var options = select.ChildNodes; List<Role> roles = new List<Role>(); Role role = null; foreach (var option in options) { if (option.Name == "option") { role = new Role(); role.Id = option.GetAttributeValue("value", null); roles.Add(role); } if (option.NodeType == HtmlNodeType.Text) { if (role != null) { role.Name = option.InnerText; } } } return roles; }
private string SaveResponse(Response response) { var filename = System.IO.Path.GetTempFileName(); using (var writer = new StreamWriter(filename)) { writer.Write(response.Content); } return filename; }
private void Error(Response response, string message) { var filename = SaveResponse(response); var exMsg = string.Format("{0}. Response saved to {1}.", message, filename); throw new SolResponseException(exMsg); }
private List<Member> ParseFilterTable(Response response) { var document = new HtmlDocument(); document.LoadHtml(response.Content); var table = document.DocumentNode.SelectSingleNode("//table[@class='filter_tab_table']"); var headers = table.SelectNodes("//input[@class='filterlink']").Select(elem => elem.GetAttributeValue("value", null)).ToList(); var dataRows = table.SelectNodes("//tr[starts-with(@class, 'table_tr_color')]"); List<Member> members = new List<Member>(); var memberType = typeof(Member); foreach (var tr in dataRows) { var dataFields = tr.SelectNodes("./td[starts-with(@class, 'listtxt_tab')]"); var index = 0; var member = new Member(); foreach (var td in dataFields) { var key = headers[index++]; var link = td.SelectSingleNode("./a"); string value = null; if (link == null) { value = td.InnerText; } else { var href = link.GetAttributeValue("href", null); var linkProp = memberType.GetProperty(key + "Link"); if (linkProp != null) { var url = ResolveUrl(href); linkProp.SetValue(member, url, null); } value = link.InnerText; } var prop = memberType.GetProperty(key); if (prop != null) { prop.SetValue(member, value, null); } } members.Add(member); } return members; }
private void CheckNoticeMessage(Response response, string p) { var messages = GetNoticeMessages(response.Content); foreach (var message in messages) { if (message.StartsWith(p)) { return; } } // Error var exMsg = string.Format("Expected message \"{0}\" not found", p); Error(response, exMsg); }