public PriceInfo(Condition condition, PriceInfoType priceInfoType) { Condition = condition; PriceInfoType = priceInfoType; }
internal static float GetPriceGuideInfo(string itemId, int colorId, Condition condition, PriceInfoType priceInfo) { string[] args = new[] {itemId, colorId.ToString()}; string responseHtml = BrickClient.NavigateTo(BrickClient.Page.PriceGuide, true, args); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(responseHtml); HtmlNode root = htmlDoc.DocumentNode; var rows = root.SelectNodes("/table[@class='fv'][1]/tr/*"); List<HtmlNode> headerCells = rows.Skip(1).First().SelectNodes("td").ToList(); int newIndex = headerCells.FindIndex(c => c.InnerText.Equals("New")); int oldIndex = headerCells.FindIndex(c => c.InnerText.Equals("Old")); HtmlNode priceRow = rows.Skip(2).First(); var priceTableRows = priceRow.SelectNodes("/table/tr/*"); var priceTableCell = condition == Condition.New ? priceTableRows[newIndex] : priceTableRows[oldIndex]; var priceTableInnerRows = priceTableCell.SelectNodes("/table[@class='fv'/tr/*"); string searchString; switch (priceInfo) { case PriceInfoType.Min: searchString = "Min"; break; case PriceInfoType.Max: searchString = "Max"; break; default: case PriceInfoType.Average: searchString = "Avg"; break; case PriceInfoType.QuantityAverage: searchString = "Qty Avg"; break; } foreach (HtmlNode row in priceTableInnerRows) { if (!row.ChildNodes[0].InnerText.StartsWith(searchString)) continue; string price = row.ChildNodes[1].InnerText.Split(' ')[1]; return float.Parse(price); } return float.NaN; }