예제 #1
0
        // Gets Supreme item's ID from item's HTML page depending on size chosen
        public String GetItemSizeIdFromPage(string pageHTML, TaskItemInfo tii)
        {
            Regex  sizePattern;
            Match  sizeMatch;
            string chosenSizeString = tii.size;
            string size             = "";

            if (tii.size.Equals("Universal"))    // universal size items - those that are available in only one size.
            {
                sizePattern = new Regex("id=\"size\" value=\"([0-9]*)\"");
                sizeMatch   = sizePattern.Match(pageHTML);
                if (sizeMatch.Groups.Count > 1)
                {
                    size = sizeMatch.Groups[1].Value;
                }
                else
                {
                    return(null);
                }
            }
            else if (tii.size.Equals("Any"))    // choose size randomly - either universal or from size list.
            {
                sizePattern = new Regex("<option value=\"([0-9]*)\">");
                MatchCollection matches      = sizePattern.Matches(pageHTML); // first check if item is universal or multi-size
                int             matchesFound = matches.Count;                 // if it's universal we won't find options to choose

                if (matchesFound >= 1)                                        // Items are in multiple or one choices ( Not universal )
                {
                    int idChosen = (int)(generator.NextDouble() * (matchesFound));
                    return(matches[idChosen].Groups[1].Value);
                }

                // Check if item has only one choice
                sizePattern  = new Regex("id=\"size\" value=\"([0-9]*)\"");
                matches      = sizePattern.Matches(pageHTML);
                matchesFound = matches.Count;
                if (matchesFound >= 1)
                {
                    return(matches[0].Groups[1].Value);
                }
                return(null);
            }
            else   // normal sizing items - Medium, Large - chosen by user
            {
                sizePattern = new Regex("<option value=\"([0-9]*)\">" + chosenSizeString + "</option>");
                sizeMatch   = sizePattern.Match(pageHTML);
                if (sizeMatch.Groups.Count > 1)
                {
                    size = sizeMatch.Groups[1].Value;
                }
                else  // no sizes available
                {
                    return(null);
                }
            }
            return(size);
        }
예제 #2
0
        public String GetItemStyleId(string pageHTML, TaskItemInfo tii)
        {
            Regex stylePattern = new Regex("id=\"style\" value=\"([0-9]*)\"");
            Match styleMatch   = stylePattern.Match(pageHTML);

            if (styleMatch.Groups.Count > 1)
            {
                return(styleMatch.Groups[1].Value);
            }
            return(null);
        }
예제 #3
0
        //  Gets Website's HTML in specific category, finds all items
        //  and returns item matching by color and keywords specified in TaskItemInfo
        //  null is returned if finding fails.
        private ShopItemInfo findMatchingItem(TaskInfo info, TaskItemInfo userItem)
        {
            SupremeParser       parser = new SupremeParser();
            List <ShopItemInfo> items  = parser.GetItemsFromCategory(userItem.category, cookies[info.name], (ProxyInfo)infoManager.GetProxyByName(info.proxyName));

            if (items == null)
            {
                return(null);
            }
            forwardMessageToLogMonitor(Properties.Resources.logFoundTotalOf + " " + items.Count.ToString() +
                                       " " + Properties.Resources.logItemsIn + " " + userItem.category, info.name);

            foreach (var shopItem in items)                                                                           // find item by name and color
            {
                if (everyKeywordMatches(userItem.keywords, shopItem.name) && shopItem.color.Contains(userItem.color)) // get first matching item
                {
                    return(shopItem);
                }
            }
            return(null);
        }
예제 #4
0
        private void butAddItem_Click(object sender, RoutedEventArgs e)
        {
            TaskItemInfo tii = new TaskItemInfo();

            tii.category = ((ComboBoxItem)cbCategory.SelectedItem).Content.ToString();
            tii.color    = tbColor.Text.ToLower();
            tii.size     = ((ComboBoxItem)cbSize.SelectedItem).Content.ToString();

            if (tii.category.Equals(""))
            {
                MessageBox.Show(Properties.Resources.errorEnter + " " + Properties.Resources.taskInfoCategory);
                return;
            }
            else if (tii.color.Equals(""))
            {
                MessageBox.Show(Properties.Resources.errorEnter + " " + Properties.Resources.taskInfoColor);
                return;
            }
            else if (tii.size.Equals(""))
            {
                MessageBox.Show(Properties.Resources.errorEnter + " " + Properties.Resources.taskInfoSize);
                return;
            }

            string keywords = tbKeywords.Text.ToLower();

            string[] akeywords = keywords.Split(',');
            foreach (var keyword in akeywords)
            {
                tii.keywords.Add(keyword);
            }
            items.Add(tii);

            lvItems.Items.Add(new LvItemInfo {
                Id = (id++).ToString(), Keywords = tii.GetKeywords(), Size = tii.size, Color = tii.color, Category = tii.category
            });
        }
예제 #5
0
        // Adds item to cart, stores cookies in TaskInfo,
        // those cookies have informations about items
        // that are put in cart
        // returns false if failed
        private bool addToCart(ShopItemInfo itemInfo, TaskInfo ti, TaskItemInfo tii)
        {
            forwardMessageToLogMonitor(Properties.Resources.logAdding + " " + itemInfo.name + " " + Properties.Resources.logToCart, ti.name);
            SupremeParser parser = new SupremeParser();

            // get url of the chosen item
            var itemUrl = "http://www.supremenewyork.com" + itemInfo.url;

            ti.lastItemUri = itemUrl; // referer for checkout
            var responseItemHTML = WebTools.GetPageHTML(itemUrl, cookies[ti.name], (ProxyInfo)infoManager.GetProxyByName(ti.proxyName));

            string itemAddUrl = "https://www.supremenewyork.com" + parser.GetItemCartAddUrl(responseItemHTML);

            String style = parser.GetItemStyleId(responseItemHTML, tii);
            String size  = parser.GetItemSizeIdFromPage(responseItemHTML, tii);

            String csrf_token = new Regex("<meta name=\"csrf-token\" content=\"([^\"]*)\"").Match(responseItemHTML).Groups[1].Value;


            //FileLogger.log("ItemUri: " + itemUrl + "\n");
            //FileLogger.log("Style: " + style + " Size: " + size + "\n");
            //FileLogger.log("PostUri: " + itemAddUrl + "\n");

            if (style == null || size == null)
            {
                forwardMessageToLogMonitor(Properties.Resources.logItemNotAvailable, ti.name);
                return(false);
            }
            string postString = PostStringGenerator.generateAddCartPostString(size, style);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(itemAddUrl);

            req.Referer = itemUrl;
            req.Method  = "POST";
            req.Accept  = "*/*;q=0.5, text/javascript, application/javascript, application/ecmascript, application/x-ecmascript";
            req.Headers["x-csrf-token"] = csrf_token;
            req.ContentType             = "application/x-www-form-urlencoded; charset=UTF-8"; // utf8 del
            req.ContentLength           = postString.Length;
            req.CookieContainer         = cookies[ti.name];

            WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req);

            // as postWriter doesn't actually send any data, we only need to make sure that GetResponse is going good.
            StreamWriter postWriter = new StreamWriter(req.GetRequestStream());

            postWriter.Write(postString);
            postWriter.Close();


            //MSDOC
            //The GetResponse method sends a request to an Internet resource and returns a WebResponse instance.
            //If the request has already been initiated by a call to GetRequestStream, the GetResponse method
            //completes the request and returns any response. \|/
            var res = WebTools.SendRequestAtAllCosts(req);

            res.Close();
            // it takes ~7ms to read the response, but well, we don't need it here, we just need cookiez

            foreach (var cookie in cookies[ti.name].GetCookies(new Uri("http://www.supremenewyork.com")))
            {
                Console.WriteLine(cookie.ToString());
            }


            //cookies are now in CookieContainer which is a reference for cookies[ti.number] ( no need to save them )
            forwardMessageToLogMonitor(Properties.Resources.logSuccessfullyAdded + " " + itemInfo.name + " " + Properties.Resources.logToCart, ti.name);
            return(true);
        }