Пример #1
0
        public List <String> BuildListingsWithSteamID(string appIDCsv)
        {
            string[] appIds = appIDCsv.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            List <string> outputList = new List <string>();

            if (appIds.Count() > 0)
            {
                foreach (string appId in appIds)
                {
                    int appIdVal = 0;

                    Int32.TryParse(appId, out appIdVal);

                    if (appIdVal != 0)
                    {
                        Product prod = listingRepository.GetProducts().FirstOrDefault(p => p.AppID == appIdVal);

                        if (prod == null)
                        {
                            prod = new Product(appIdVal);
                        }

                        BuildOrUpdateSteamProduct(appIdVal, prod);

                        if (prod != null)
                        {
                            if (prod.Listings == null || prod.Listings.Count == 0 || !prod.Listings.Any(l => l.ContainsPlatform("Steam")))
                            {
                                Listing  newListing = new Listing(prod.ProductName);
                                Platform steam      = GetPlatforms().Where(p => p.PlatformName.CompareTo("Steam") == 0).Single();
                                newListing.AddProduct(prod);
                                newListing.AddPlatform(steam);
                                listingRepository.InsertListing(newListing);
                                outputList.Add("Added " + appId);
                            }
                            else
                            {
                                listingRepository.UpdateProduct(prod);
                                outputList.Add("Updated " + appId);
                            }
                        }
                    }
                    else
                    {
                        outputList.Add("Failed to add entry for " + appId);
                    }
                }
            }

            unitOfWork.Save();

            return(outputList);
        }
Пример #2
0
        // gets the AppIDs contained within the package and then builds a listing for each one using BuildListingWithAppID
        private void BuildListingWithPackageID(Listing listing, List <int> appIds, string name = "")
        {
            foreach (int id in appIds)
            {
                Listing subListing = GetListingByAppID(id, "Steam");

                if (subListing == null)
                {
                    subListing = new Listing();
                    subListing.AddPlatform(GetPlatforms().Where(p => object.Equals(p.PlatformName, "Steam")).SingleOrDefault());
                    subListing.AddProduct(new Product(id));

                    AddListing(subListing);

                    BuildListingWithAppID(subListing, id);

                    UpdateListing(subListing);

                    listing.AddChildListing(subListing);
                }
                else
                {
                    listing.AddChildListing(subListing);
                }
            }

            if (String.IsNullOrEmpty(listing.ListingName))
            {
                string newName = "";

                string[] names = listing.ChildListings.OrderBy(l => l.ListingName).Select(l => l.ListingName).ToArray();

                if (names.Count() > 0)
                {
                    newName = names[0];
                }

                for (int i = 1; i < names.Count(); i++)
                {
                    newName = newName + "," + names[i];
                }

                listing.ListingName = newName;
            }
        }
Пример #3
0
        // --- Listing building logic
        public List <String> AddSteamProductKeys(Platform platform, string input)
        {
            List <Listing> listings  = new List <Listing>();
            List <String>  addedKeys = new List <String>();

            input = input.Replace("\r\n", "\r");
            input = input.Replace("\n", "\r");

            List <String> lines = input.Split(new string[] { "\r" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            Regex SubIDPriceKey = new Regex(@"^sub/([0-9]+)\t+([0-9,]+)\t+([0-9]+)\t+([^\t]+)(\t+[^\t]+)?$");
            Regex AppIDPriceKey = new Regex(@"^([0-9]+)\t+([0-9]+)(\t+[^\t]+)?$");
            //\t+([^\t]+)

            DateTime dateAdded = DateTime.Now;

            Match      match;
            bool       isGift   = false;
            string     key      = "";
            string     gameName = "";
            int        appId    = 0;
            int        price    = 0;
            int        subId    = 0;
            List <int> appIds   = new List <int>();

            foreach (String line in lines)
            {
                price    = 0;
                appId    = 0;
                gameName = "";
                key      = "";
                isGift   = false;
                subId    = 0;
                appIds   = new List <int>();

                if (AppIDPriceKey.Match(line).Success)
                {
                    match = AppIDPriceKey.Match(line);

                    appId = Int32.Parse(match.Groups[1].ToString());
                    price = Int32.Parse(match.Groups[2].ToString());

                    if (String.IsNullOrEmpty(match.Groups[3].Value))
                    {
                        isGift = true;
                    }
                    else
                    {
                        key = match.Groups[3].Value.Trim();
                    }
                }
                else if (SubIDPriceKey.Match(line).Success)
                {
                    match = SubIDPriceKey.Match(line);

                    subId = Int32.Parse(match.Groups[1].Value);

                    string[] separator = new string[] { "," };
                    foreach (string splitId in match.Groups[2].Value.Split(separator, StringSplitOptions.RemoveEmptyEntries))
                    {
                        appIds.Add(Int32.Parse(splitId));
                    }

                    if (String.IsNullOrEmpty(match.Groups[5].Value))
                    {
                        isGift = true;
                    }
                    else
                    {
                        key = match.Groups[5].Value.Trim();
                    }

                    gameName = match.Groups[4].Value;
                    price    = Int32.Parse(match.Groups[3].ToString());
                }
                else
                {
                    addedKeys.Add("Unable to parse: " + line);
                    continue;
                }

                Listing listing = null;

                if (appId != 0)
                {
                    listing = listings.Where(x => x.Product.AppID == appId).SingleOrDefault();

                    if (listing == null)
                    {
                        listing = GetListingByAppIDSteam(appId, platform.PlatformID);//GetListingByAppID(appId, platform.PlatformName);
                        if (listing != null)
                        {
                            listings.Add(listing);
                        }
                    }
                }
                else if (subId != 0)
                {
                    listing = listings.Where(x => x.Product.AppID == subId).SingleOrDefault();

                    if (listing == null)
                    {
                        listing = GetListingByAppIDSteam(subId, platform.PlatformID);//GetListingByAppID(subId, platform.PlatformName);
                        if (listing != null)
                        {
                            listings.Add(listing);
                        }
                    }
                }

                if (listing != null)
                {
                    listing.ListingPrice = price;
                    listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key));
                    listing.DateEdited = dateAdded;
                    //listingRepository.UpdateListing(listing);

                    addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...+1!");
                }
                else
                {
                    listing = new Listing(gameName, price, dateAdded);
                    listing.AddPlatform(platform);
                    listing.AddProductKeyAndUpdateQuantity(new ProductKey(isGift, key));

                    Product product = new Product(appId, gameName);
                    //Add logic to get data from api on product info & product details

                    listing.AddProduct(product);

                    // insert this listing entry for now, as we build the listing with data gathered from Steam's store api
                    // we may need to build more listings recursively, we need this listing to be in the repository so it doesn't get stuck in a loop
                    //AddListing(listing);

                    if (appId != 0)
                    {
                        BuildListingWithAppID(listing, appId);
                    }
                    else if (appIds.Count != 0)
                    {
                        listing.Product.AppID = subId;
                        BuildListingWithPackageID(listing, appIds, gameName);
                    }

                    listings.Add(listing);
                    //UpdateListing(listing);

                    addedKeys.Add(platform.PlatformName + ": " + listing.ListingName + "...created!");
                }
            }

            foreach (Listing updatedListing in listings)
            {
                if (updatedListing.ListingID != 0)
                {
                    listingRepository.UpdateListing(updatedListing);
                }
                else
                {
                    listingRepository.InsertListing(updatedListing);
                }
            }

            SiteNotification notification = new SiteNotification();
            var url = String.Format("https://theafterparty.azurewebsites.net/store/date?month={0}&day={1}&year={2}", DateTime.Today.Month, DateTime.Today.Day, DateTime.Today.Year);

            notification.Notification     = "[new][/new] [url=" + url + "][gtext]" + addedKeys.Count() + "[/gtext][/url] items added to the [url=https://theafterparty.azurewebsites.net/store/newest]Co-op Shop[/url]!";
            notification.NotificationDate = DateTime.Now;
            siteRepository.InsertSiteNotification(notification);

            unitOfWork.Save();

            return(addedKeys);
        }