コード例 #1
0
        private List <CseProductInfo> ParseShoppingProducts(int cse, string source, DataTable products, DataTable productMerchants)
        {
            if (products == null || products.Rows.Count == 0)
            {
                return(null);
            }

            var productsList = new List <CseProductInfo>();

            for (int i = 0; i < products.Rows.Count; i++)
            {
                var product = new CseProductInfo();

                product.ShoppingEngine = cse;
                product.Source         = source;
                product.ProductId      = products.Rows[i]["PID"] as string;
                product.CategoryId     = products.Rows[i]["categoryID"] as string;
                product.Name           = products.Rows[i]["name"] != DBNull.Value ? ((string)products.Rows[i]["name"]).ToLower() : null;
                product.DisplayName    = products.Rows[i]["name"] as string;
                product.Description    = products.Rows[i]["fullDescription"] as string;
                product.Image          = products.Rows[i]["image"] as string;

                product.Offers = new List <CseOfferInfo>();

                if (productMerchants == null || productMerchants.Rows.Count == 0)
                {
                    continue;
                }

                var rows = productMerchants.Select("PID = '" + product.ProductId + "'");

                if (rows.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < rows.Length; x++)
                {
                    var offer = new CseOfferInfo();

                    offer.Url        = rows[x]["offerUrl"] as string;
                    offer.Price      = double.Parse((string)rows[x]["basePrice"]);
                    offer.Brand      = rows[x]["brand"] != DBNull.Value ? (string)rows[x]["brand"] : null;
                    offer.Sku        = rows[x]["sku"] != DBNull.Value ? (string)rows[x]["sku"] : null;
                    offer.Model      = rows[x]["model"] != DBNull.Value ? (string)rows[x]["model"] : null;
                    offer.MerchantId = rows[x]["mid"] != DBNull.Value ? (string)rows[x]["mid"] : null;
                    offer.Cpc        = rows[x]["cpc"] != DBNull.Value ? double.Parse((string)rows[x]["cpc"]) : 0;

                    product.Offers.Add(offer);
                }

                product.Offers   = product.Offers.OrderBy(x => x.Price).ToList();
                product.MinPrice = product.Offers[0].Price;
                product.MaxPrice = product.Offers[product.Offers.Count - 1].Price;

                productsList.Add(product);
            }

            return(productsList);
        }
コード例 #2
0
        private List <CseProductInfo> ParseShopZillaProducts(string source, DataTable products, DataTable productMerchants)
        {
            if (products == null || products.Rows.Count == 0)
            {
                return(null);
            }

            var productsList = new List <CseProductInfo>();

            for (int i = 0; i < products.Rows.Count; i++)
            {
                var product = new CseProductInfo();

                product.ShoppingEngine = 2;
                product.Source         = source;
                product.ProductId      = products.Rows[i]["pid"] as string;
                product.CategoryId     = products.Rows[i]["category_id"] as string;
                product.Name           = ((string)products.Rows[i]["name"]).ToLower();
                product.DisplayName    = products.Rows[i]["name"] as string;
                product.Image          = products.Rows[i]["imageURL_small"] as string;
                product.Description    = products.Rows[i]["long_Desc"] != DBNull.Value ? (string)products.Rows[i]["long_Desc"] : null;

                product.Offers = new List <CseOfferInfo>();

                if (productMerchants == null || productMerchants.Rows.Count == 0)
                {
                    continue;
                }

                var rows = productMerchants.Select("mPID = '" + product.ProductId + "'");

                if (rows.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < rows.Length; x++)
                {
                    var offer = new CseOfferInfo();

                    offer.Url        = rows[x]["URL"] as string;
                    offer.Price      = (double)rows[x]["price"];
                    offer.MerchantId = rows[x]["mid"] != DBNull.Value ? (string)rows[x]["mid"] : null;

                    product.Offers.Add(offer);
                }

                product.Offers   = product.Offers.OrderBy(x => x.Price).ToList();
                product.MinPrice = product.Offers[0].Price;
                product.MaxPrice = product.Offers[product.Offers.Count - 1].Price;

                productsList.Add(product);
            }

            return(productsList);
        }
コード例 #3
0
        private List <CseProductInfo> ParseAffiliateWindowProducts(string source, DataTable products, DataTable productMerchants)
        {
            if (products == null || products.Rows.Count == 0)
            {
                return(null);
            }

            var productsList = new List <CseProductInfo>();

            for (int i = 0; i < products.Rows.Count; i++)
            {
                var product = new CseProductInfo();

                product.ShoppingEngine = 6;
                product.Source         = source;
                product.ProductId      = products.Rows[i]["pid"] as string;
                product.Name           = ((string)products.Rows[i]["name"]).ToLower();
                product.DisplayName    = products.Rows[i]["name"] as string;
                product.Image          = (string)productMerchants.Select("iId = '" + product.ProductId + "'")[0]["sAwThumbUrl"];
                product.Description    = products.Rows[i]["short_Desc"] != DBNull.Value ? (string)products.Rows[i]["short_Desc"] : null;

                product.Offers = new List <CseOfferInfo>();

                if (productMerchants == null || productMerchants.Rows.Count == 0)
                {
                    continue;
                }

                var rows = productMerchants.Select("iId = '" + product.ProductId + "'");

                if (rows.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < rows.Length; x++)
                {
                    var offer = new CseOfferInfo();

                    offer.Url        = rows[x]["sAwDeepLink"] as string;
                    offer.Price      = (double)(float)rows[x]["fPrice"];
                    offer.MerchantId = rows[x]["iMerchantId"] != DBNull.Value ? ((int)rows[x]["iMerchantId"]).ToString() : null;

                    product.Offers.Add(offer);
                }

                product.Offers   = product.Offers.OrderBy(x => x.Price).ToList();
                product.MinPrice = product.Offers[0].Price;
                product.MaxPrice = product.Offers[product.Offers.Count - 1].Price;

                productsList.Add(product);
            }

            return(productsList);
        }
コード例 #4
0
        public CseProductInfo InsertProduct(CseProductInfo product)
        {
            var dataBase   = _server.ServerConnection.GetDatabase(string.Format("cse_caching_{0}", product.ShoppingEngine));
            var collection = dataBase.GetCollection <CseProductInfo>(PRODUCTS_COLLECTION);

            product.DateCreated  = DateTime.Now;
            product.DateModified = DateTime.Now;

            collection.Insert(product, new MongoInsertOptions()
            {
                SafeMode = SafeMode.False
            });

            return(product);
        }
コード例 #5
0
        public void UpdateProduct(CseProductInfo product)
        {
            var dataBase   = _server.ServerConnection.GetDatabase(string.Format("cse_caching_{0}", product.ShoppingEngine));
            var collection = dataBase.GetCollection <CseProductInfo>(PRODUCTS_COLLECTION);

            var updateBuilder = new UpdateBuilder();

            if (product.Name != null)
            {
                updateBuilder.Set("name", product.Name);
            }
            if (product.DisplayName != null)
            {
                updateBuilder.Set("display_name", product.DisplayName);
            }
            if (product.Description != null)
            {
                updateBuilder.Set("description", product.Description);
            }
            if (product.CategoryId != null)
            {
                updateBuilder.Set("category_id", product.CategoryId);
            }
            if (product.CategoryId != null)
            {
                updateBuilder.Set("category", product.CategoryId);
            }
            if (product.Source != null)
            {
                updateBuilder.Set("source", product.Source);
            }
            if (product.Image != null)
            {
                updateBuilder.Set("image", product.Image);
            }
            if (product.Offers != null)
            {
                updateBuilder.SetWrapped("offers", product.Offers);
            }

            updateBuilder.Set("min_price", product.MinPrice);
            updateBuilder.Set("max_price", product.MaxPrice);
            updateBuilder.Set("shopping_engine", product.ShoppingEngine);
            updateBuilder.Set("date_modified", DateTime.Now);

            collection.Update(Query.EQ("product_id", product.ProductId), updateBuilder);
        }
コード例 #6
0
        private List <CseProductInfo> GetProductsFromPcmAction(CsePcmInfo pcmInfo, string op)
        {
            var matches         = pcmInfo.Matches;
            var cseDataProvider = new CseToMongoEtlProvider();
            var products        = new List <CseProductInfo>();

            foreach (var match in matches)
            {
                foreach (var pid in match.Pids)
                {
                    CseProductInfo product = null;

                    if (match.Cse == 9 || match.Cse == 10)
                    {
                        product = cseDataProvider.GetProduct(match.Cse, op + "_" + pid);
                    }
                    else
                    {
                        product = cseDataProvider.GetProduct(match.Cse, pid);
                    }

                    if (product == null)
                    {
                        return(new List <CseProductInfo>());
                    }

                    foreach (var offer in product.Offers)
                    {
                        offer.MerchantInfo = cseDataProvider.GetMerchant(match.Cse, offer.MerchantId);
                    }

                    products.Add(product);
                }

                _context.AddCseOptimizationMapping(match.Cse.ToString(), match.ModifiedBy);
            }

            return(products);
        }