public static List <RAM> raminfo() { ManagementObjectSearcher searcher11 = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMemory"); List <RAM> memory = new List <RAM>(); foreach (ManagementObject queryObj in searcher11.Get()) { RAM memory0 = new RAM(); memory0.size = Math.Round(System.Convert.ToDouble(queryObj["Capacity"]) / 1024 / 1024 / 1024, 2).ToString(); memory0.speed = queryObj["Speed"].ToString(); memory0.slot = queryObj["BankLabel"].ToString(); //memory0.type = queryObj["Attributes"].ToString(); memory.Add(memory0); } return(memory); }
/// <summary> /// Generates a file with info from citilink /// </summary> /// TODO: nake for n pages public static void generateFile(int pages) { //Setting up webparser var wClient = new WebClient(); wClient.Proxy = null; wClient.Encoding = encode; HtmlDocument html = new HtmlDocument(); var shop = new Dictionary <string, List <Item> >(); foreach (var area in areas.Keys) { //Load items and parse characteristics var itemObjects = new List <Item>(); for (var i = 1; i <= pages; i++) { //Open page var page = url + area; html.LoadHtml(wClient.DownloadString(page + @"?available=1&p=" + i)); //get table of contents //*Search a tag var tmp = html.GetElementbyId("subcategoryList").ChildNodes.Where(x => x.Name == "div").Where(x => x.GetAttributeValue("class", "none") == "product_category_list").First(); var elements = tmp.FirstChild.ChildNodes.Where(x => x.GetAttributeValue("class", "") == "product_data__gtm-js product_data__pageevents-js"); //*Find id's var elements_id = new Dictionary <string, string>(); foreach (var elem in elements) { var data_params = elem.GetAttributeValue("data-params", "").Replace(""", "\""); dynamic stuff = JObject.Parse(data_params); elements_id.Add(stuff["id"].Value, stuff["shortName"].Value); } foreach (var id in elements_id.Keys) { //Loading new item html.LoadHtml(wClient.DownloadString(page + id + "/")); //Finding parametrs var tmp2 = html.GetElementbyId("content").ChildNodes[0].ChildNodes.Where(x => x.GetAttributeValue("class", "") == "specification_view product_view").First(); var tableOfParams = tmp2.ChildNodes.Where(x => x.GetAttributeValue("class", "") == "product_features").First().ChildNodes; //Creating object and loading params Item item; switch (area) { case "hdd/hdd_in/": item = new HDD(); break; case "parts/cpu/": item = new CPU(); break; case "parts/motherboards/": item = new MB(); break; case "parts/videocards/": item = new GPU(); break; case "parts/memory/": item = new RAM(); break; case "parts/powersupply/": item = new POWER(); break; case "parts/odds/": item = new ROM(); break; default: //never be reached item = new HDD(); break; } //Adding to category array item.add("Имя", elements_id[id]); item.webAddress = page + id + "/"; item.fillItem(tableOfParams); itemObjects.Add(item); } } //Adding to database shop.Add(areas[area], itemObjects); } //Creating a file var json = JsonConvert.SerializeObject(shop); System.IO.File.WriteAllText(@"ShopItems.json", json); }