private static string[] SetCostTosPropertiesCarInfo(CarInfo info) { string cost = ""; string tos = ""; if (info.Cost1001 != null) { cost = info.Cost1001; tos = "1001"; } else if (info.Cost1050 != null) { cost = info.Cost1050; tos = "1050"; } else if (info.Cost1040 != null) { cost = info.Cost1040; tos = "1040"; } else if (info.Cost1030 != null) { cost = info.Cost1030; tos = "1030"; } else if (info.Cost1025 != null) { cost = info.Cost1025; tos = "1025"; } else if (info.Cost1020 != null) { cost = info.Cost1020; tos = "1020"; } return new string[] { cost, tos }; }
//getting information about cars private static CarInfo GetCarInfo(int trainNumberIdInList, HtmlAgilityPack.HtmlDocument PageGeneral) { //current train node int nodeGuid1 = PageGeneral.DocumentNode.InnerHtml.IndexOf("window.trips_['" + trainNumberIdInList + "']"); //next train node. For getting id of html segment in document int nodeGuid2 = PageGeneral.DocumentNode.InnerHtml.IndexOf("window.trips_['" + (trainNumberIdInList + 1).ToString() + "']"); // parse next html code(need if train node is last in html document) int functionStringIndex = 0; CarInfo info = new CarInfo(); if (nodeGuid2 == -1) { functionStringIndex = PageGeneral.DocumentNode.InnerHtml.IndexOf("function stip(a,b,c) {"); string doc = PageGeneral.DocumentNode.InnerHtml.Substring(nodeGuid1 + 18 + trainNumberIdInList.ToString().Length, functionStringIndex - (nodeGuid1 + 18 + trainNumberIdInList.ToString().Length + 2)); info = JsonConvert.DeserializeObject<CarInfo>(doc); } //getting info about html segment (need for form request string) if (nodeGuid2 != -1) { string doc = PageGeneral.DocumentNode.InnerHtml.Substring(nodeGuid1 + 18 + trainNumberIdInList.ToString().Length, nodeGuid2 - (nodeGuid1 + 18 + trainNumberIdInList.ToString().Length + 2)); info = JsonConvert.DeserializeObject<CarInfo>(doc); } return info; }