예제 #1
0
        public ShoppingCartEntry(AppUser user, Listing listing, int quantity)
        {
            DateAdded = DateTime.Now;
            this.Quantity = quantity;

            this.ListingID = listing.ListingID;
            this.Listing = listing;

            this.UserID = user.Id;
            this.AppUser = user;
        }
예제 #2
0
 public void AddParent(Listing listing)
 {
     ParentListings.Add(listing);
     listing.ChildListings.Add(this);
 }
예제 #3
0
        public Listing RemoveParent(Listing listing)
        {
            if (ParentListings.Contains(listing))
            {
                ParentListings.Remove(listing);
                return listing;
            }

            return null;
        }
예제 #4
0
 public bool OwnsListing(Listing listing)
 {
     if (OwnedGames == null) return false;
     return (OwnedGames.Where(o => o.AppID == listing.Product.AppID).Count() >= 1) ? true : false;
 }
예제 #5
0
        public void AddChildListing(Listing listing)
        {
            if (ChildListings == null)
            {
                ChildListings = new HashSet<Listing>();
            }

            if (listing.ParentListings == null)
            {
                listing.ParentListings = new HashSet<Listing>();
            }

            ChildListings.Add(listing);
            listing.ParentListings.Add(this);

            UpdateQuantity();
        }
예제 #6
0
        public void EditListing(Listing listing)
        {
            Listing updatedListing = listingRepository.GetListingByID(listing.ListingID);

            updatedListing.ListingName = listing.ListingName;
            updatedListing.ListingPrice = listing.ListingPrice;
            updatedListing.DateEdited = DateTime.Now;

            listingRepository.UpdateListing(updatedListing);
            unitOfWork.Save();
        }
예제 #7
0
        public ShoppingCartEntry AddShoppingCartEntry(Listing listing, int quantity = 1)
        {
            ShoppingCartEntry entry = ShoppingCartEntries.Where(e => e.ListingID == listing.ListingID).SingleOrDefault(); // && Object.Equals(e.UserID, Id)).SingleOrDefault();

            if (entry == null)
            {
                entry = new ShoppingCartEntry(this, listing, quantity);
                ShoppingCartEntries.Add(entry);
            }
            else
            {
                entry.Quantity++;
            }

            return entry;
        }
예제 #8
0
        public async Task BuildListingWithPackageID(Listing listing, int packageId, string name = "")
        {
            SteamClient client = new SteamClient();
            SteamApps steamApps = client.GetHandler<SteamApps>();
            AsyncJobMultiple<SteamApps.PICSProductInfoCallback>.ResultSet resultSet = await steamApps.PICSGetProductInfo(app: null, package: (uint)packageId);

            List<int> appIds = new List<int>();

            if (resultSet.Complete)
            {
                SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.First();

                SteamApps.PICSProductInfoCallback.PICSProductInfo packageInfo = productInfo.Packages.FirstOrDefault().Value;
                List<KeyValue> list = packageInfo.KeyValues.Children.FirstOrDefault().Children;
                
                foreach (KeyValue val in list)
                {
                    if (val.Name.CompareTo("appids") == 0)
                    {
                        foreach (KeyValue appVal in val.Children)
                        {
                            appIds.Add(Int32.Parse(appVal.Value));
                        }
                    }
                }
            }

            foreach (int id in appIds)
            {
                Listing subListing = _storeService.GetListingByAppID(id, "Steam");

                if (subListing == null)
                {
                    BuildListingWithAppID(subListing, id);
                    _storeService.AddListing(subListing);
                    listing.ChildListings.Add(subListing);
                }
                else
                {
                    listing.ChildListings.Add(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;
            }
        }
예제 #9
0
        public void BuildListingWithAppID(Listing listing, int appId)
        {
            Product product = listing.Product ?? new Product();
            ProductDetail productDetail = product.ProductDetail ?? new ProductDetail();

            string url = String.Format("http://store.steampowered.com/api/appdetails?appids={0}", product.AppID);

            string result = new System.Net.WebClient().DownloadString(url);

            JObject jsonResult = JObject.Parse(result);

            string appID = product.AppID.ToString();

            if (!jsonResult[appID].Any() || !jsonResult[appID]["data"].Any())
            {
                return;
            }

            JToken appData = jsonResult[appID]["data"];
            int baseAppID = 0;

            //get all the product details from the jtoken
            productDetail.ProductType = (string)appData["type"];
            productDetail.ProductName = (string)appData["name"];
            productDetail.AgeRequirement = (int)appData["required_age"];
            productDetail.DetailedDescription = (string)appData["detailed_description"];
            productDetail.DLCAppIDs = appData["dlc"].Select(d => (int)d).ToArray();
            productDetail.AboutTheGame = (string)appData["about_the_game"];
            productDetail.BaseProductName = (string)appData["fullgame "]["name"];
            baseAppID = (int)appData["fullgame"]["appid"];
            productDetail.SupportedLanguages = (string)appData["supported_languages"];
            productDetail.HeaderImageURL = (string)appData["header_image"];
            productDetail.ProductWebsite = (string)appData["website"];
            productDetail.PCMinimumRequirements = (string)appData["pc_requirements"]["minimum"];
            productDetail.PCRecommendedRequirements = (string)appData["pc_requirements"]["recommended"];
            productDetail.MacMinimumRequirements = (string)appData["mac_requirements"]["minimum"];
            productDetail.MacRecommendedRequirements = (string)appData["mac_requirements"]["recommended"];
            productDetail.LinuxMinimumRequirements = (string)appData["linux_requirements"]["minimum"];
            productDetail.LinuxRecommendedRequirements = (string)appData["linux_requirements"]["recommended"];
            productDetail.Developers = appData["developers"].Select(d => (string)d).ToArray();
            productDetail.Publishers = appData["publishers"].Select(d => (string)d).ToArray();
            productDetail.DemoAppID = (int)appData["demos"]["appid"];
            productDetail.DemoRestrictions = (string)appData["demos"]["description"];
            productDetail.FinalPrice = (int)appData["price_overview"]["final"];
            productDetail.InitialPrice = (int)appData["price_overview"]["initial"];
            productDetail.CurrencyType = (string)appData["price_overview"]["currency"];
            productDetail.PackageIDs = appData["packages"].Select(d => (int)d).ToArray();
            productDetail.AvailableOnPC = (bool)appData["platforms"]["windows"];
            productDetail.AvailableOnMac = (bool)appData["platforms"]["mac"];
            productDetail.AvailableOnLinux = (bool)appData["platforms"]["linux"];
            productDetail.MetacriticScore = (int)appData["metacritic"]["score"];
            productDetail.MetacriticURL = (string)appData["metacritic"]["url"];
            productDetail.Genres = appData["genres"].Select(d => (string)d["description"]).ToArray();
            productDetail.TotalRecommendations = (int)appData["recommendations"]["total"];
            productDetail.NumAchievements = (int)appData["achievements"]["total"];
            productDetail.ReleaseDate = (string)appData["release_date"]["date"];

            JArray movies = (JArray)appData["movies"];

            for (int i = 0; i < movies.Count; i++)
            {
                AppMovie temp = new AppMovie();

                temp.Highlight = (bool)movies[i]["highlight"];
                temp.LargeMovieURL = (string)movies[i]["webm"]["max"];
                temp.Name = (string)movies[i]["name"];
                temp.SmallMovieURL = (string)movies[i]["webm"]["480"];
                temp.ThumbnailURL = (string)movies[i]["thumbnail"];

                productDetail.AddAppMovie(temp);
            }

            JArray screenshots = (JArray)appData["screenshots"];

            for (int i = 0; i < screenshots.Count; i++)
            {
                AppScreenshot temp = new AppScreenshot();

                temp.FullSizeURL = (string)screenshots[i]["path_full"];
                temp.ThumbnailURL = (string)screenshots[i]["path_thumbnail"];

                productDetail.AddAppScreenshot(temp);
            }

            string[] categories = appData["categories"].Select(c => (string)c).ToArray();

            if (categories != null)
            {
                for (int i = 0; i < categories.Count(); i++)
                {
                    if (_storeService.GetProductCategoryByName(categories[i]) == null)
                    {
                        ProductCategory category = new ProductCategory(categories[i]);
                        product.AddProductCategory(category);
                    }
                    else
                    {
                        product.AddProductCategory(_storeService.GetProductCategoryByName(categories[i]));
                    }
                }
            }

            product.AddProductDetail(productDetail);
            if (String.IsNullOrEmpty(product.ProductName))
            {
                product.ProductName = productDetail.ProductName;
            }
        }
예제 #10
0
        // gets the AppIDs contained within the package and then builds a listing for each one (and recursively builds listings for DLCs or the base game for each AppID, if any exists) 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;
            }
        }
예제 #11
0
        // using a Steam App ID, queries the storefront API to get information about the product and build the listing object
        // listings sent to this method should be persisted to prevent looping behavior
        private void BuildListingWithAppID(Listing listing, int appId)
        {
            if (listing.ListingID == 0)
            {
                throw new Exception("The listing was not persisted!");
            }
            if (listing.Product == null)
            {
                throw new Exception("A valid product object was not added to the listing object!");
            }

            ProductDetail productDetail = listing.Product.ProductDetail ?? new ProductDetail();

            if (listing.Product.ProductDetail == null)
            {
                listing.Product.AddProductDetail(productDetail);
            }

            string url = String.Format("http://store.steampowered.com/api/appdetails?appids={0}", listing.Product.AppID);

            string result = new System.Net.WebClient().DownloadString(url);

            JObject jsonResult = JObject.Parse(result);

            string appID = listing.Product.AppID.ToString();

            if (jsonResult == null || jsonResult[appID] == null || jsonResult[appID]["data"] == null)
            {
                return;
            }

            JToken appData = jsonResult[appID]["data"];
            int baseAppID = 0;

            //get all the product details from the jtoken
            productDetail.AppID = (appData["steam_appid"].IsNullOrEmpty()) ? 0 : (int)appData["steam_appid"];
            productDetail.ProductType = (string)appData["type"] ?? "";
            productDetail.ProductName = (string)appData["name"] ?? "";
            listing.ListingName = (String.IsNullOrEmpty(productDetail.ProductName) ? listing.ListingName : productDetail.ProductName);

            productDetail.AgeRequirement = (appData["required_age"].IsNullOrEmpty()) ? 0 : (int)appData["required_age"];
            productDetail.DetailedDescription = (string)appData["detailed_description"] ?? "";

            if (!appData["dlc"].IsNullOrEmpty())
            {
                productDetail.DLCAppIDs = appData["dlc"].Select(d => (int)d).ToArray();
            }

            productDetail.AboutTheGame = (string)appData["about_the_game"] ?? "";

            if (!appData["fullgame"].IsNullOrEmpty())
            {
                productDetail.BaseProductName = (string)appData["fullgame"]["name"] ?? "";
                baseAppID = (appData["fullgame"]["appid"].IsNullOrEmpty()) ? 0 : (int)appData["fullgame"]["appid"];
            }

            productDetail.SupportedLanguages = (string)appData["supported_languages"] ?? "";
            productDetail.HeaderImageURL = (string)appData["header_image"] ?? "";
            productDetail.ProductWebsite = (string)appData["website"] ?? "";

            if (!appData["pc_requirements"].IsNullOrEmpty())
            {
                productDetail.PCMinimumRequirements = (string)appData["pc_requirements"]["minimum"] ?? "";
                productDetail.PCRecommendedRequirements = (string)appData["pc_requirements"]["recommended"] ?? "";
            }

            if (!appData["mac_requirements"].IsNullOrEmpty())
            {
                productDetail.MacMinimumRequirements = (string)appData["mac_requirements"]["minimum"] ?? "";
                productDetail.MacRecommendedRequirements = (string)appData["mac_requirements"]["recommended"] ?? "";
            }

            if (!appData["linux_requirements"].IsNullOrEmpty())
            {
                productDetail.LinuxMinimumRequirements = (string)appData["linux_requirements"]["minimum"] ?? "";
                productDetail.LinuxRecommendedRequirements = (string)appData["linux_requirements"]["recommended"] ?? "";
            }

            if (!appData["developers"].IsNullOrEmpty())
            {
                productDetail.Developers = appData["developers"].Select(d => (string)d).ToArray();
            }

            if (!appData["publishers"].IsNullOrEmpty())
            {
                productDetail.Publishers = appData["publishers"].Select(d => (string)d).ToArray();
            }

            if (!appData["demos"].IsNullOrEmpty())
            {
                productDetail.DemoAppID = (appData["demos"][0]["appid"].IsNullOrEmpty()) ? 0 : (int)appData["demos"][0]["appid"];
                productDetail.DemoRestrictions = (string)appData["demos"][0]["description"] ?? "";
            }

            if (!appData["price_overview"].IsNullOrEmpty())
            {
                productDetail.FinalPrice = (appData["price_overview"]["final"].IsNullOrEmpty()) ? 0 : (int)appData["price_overview"]["final"];
                productDetail.InitialPrice = (appData["price_overview"]["initial"].IsNullOrEmpty()) ? 0 : (int)appData["price_overview"]["initial"];
                productDetail.CurrencyType = (string)appData["price_overview"]["currency"] ?? "";
            }

            if (!appData["packages"].IsNullOrEmpty())
            {
                productDetail.PackageIDs = appData["packages"].Select(d => (int)d).ToArray();
            }

            if (!appData["platforms"].IsNullOrEmpty())
            {
                productDetail.AvailableOnPC = (appData["platforms"]["windows"].IsNullOrEmpty()) ? true : (bool)appData["platforms"]["windows"];
                productDetail.AvailableOnMac = (appData["platforms"]["mac"].IsNullOrEmpty()) ? false : (bool)appData["platforms"]["mac"];
                productDetail.AvailableOnLinux = (appData["platforms"]["linux"].IsNullOrEmpty()) ? false : (bool)appData["platforms"]["linux"];
            }

            if (!appData["metacritic"].IsNullOrEmpty())
            {
                productDetail.MetacriticScore = (appData["metacritic"]["score"].IsNullOrEmpty()) ? 0 : (int)appData["metacritic"]["score"];
                productDetail.MetacriticURL = (string)appData["metacritic"]["url"] ?? "";
            }

            if (!appData["genres"].IsNullOrEmpty())
            {
                JArray jGenres = (JArray)appData["genres"];
                List<string> genresList = new List<string>();

                for (int i = 0; i < jGenres.Count; i++)
                {
                    genresList.Add((string)jGenres[i]["description"]);
                }

                string[] genres = genresList.ToArray();

                if (genres != null)
                {
                    for (int i = 0; i < genres.Count(); i++)
                    {
                        if (GetTagByName(genres[i]) != null)
                        {
                            listing.Product.AddTag(GetTagByName(genres[i]));
                        }
                        else
                        {
                            Tag tag = new Tag(genres[i]);
                            listing.Product.AddTag(tag);
                        }
                    }
                }

                productDetail.Genres = genresList.ToArray();
            }

            if (!appData["recommendations"].IsNullOrEmpty())
            {
                productDetail.TotalRecommendations = (appData["recommendations"]["total"].IsNullOrEmpty()) ? 0 : (int)appData["recommendations"]["total"];
            }

            if (!appData["achievements"].IsNullOrEmpty())
            {
                productDetail.NumAchievements = (appData["achievements"]["total"].IsNullOrEmpty()) ? 0 : (int)appData["achievements"]["total"];
            }

            if (!appData["release_date"].IsNullOrEmpty())
            {
                productDetail.ReleaseDate = (string)appData["release_date"]["date"] ?? "";
            }

            // run a sub-routine to build a listing/product for the base game of this demo/DLC
            if (baseAppID != 0)
            {
                Listing baseGameListing = GetListingByAppID(baseAppID, "Steam");

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

                    AddListing(baseGameListing);

                    BuildListingWithAppID(baseGameListing, baseAppID);

                    if (productDetail.ProductType.CompareTo("dlc") == 0)
                    {
                        baseGameListing.Product.ProductDetail.AddDLC(productDetail.Product);
                    }
                    else
                    {
                        productDetail.BaseProduct = baseGameListing.Product;
                    }

                    UpdateListing(baseGameListing);
                }
                else
                {
                    if (productDetail.ProductType.CompareTo("dlc") == 0)
                    {
                        baseGameListing.Product.ProductDetail.AddDLC(productDetail.Product);
                    }
                    else
                    {
                        productDetail.BaseProduct = baseGameListing.Product;
                    }
                }
            }

            // run a series of sub-routines to build listings/products for each DLC of this game (if applicable)
            if (productDetail.DLCAppIDs != null && productDetail.DLCAppIDs.Count() > 0)
            {
                for (int i = 0; i < productDetail.DLCAppIDs.Count(); i++)
                {
                    Listing DLCListing = GetListingByAppID(productDetail.DLCAppIDs[i], "Steam");

                    if (DLCListing == null)
                    {
                        DLCListing = new Listing();
                        DLCListing.AddPlatform(GetPlatforms().Where(p => object.Equals(p.PlatformName, "Steam")).SingleOrDefault());
                        DLCListing.AddProduct(new Product(productDetail.DLCAppIDs[i]));

                        AddListing(DLCListing);

                        BuildListingWithAppID(DLCListing, productDetail.DLCAppIDs[i]);

                        productDetail.AddDLC(DLCListing.Product);

                        UpdateListing(DLCListing);
                    }
                    else
                    {
                        productDetail.AddDLC(DLCListing.Product);
                    }
                }
            }

            if (!appData["movies"].IsNullOrEmpty())
            {
                JArray movies = (JArray)appData["movies"];

                for (int i = 0; i < movies.Count; i++)
                {
                    AppMovie temp = new AppMovie();

                    temp.Highlight = (!movies[i]["highlight"].IsNullOrEmpty()) ? false : (bool)movies[i]["highlight"];
                    temp.LargeMovieURL = (string)movies[i]["webm"]["max"] ?? "";
                    temp.Name = (string)movies[i]["name"] ?? "";
                    temp.SmallMovieURL = (string)movies[i]["webm"]["480"] ?? "";
                    temp.ThumbnailURL = (string)movies[i]["thumbnail"] ?? "";

                    productDetail.AddAppMovie(temp);
                }
            }

            if (!appData["screenshots"].IsNullOrEmpty())
            {
                JArray screenshots = (JArray)appData["screenshots"];

                for (int i = 0; i < screenshots.Count; i++)
                {
                    AppScreenshot temp = new AppScreenshot();

                    temp.FullSizeURL = (string)screenshots[i]["path_full"] ?? "";
                    temp.ThumbnailURL = (string)screenshots[i]["path_thumbnail"] ?? "";

                    productDetail.AddAppScreenshot(temp);
                }
            }

            if (!appData["categories"].IsNullOrEmpty())
            {
                JArray jCategories = (JArray)appData["categories"];
                List<string> categoriesList = new List<string>();

                for (int i = 0; i < jCategories.Count; i++)
                {
                    categoriesList.Add((string)jCategories[i]["description"]);
                }

                string[] categories = categoriesList.ToArray();

                if (categories != null)
                {
                    for (int i = 0; i < categories.Count(); i++)
                    {
                        if (GetProductCategoryByName(categories[i]) == null)
                        {
                            ProductCategory category = new ProductCategory(categories[i]);
                            listing.Product.AddProductCategory(category);
                        }
                        else
                        {
                            listing.Product.AddProductCategory(GetProductCategoryByName(categories[i]));
                        }
                    }
                }
            }

            listing.Product.AddProductDetail(productDetail);

            if (String.IsNullOrEmpty(listing.Product.ProductName))
            {
                listing.Product.ProductName = productDetail.ProductName;
            }
            if (String.IsNullOrEmpty(listing.ListingName))
            {
                listing.ListingName = productDetail.ProductName;
            }
        }
예제 #12
0
        // --- Listing building logic
        public List<String> AddSteamProductKeys(Platform platform, string input)
        {
            List<String> addedKeys = new List<String>();

            input = input.Replace("\r\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]+)?$");
            //Regex ExistingSubKey = new Regex(@"^sub/([0-9]+)\t+([0-9]+)(\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());

                    gameName = match.Groups[3].Value;

                    if (String.IsNullOrEmpty(match.Groups[4].Value))
                    {
                        isGift = true;
                    }
                    else
                    {
                        key = match.Groups[4].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 = GetListingByAppID(appId, platform.PlatformName);
                }
                else if (subId != 0)
                {
                    listing = GetListingByAppID(subId, platform.PlatformName);
                }

                if (listing != null)
                {
                    listing.ListingPrice = price;
                    listing.AddProductKey(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.AddProductKey(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);
                    }

                    UpdateListing(listing);

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

                // test regex

                unitOfWork.Save();
            }

            return addedKeys;
        }
예제 #13
0
        public void UpdateListing(Listing listing)
        {
            if (listing.ListingID != 0)
            {
                listingRepository.UpdateListing(listing);
            }
            else
            {
                listingRepository.InsertListing(listing);
            }

            unitOfWork.Save();
        }
예제 #14
0
        public List<String> AddProductKeys(Platform platform, string input)
        {
            if (platform.PlatformName.ToLower().CompareTo("steam") == 0)
            {
                return AddSteamProductKeys(platform, input);
            }

            List<String> addedKeys = new List<String>();

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

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

            Regex NamePriceKey = new Regex("^([^\t]+)\t+([0-9]+)\t+([^\t]+)$");
            Regex NamePrice = new Regex("^([^\t]+)\t+([0-9]+)$");

            DateTime dateAdded = DateTime.Now;

            Match match;

            bool isGift = false;
            string key = "";
            string gameName = "";
            int price = 0;

            foreach (String line in lines)
            {
                price = 0;
                gameName = "";
                key = "";
                isGift = false;

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

                    gameName = match.Groups[1].Value;
                    price = Int32.Parse(match.Groups[2].ToString());
                    key = match.Groups[3].ToString();
                }
                else if (NamePrice.Match(line).Success)
                {
                    match = NamePrice.Match(line);

                    gameName = match.Groups[1].Value;
                    price = Int32.Parse(match.Groups[2].ToString());
                    isGift = true;
                }

                Listing listing;

                listing = listingRepository.GetListings().Where(l => l.ContainsPlatform(platform) && object.Equals(l.Product.ProductName, gameName)).SingleOrDefault();

                if (listing != null)
                {
                    listing.ListingPrice = price;
                    listing.AddProductKey(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.AddProductKey(new ProductKey(isGift, key));

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

                    listing.AddProduct(product);

                    listingRepository.InsertListing(listing);

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

            return addedKeys;
        }
예제 #15
0
        public void InsertListing(Listing listing)
        {
            context.Listings.Add(listing);

            if (listing.Product != null)
            {
                if (listing.Product.ProductID == 0)
                {
                    InsertProduct(listing.Product);
                }
                else
                {
                    UpdateProduct(listing.Product);
                }
            }

            if (listing.DiscountedListings != null)
            {
                foreach (DiscountedListing entry in listing.DiscountedListings)
                {
                    if (entry.DiscountedListingID == 0)
                    {
                        InsertDiscountedListing(entry);
                    }
                    else
                    {
                        UpdateDiscountedListing(entry);
                    }
                }
            }

            if (listing.ProductKeys != null)
            {
                foreach (ProductKey entry in listing.ProductKeys)
                {
                    if (entry.ProductKeyID == 0)
                    {
                        InsertProductKey(entry);
                    }
                    else
                    {
                        UpdateProductKey(entry);
                    }
                }
            }

            if (listing.ListingComments != null)
            {
                foreach (ListingComment entry in listing.ListingComments)
                {
                    if (entry.ListingCommentID == 0)
                    {
                        InsertListingComment(entry);
                    }
                    else
                    {
                        UpdateListingComment(entry);
                    }
                }
            }
        }
예제 #16
0
        public void AddListingBlacklistEntry(Listing listing)
        {
            if (BlacklistedListings == null)
            {
                BlacklistedListings = new HashSet<Listing>();
            }

            if (listing.UsersBlacklist == null)
            {
                listing.UsersBlacklist = new HashSet<AppUser>();
            }

            BlacklistedListings.Add(listing);
            listing.UsersBlacklist.Add(this);
        }
예제 #17
0
        public void UpdateListing(Listing listing)
        {
            Listing targetListing = context.Listings.Find(listing.ListingID);

            if (targetListing != null)
            {
                targetListing.ListingName = listing.ListingName;
                targetListing.ListingPrice = listing.ListingPrice;
                targetListing.Quantity = listing.Quantity;
                targetListing.DateEdited = listing.DateEdited;
            }

            if (listing.Product != null)
            {
                if (listing.Product.ProductID == 0)
                {
                    InsertProduct(listing.Product);
                }
                else
                {
                    UpdateProduct(listing.Product);
                }
            }

            if (listing.DiscountedListings != null)
            {
                foreach (DiscountedListing entry in listing.DiscountedListings)
                {
                    if (entry.DiscountedListingID == 0)
                    {
                        InsertDiscountedListing(entry);
                    }
                    else
                    {
                        UpdateDiscountedListing(entry);
                    }
                }
            }

            if (listing.ProductKeys != null)
            {
                foreach (ProductKey entry in listing.ProductKeys)
                {
                    if (entry.ProductKeyID == 0)
                    {
                        InsertProductKey(entry);
                    }
                    else
                    {
                        UpdateProductKey(entry);
                    }
                }
            }

            if (listing.ListingComments != null)
            {
                foreach (ListingComment entry in listing.ListingComments)
                {
                    if (entry.ListingCommentID == 0)
                    {
                        InsertListingComment(entry);
                    }
                    else
                    {
                        UpdateListingComment(entry);
                    }
                }
            }
        }
예제 #18
0
 public void AddListing(Listing listing)
 {
     listingRepository.InsertListing(listing);
     unitOfWork.Save();
 }