Example #1
0
        public static MB mbinfo()
        {
            ManagementObjectSearcher searcher11 =
                new ManagementObjectSearcher("root\\CIMV2",
                                             "SELECT * FROM Win32_MotherboardDevice ");
            MB mb = new MB();

            foreach (ManagementObject queryObj in searcher11.Get())
            {
                mb.name         = queryObj["Name"].ToString();
                mb.gpuinterface = queryObj["PrimaryBusType"].ToString();
            }
            return(mb);
        }
Example #2
0
        public MB findMB(string file)
        {
            string patternName = "(?<=\\sСистемная плата\\s+)\\S.+$";
            var    nameMatch   = Regex.Matches(file, patternName, RegexOptions.Multiline)[0].Value;

            if (nameMatch == "Неизвестно")
            {
                throw new Exception("Невозможно определить плату.");
            }

            string patternSocket = "(?<=Число гнёзд для ЦП\\s+)\\S.+$";
            var    socketMatch   = Regex.Matches(file, patternSocket, RegexOptions.Multiline)[0].Value;

            if (socketMatch.IndexOf("LGA") != -1)
            {
                socketMatch = socketMatch.Remove(0, 2).Insert(3, " "); //Плохо работает с процессорами АМД.
            }
            string patternInterface    = "(?<=Разъёмы расширения\\s+)\\S.+$";
            var    gpuInterfaceMatches = Regex.Matches(file, patternInterface, RegexOptions.Multiline);
            var    gpuInterfaces       = Regex.Replace(gpuInterfaceMatches[0].Value, "(\\d| )", "");

            string patternRamSlots = "(?<=Устройства памяти\\s+)\\d+";
            var    ramSlotsMatches = Regex.Matches(file, patternRamSlots, RegexOptions.Multiline);

            string patternMaxRam = "(?<=\\s+Макс. объём памяти\\s+)\\d+.+?$";
            var    maxRamMatches = Regex.Matches(file, patternMaxRam, RegexOptions.Multiline);

            string patternRamType = "DDR\\d";
            var    ramTypeMatches = Regex.Matches(file, patternRamType, RegexOptions.Multiline);

            if (gpuInterfaceMatches.Count == 0 || ramSlotsMatches.Count == 0 || maxRamMatches.Count == 0 || ramTypeMatches.Count == 0)
            {
                throw new Exception("Невозможно определить параметры платы.");
            }

            string patternStoreInterface = "(?<=Интерфейс\\s+)SATA.+$";
            var    storeInterfaceMatches = Regex.Matches(file, patternStoreInterface, RegexOptions.Multiline);

            if (storeInterfaceMatches.Count == 0)
            {
                throw new Exception("Не найдена информация об интерфейсах жестких дисков.");
            }
            mb = new MB(nameMatch, storeInterfaceMatches[0].Value, gpuInterfaces, socketMatch, ramSlotsMatches[0].Value, maxRamMatches[0].Value, ramTypeMatches[0].Value);
            return(mb);
        }
Example #3
0
        /// <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("&quot;", "\"");
                        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);
        }