Exemple #1
0
        public string ParseLoungeNames() // returns html of trades
        {
            string listToBeOut = null, downloadString;
            string oneLeft, oneRight;

            string[]              customUrl;
            List <HtmlNode>       singleRowTrade_Node = new List <HtmlNode>();
            List <List <string> > LeftPlusRight = new List <List <string> >();
            List <ItemsStructure> WholeLeftStructure;
            List <ItemsStructure> WholeRightStructure;
            List <string>         NamesList = new List <string>();
            List <string>         LinksList = new List <string>();

            List <string> singleTradeList;

            using (WebClient client = new WebClient())
            {
                if (proxyEnabled)
                {
                    client.Proxy = wp;
                    Console.WriteLine("Changing proxy...");
                    Console.WriteLine("Proxy changed to " + wp.Address);
                }
                try
                {
                    while (client.IsBusy)
                    {
                        Thread.Sleep(20);
                    }
                    //downloadString = client.DownloadString("https://csgolounge.com");
                    downloadString = client.DownloadString(Custom_URL);
                    //client.Proxy = new WebProxy(); // reset proxy
                    singleRowTrade_Node = ParseHTMLFromString(downloadString);
                    customUrl           = singleRowTrade_Node[0].InnerHtml.Split('Â'); // contains all trades

                    //retrieve username from customURL
                    foreach (string singleTrade in customUrl)
                    {
                        singleTradeList = new List <string>();
                        if (singleTrade.Contains("left") || singleTrade.Contains("right"))
                        {
                            NamesList.Add(GetName(singleTrade));
                            LinksList.Add(GetLink(singleTrade));
                            singleTradeList = ParseSingleTrade_Step1(singleTrade);
                            LeftPlusRight.Add(singleTradeList); // contains list with all trades (0, 2, 4...left; 1,3,5,7, - right)
                        }                                       //need to compare all from left to all from right
                    }
                    // repeat this for steam links?
                    int iterator = 0;
                    foreach (List <string> singleOne in LeftPlusRight)
                    {
                        WholeLeftStructure  = new List <ItemsStructure>();
                        WholeRightStructure = new List <ItemsStructure>();
                        //single one now contains 2 lists (one for left, one for right)
                        if (singleOne.Count < 2)
                        {
                            Console.WriteLine("[IF Failed][Parser.cs][ParseLoungeNames]:: singleOne too small: " + singleOne.Count);
                        }
                        oneLeft  = singleOne[0];
                        oneRight = singleOne[1];
                        List <HtmlNode> nodeListBuffer = GetCustomSimpleNode(oneLeft, "b");

                        MatchCollection mc              = Regex.Matches(oneLeft, "<a[^>]+href=\"(.*?)\"[^>]*>");
                        List <string>   steamLinksLeft  = GetLinksFromString(oneLeft);
                        List <string>   steamLinksRight = GetLinksFromString(oneRight);

                        int    linkStartRight = oneRight.IndexOf("<a href=\"http:");
                        int    linkEndRight   = oneRight.IndexOf("target=");
                        string itemLinkRight  = HttpUtility.HtmlDecode(oneRight.Substring(linkStartRight + 9, linkEndRight - linkStartRight - 11));

                        int linksIterator = 0;
                        foreach (HtmlNode nodeBuffer in nodeListBuffer)
                        {
                            ItemsStructure leftStructureForList;
                            if (nodeBuffer.InnerHtml.Contains("Any Offers") || nodeBuffer.InnerHtml.Contains("Real Money") || nodeBuffer.InnerHtml.Contains("Any Keys"))
                            {
                                leftStructureForList = ConstructSmallStructure("NVM", nodeBuffer);
                            }
                            if (linksIterator < steamLinksLeft.Count)
                            {
                                leftStructureForList = ConstructSmallStructure(steamLinksLeft[linksIterator], nodeBuffer);
                                WholeLeftStructure.Add(leftStructureForList);
                                linksIterator++;
                            }
                            else
                            {
                                //Console.WriteLine("Iterator too big");
                                Console.WriteLine("[IF Failed][Parser.cs][ParseLoungeNames]:: Left Iterator too big: " + linksIterator + ", max is: " + steamLinksLeft.Count);
                            }
                        }
                        linksIterator  = 0;
                        nodeListBuffer = GetCustomSimpleNode(oneRight, "b");
                        foreach (HtmlNode nodeBuffer in nodeListBuffer)
                        {
                            ItemsStructure rightStructureForList;
                            if (nodeBuffer.InnerHtml.Contains("Any Offers") || nodeBuffer.InnerHtml.Contains("Real Money") || nodeBuffer.InnerHtml.Contains("Any Keys"))
                            {
                                rightStructureForList = ConstructSmallStructure("NVM", nodeBuffer);
                            }
                            if (linksIterator < steamLinksRight.Count)
                            {
                                rightStructureForList = ConstructSmallStructure(steamLinksRight[linksIterator], nodeBuffer);
                                WholeRightStructure.Add(rightStructureForList);
                                linksIterator++;
                            }
                            else
                            {
                                Console.WriteLine("[IF Failed][Parser.cs][ParseLoungeNames]:: Right Iterator too big: " + linksIterator + ", max is: " + steamLinksRight.Count);
                            }
                        }
                        if (iterator >= NamesList.Count)
                        {
                            Console.WriteLine("[IF Failed][Parser.cs][ParseLoungeNames]:: Names Iterator too big: " + linksIterator + ", max is: " + NamesList.Count);
                        }
                        DataStructure toBeAddedToStruct = new DataStructure
                        {
                            SellerName = NamesList[iterator],
                            Tradelink  = LinksList[iterator],
                            LeftItems  = WholeLeftStructure,
                            RightItems = WholeRightStructure
                        };
                        TradeStructure.Add(toBeAddedToStruct);
                        //SendStructToUI(toBeAddedToStruct);
                        iterator++;
                    }
                    SeparatePriceComputer();
                }
                catch (Exception e)
                {
                    Console.WriteLine("[EXCEPTION][Parser.cs][ParseLoungeNames]:: " + e.Message);
                }
            }
            TradeStructure = new List <DataStructure>();
            return(listToBeOut);
        }