private dynamic GetProductsByKeywordAction(DealFinderContext context) { var appCachedValue = string.Format("GetProductsByKeyword:{0}:{1}", context.Url, context.CampaignId); var products = new List <CseProductInfo>(); var pcmInfo = new CsePcmInfo(); if (MemoryCache.Default.Get(appCachedValue) == null || context.QaMode == true) { products = RetrieveProducts(context, out pcmInfo); dynamic cacheObject = new { products = products, pcm = pcmInfo }; MemoryCache.Default.Add(appCachedValue, cacheObject, DateTimeOffset.Now.AddHours(4)); } else { context.Status = 1; var cacheOject = (dynamic)MemoryCache.Default[appCachedValue]; products = cacheOject.products; pcmInfo = cacheOject.pcm; } context.Currency = pcmInfo.Currency; var result = GetResult(context, pcmInfo, products); return(result); }
public void DeleteProduct(CsePcmInfo product) { var dataBase = _server.ServerConnection.GetDatabase(PCM_DB); var collection = dataBase.GetCollection <CseProductInfo>(PCM_COLLECTION); collection.Remove(Query.And(Query.EQ("sku", product.Sku), Query.EQ("domain", product.Domain))); }
public dynamic GetProductsByUrl(string url, string campaignId, dynamic cookies, bool qaMode) { var context = new DealFinderContext(HttpContext.Current) { Url = HttpUtility.UrlDecode(url), DomainName = GetDomainName(HttpUtility.UrlDecode(url)), CampaignId = campaignId, QaMode = qaMode, NewUserId = cookies.userId == "" ? Guid.NewGuid().ToString() : cookies.userId, NewImpressionId = Guid.NewGuid().ToString(), }; context.UserId = context.NewUserId; context.ImpressionId = context.NewImpressionId; dynamic result = null; try { result = GetProductsByUrlOrKeywordAction(context); } catch (Exception ex) { context.Status = 3; var pcmInfo = new CsePcmInfo(); var products = new List <CseProductInfo>(); result = GetResult(context, pcmInfo, products); } result = LogResult(context, result); return(result); }
private dynamic GetProductsByTriggerAction(DealFinderContext context) { var domainTriggers = GetDomainTriggersAndCountry(context); bool hasMatch = CheckIfCurrentDomainHasMatchForCurrentUrl(context, domainTriggers); var retargetingProvider = new RetargetingProvider(context); var retargetingInfo = retargetingProvider.GetRetargetingInfo(); var retargetingSettings = retargetingProvider.GetRtSettings(); bool isEcommerceDomain = retargetingProvider.IsEcommerceDomain(); context.IsRetargetingEnabled = retargetingSettings.is_active; context.IsEcommerceDomain = isEcommerceDomain; context.EcommerceRecency = retargetingSettings.e_com_rec.ToString() + " Minutes"; context.NonEcommerceRecency = retargetingSettings.non_e_com_rec.ToString() + " Minutes"; context.NonEcommerceFrequency = retargetingSettings.freq.ToString(); dynamic result = null; if (hasMatch) { result = GetProductsByUrlOrKeywordAction(context); int stackCount = 0; var stack = retargetingProvider.UpdateProductIdsStack(context.RtStack, (string)result.product_id, out stackCount); result.rt_stack = stack; result.rt_pointer = (stackCount - 1).ToString(); result.rt_last_shown = DateTime.Now.Ticks.ToString(); } else { context.Status = -1; context.PageType = "No Trigger"; context.IsDomainInDataBase = GetDomainCache(context.DomainName).Length > 0; if (retargetingInfo == null) { var pcmInfo = new CsePcmInfo(); var products = new List <CseProductInfo>(); result = GetResult(context, pcmInfo, products); } else { context.IsRetargetingResult = true; context.PageType = isEcommerceDomain ? "Retargeting eCom" : "Retargeting non eCom"; result = GetProductsByPcmIdAction(context, (ObjectId)retargetingInfo.product_id); result.rt_pointer = retargetingInfo.pointer; result.rt_show_count = retargetingInfo.show_count.ToString(); result.rt_last_shown = DateTime.Now.Ticks.ToString(); } } return(result); }
public dynamic GetProductsByTrigger(string url, string campaignId, string sid, dynamic cookies, bool qaMode) { var context = new DealFinderContext(HttpContext.Current) { Url = HttpUtility.UrlDecode(url), DomainName = GetDomainName(HttpUtility.UrlDecode(url)), CampaignId = campaignId, QaMode = qaMode, RtPointer = cookies.rtPointer, RtLastShown = cookies.rtLastShown, RtShowCount = cookies.rtShowCount, RtStack = cookies.rtStack, NewUserId = cookies.userId == "" ? Guid.NewGuid().ToString() : cookies.userId, NewImpressionId = Guid.NewGuid().ToString(), CookiesEnabled = cookies.cookiesEnabled, Sid = sid, Nid = campaignId, Op = GetOP(campaignId, sid, campaignId) }; var timer = new TimerProvider(context, "global-server-time"); context.UserId = context.NewUserId; context.ImpressionId = context.NewImpressionId; dynamic result = null; try { result = GetProductsByTriggerAction(context); } catch (Exception ex) { context.Status = 3; var pcmInfo = new CsePcmInfo(); var products = new List <CseProductInfo>(); result = GetResult(context, pcmInfo, products); } result = LogResult(context, result); AddDebugParameters(context); timer.StopTimer(); return(result); }
public CsePcmInfo InsertProduct(CsePcmInfo product) { var dataBase = _server.ServerConnection.GetDatabase(PCM_DB); var collection = dataBase.GetCollection <CseProductInfo>(PCM_COLLECTION); product.DateCreated = DateTime.Now; product.DateModified = DateTime.Now; collection.Insert(product, new MongoInsertOptions() { SafeMode = SafeMode.False }); return(product); }
public void UpsertPcm(CsePcmInfo product) { if (product == null) { return; } var result = GetProduct(product.Domain, product.Sku, "_id"); if (result == null) { InsertProduct(product); } else { UpdateProduct(product); } }
private dynamic GetProductsByPcmIdAction(DealFinderContext context, ObjectId pcmId) { var appCachedValue = string.Format("GetProductsByPcmId:{0}", pcmId); var products = new List <CseProductInfo>(); var pcmInfo = new CsePcmInfo(); context.Status = 1; if (MemoryCache.Default.Get(appCachedValue) == null || context.QaMode == true) { var pcmProvider = new PcmProvider(context); pcmInfo = pcmProvider.GetProductFromPcmById(pcmId); context.IsExistInPcm = true; context.ProductName = pcmInfo.ProductName; context.Price = pcmInfo.Price; context.IsDefaultPrice = pcmInfo.IsDefaultPrice; var productsProvider = new ProductsProvider(context); products = productsProvider.GetProductsFromPcm(pcmInfo); dynamic cacheObject = new { products = products, pcm = pcmInfo }; MemoryCache.Default.Add(appCachedValue, cacheObject, DateTimeOffset.Now.AddHours(4)); } else { var cacheOject = (dynamic)MemoryCache.Default[appCachedValue]; products = cacheOject.products; pcmInfo = cacheOject.pcm; } context.Currency = pcmInfo.Currency; var result = GetResult(context, pcmInfo, products); return(result); }
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); }
public List <CseProductInfo> GetProductsFromPcm(CsePcmInfo pcmInfo) { var products = GetProductsFromPcmAction(pcmInfo, _context.Op); if (products.Count == 0) { products = GetProductsFromCseAction(1); var pcmProvider = new PcmProvider(_context); pcmProvider.UpsertProductToPcm(products); return(products); } var filterProvider = new FilterProvider(_context); products = filterProvider.FilterSameStore(products); products = filterProvider.FilterPriceRange(products); products = filterProvider.FilterDuplicateStores(products); products = filterProvider.FilterDuplicateProductId(products); return(products); }
private CsePcmInfo UpsertProductToPcmAction(List <CseProductInfo> products) { var pcmInfo = new CsePcmInfo(); pcmInfo.DomainPriceRule = _context.DomainPriceRule; pcmInfo.PageType = _context.PageType; pcmInfo.Domain = _context.PageType == "search" ? _context.SearchDomainName : _context.DomainName; pcmInfo.Sku = _context.CachedValue; pcmInfo.Isbn = _context.Isbn; pcmInfo.Upc = _context.Upc; pcmInfo.IsDefaultPrice = _context.IsDefaultPrice; pcmInfo.Price = _context.Price; pcmInfo.ProductDisplayName = _context.ProductName; pcmInfo.ProductName = _context.ProductName.ToLower(); pcmInfo.ProductUrl = _context.Url; pcmInfo.Currency = _context.Currency; pcmInfo.Status = 1; pcmInfo.Matches = new List <CseMatchInfo>(); var matchGroup2 = products.Where(x => x.ShoppingEngine == 2).ToList(); if (matchGroup2.Count > 0) { pcmInfo.Matches.Add(ExtractMatchInfoFromProducts(matchGroup2)); } var matchGroup3 = products.Where(x => x.ShoppingEngine == 3).ToList(); if (matchGroup3.Count > 0) { pcmInfo.Matches.Add(ExtractMatchInfoFromProducts(matchGroup3)); } var matchGroup4 = products.Where(x => x.ShoppingEngine == 4).ToList(); if (matchGroup4.Count > 0) { pcmInfo.Matches.Add(ExtractMatchInfoFromProducts(matchGroup4)); } var matchGroup6 = products.Where(x => x.ShoppingEngine == 6).ToList(); if (matchGroup6.Count > 0) { pcmInfo.Matches.Add(ExtractMatchInfoFromProducts(matchGroup6)); } var matchGroup9 = products.Where(x => x.ShoppingEngine == 9).ToList(); if (matchGroup9.Count > 0) { pcmInfo.Matches.Add(ExtractMatchInfoFromProducts(matchGroup9)); } var matchGroup10 = products.Where(x => x.ShoppingEngine == 10).ToList(); if (matchGroup10.Count > 0) { pcmInfo.Matches.Add(ExtractMatchInfoFromProducts(matchGroup10)); } var timerStart = DateTime.Now; if (pcmInfo.Matches != null && pcmInfo.Matches.Count > 0) { _pcmDataProvider.UpsertPcm(pcmInfo); } var opTime = DateTime.Now - timerStart; return(pcmInfo); }
public void UpdateProduct(CsePcmInfo product) { var dataBase = _server.ServerConnection.GetDatabase(PCM_DB); var collection = dataBase.GetCollection <CseProductInfo>(PCM_COLLECTION); var updateBuilder = new UpdateBuilder(); if (product.Brand != null) { updateBuilder.Set("brand", product.Brand); } if (product.BrandOrigin != null) { updateBuilder.Set("brand_origin", product.BrandOrigin); } if (product.ImageUrl != null) { updateBuilder.Set("image_url", product.ImageUrl); } if (product.Isbn != null) { updateBuilder.Set("isbn", product.Isbn); } if (product.Mpn != null) { updateBuilder.Set("mpn", product.Mpn); } if (product.MpnOrigin != null) { updateBuilder.Set("mpn_origin", product.MpnOrigin); } if (product.Matches != null) { updateBuilder.SetWrapped("matches", product.Matches); } if (product.ProductDisplayName != null) { updateBuilder.Set("product_display_name", product.ProductDisplayName); } if (product.ProductName != null) { updateBuilder.Set("product_name", product.ProductName); } if (product.Sku != null) { updateBuilder.Set("sku", product.Sku); } if (product.Upc != null) { updateBuilder.Set("upc", product.Upc); } if (product.Price != null) { updateBuilder.Set("price", product.Price); } if (product.ShippingPrice != null) { updateBuilder.Set("shipping_price", product.ShippingPrice); } if (product.Status != null) { updateBuilder.Set("status", product.Status); } if (product.DomainPriceRule != null) { updateBuilder.Set("domain_price_rule", product.DomainPriceRule); } updateBuilder.Set("date_modified", DateTime.Now); collection.Update(Query.And(Query.EQ("domain", product.Domain), Query.EQ("sku", product.Sku)), updateBuilder); }
private dynamic GetResult(DealFinderContext context, CsePcmInfo pcmInfo, List <CseProductInfo> products) { dynamic result = new ExpandoObject(); result.html_template = new MarketTemplateProvider().GetTemplate(); result.keyword = pcmInfo.ProductDisplayName; result.encoded_keyword = pcmInfo.ProductName; result.height = "90px"; result.more_deals_url = GetMoreDealsUrl(context, pcmInfo.ProductName); result.sku = context.CachedValue; result.product_id = pcmInfo.ObjectId.ToString(); result.rt_pointer = null; result.rt_stack = null; result.rt_show_count = null; result.rt_last_shown = null; result.price = pcmInfo.Price; result.debug = context.Debug; result.timers = context.Timers; result.user_id = context.NewUserId; result.impression_id = context.NewImpressionId; var resultProductList = new List <dynamic>(); foreach (var product in products) { foreach (var offer in product.Offers) { var productUrl = GenerateOuterClickUrl(offer.Url, context.PageType, 3, 3, 0, offer.Price.ToString(), offer.Price.ToString(), context.CachedValue, offer.Price.ToString(), offer.Price.ToString(), context, product.ShoppingEngine.ToString(), true); dynamic productResult = new ExpandoObject(); productResult.category = product.CategoryId; productResult.product_id = product.ProductId; productResult.product_name = product.Name.Length > 35 ? product.Name.Remove(35, product.Name.Length - 35) + "..." : product.Name; productResult.product_image = product.Image; productResult.product_url = productUrl; productResult.product_price_raw = offer.Price; productResult.product_price = string.Format("{0:0.00}", offer.Price); productResult.merchant_image = offer.MerchantInfo.UseLogo ? offer.MerchantInfo.Logo : ""; productResult.merchant_name = offer.MerchantInfo.Name; productResult.merchant_id = offer.MerchantInfo.MerchantId; productResult.country = context.Country; productResult.cse = product.ShoppingEngine; resultProductList.Add(productResult); } } context.TotalNumberOfOffersToDisplay = resultProductList.Count; var sortProvider = new SortProvider(context); if (context.PageType == "search") { resultProductList = sortProvider.RandomizeProducts(resultProductList, 3); } resultProductList = sortProvider.SortProducts(resultProductList); result.products = resultProductList.Take(3).ToList(); result.width = CalculateWidth(result.products); if (context.Status == 0 || context.Status == 1) { if (result.products.Count == 0) { context.Status = 2; } if (result.products.Count > 0 && result.products.Count < 3) { context.Status = 4; } } return(result); }
private List <CseProductInfo> RetrieveProducts(DealFinderContext context, out CsePcmInfo pcmInfo) { var timer = new TimerProvider(context, "extract-cache-value-and-domain"); var domains = GetDomainCache(context.DomainName); if (domains.Length > 0) { context.IsDomainInDataBase = true; } if (context.PageType == "product") { int priority = 0; context.CachedValue = GetCachedValue(domains, context.Url, context.DomainName, out priority); context.CachedValuePriority = priority == 0 ? "" : priority.ToString(); } timer.StopTimer(); var pcmProvider = new PcmProvider(context); pcmInfo = pcmProvider.GetProductFromPcmByCacheValueAndDomain(); var products = new List <CseProductInfo>(); if (pcmInfo == null) { if (context.PageType == "product") { timer = new TimerProvider(context, "get-site-data"); var getSiteDataProvider = new GetSiteDataProvider(context, true); var siteData = getSiteDataProvider.GetSiteData(); timer.StopTimer(); context.IsGetSiteDataExecuted = true; if (siteData == null) { context.IsGetSiteDataFailed = true; pcmInfo = new CsePcmInfo(); return(products); } } var productsProvider = new ProductsProvider(context); products = productsProvider.GetProductsFromCse(1); timer = new TimerProvider(context, "insert-product-to-pcm"); pcmInfo = pcmProvider.UpsertProductToPcm(products); timer.StopTimer(); } else { context.IsExistInPcm = true; context.Status = 1; context.ProductName = pcmInfo.ProductName; context.Price = pcmInfo.Price; context.IsDefaultPrice = pcmInfo.IsDefaultPrice; timer = new TimerProvider(context, "get-data-from-pcm"); var productsProvider = new ProductsProvider(context); products = productsProvider.GetProductsFromPcm(pcmInfo); timer.StopTimer(); } context.ProductName = pcmInfo.ProductDisplayName; context.Price = pcmInfo.Price; context.DomainPriceRule = pcmInfo.DomainPriceRule; return(products); }