private List <string> GetDomainTriggersAndCountry(DealFinderContext context)
        {
            var timer     = new TimerProvider(context, "get-domain-triggers");
            var dataTable = CseToMongoEtlProvider.GetDataTable("sp_Get_DomainTrigger",

                                                               new Dictionary <string, object>
            {
                { "Domain", context.DomainName }
            },
                                                               "SQLCacheConnectionString", 60);

            timer.StopTimer();

            timer = new TimerProvider(context, "domain-triggers-match-time");

            var domainTriggers = new List <string>();

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                domainTriggers.Add((string)dataTable.Rows[i][0]);
                context.Country = dataTable.Rows[i][1] == DBNull.Value ? "US" : (string)dataTable.Rows[i][1];
            }

            timer.StopTimer();

            return(domainTriggers);
        }
        private dynamic GetProductsByUrlOrKeywordAction(DealFinderContext context)
        {
            dynamic result = null;

            var timer = new TimerProvider(context, "get-url-mapping-data");

            var urlMappingProvider = new UrlMappingProvider();
            var urlMapping         = urlMappingProvider.GetUrlMappingData(context.Url);

            timer.StopTimer();

            if (urlMapping != null && urlMapping.data != null)
            {
                context.ProductName      = urlMapping.data.pagetype == "search" ? urlMapping.data.keyword : null;
                context.PageType         = urlMapping.data.pagetype == "search" ? "search" : "product";
                context.IsDefaultPrice   = urlMapping.data.pagetype == "search" ? true : false;
                context.CachedValue      = urlMapping.data.pagetype == "search" ? context.ProductName : null;
                context.SearchDomainName = urlMapping.data.pagetype == "search" ? string.Format("ac.search.{0}", context.Country.ToLower()) : null;
            }

            if (context.ProductName == null)
            {
                result = GetProductsByUrlAction(context);
            }
            else
            {
                result = GetProductsByKeywordAction(context);
            }

            return(result);
        }
Beispiel #3
0
        private MatchingData GetProtuctsFromCseByKeyword(short api)
        {
            string encodedKeyword = HttpUtility.UrlEncode(_keyword);

            var timer      = new TimerProvider(_context, string.Format("get-data-from-cse-[{0}]-api", api));
            var cseMatcher = new CseMatcher(api);
            var cseResult  = cseMatcher.SearchKeyword(_context.Op.ToString(), _context.DomainName, encodedKeyword, 100);

            timer.StopTimer();

            return(cseResult);
        }
        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);
        }
        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);
        }
Beispiel #6
0
        private List <CseProductInfo> GetProductsFromCseAction(int minNumberOfOffers)
        {
            var timer = new TimerProvider(_context, "get-campaign-apis-sql");
            var apis  = GetCseApisAndCurrencyForCurrentCampaignId();

            timer.StopTimer();

            if (apis.Count == 0)
            {
                return(new List <CseProductInfo>());
            }

            var cseDataProvider = new CseToMongoEtlProvider();

            var productsList    = new List <CseProductInfo>();
            var rawProductsList = new List <CseProductInfo>();
            var merchantsList   = new List <CseMerchantInfo>();

            int totalNumberOfOffers = 0;

            while (true)
            {
                for (int i = 0; i < apis.Count; i++)
                {
                    MatchingData matchingData = null;

                    try
                    {
                        matchingData = GetProtuctsFromCseByKeyword(apis[i]);

                        if (matchingData == null)
                        {
                            matchingData = new MatchingData();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorFormat("failed get data from cse [{0}], ex: [{1}]", apis[i], ex.Message);
                        _context.AddCseExecutionFailure(apis[i].ToString(), "Failed");
                    }

                    _context.AddCseNumberOfRawResults(apis[i].ToString(), matchingData.Matches.Count.ToString());

                    if (matchingData.Matches.Count == 0)
                    {
                        continue;
                    }

                    _context.AddCseExecutionFailure(apis[i].ToString(), "OK");

                    List <CseProductInfo>  products  = null;
                    List <CseMerchantInfo> merchants = null;

                    cseDataProvider.ParseProductAndMerchants(apis[i], "widget", matchingData.ds, out products, out merchants);

                    if (products.Count == 0)
                    {
                        continue;
                    }

                    merchantsList.AddRange(merchants.Select(x => (CseMerchantInfo)x.Clone()));
                    rawProductsList.AddRange(products.Select(x => (CseProductInfo)x.Clone()));

                    var filterProvider = new FilterProvider(_context);

                    products = filterProvider.FilterSameStore(products);
                    products = filterProvider.FilterPriceRange(products);

                    if (products.Count == 0)
                    {
                        continue;
                    }

                    productsList.AddRange(products);

                    productsList = filterProvider.FilterDuplicateStores(productsList);
                    productsList = filterProvider.FilterDuplicateProductId(productsList);

                    if (productsList.Count == 0)
                    {
                        continue;
                    }

                    totalNumberOfOffers = CountProdcutOffers(productsList);

                    if (totalNumberOfOffers >= minNumberOfOffers)
                    {
                        break;
                    }
                }

                totalNumberOfOffers = CountProdcutOffers(productsList);

                if (totalNumberOfOffers >= minNumberOfOffers)
                {
                    break;
                }

                if (!_context.IsDefaultPrice)
                {
                    var filterProvider = new FilterProvider(_context);

                    rawProductsList = filterProvider.FilterDuplicateStores(rawProductsList);
                    rawProductsList = filterProvider.FilterDuplicateProductId(rawProductsList);

                    totalNumberOfOffers = CountProdcutOffers(rawProductsList);

                    if (totalNumberOfOffers >= minNumberOfOffers)
                    {
                        productsList = rawProductsList;
                        break;
                    }
                }

                if (!ShrinkKeywordStart())
                {
                    break;
                }
            }

            ThreadPool.QueueUserWorkItem(state =>
            {
                dynamic param = state as dynamic;

                cseDataProvider.AddCseResultToMongoDb("widget", _context.Op, param.products, param.merchants, false);
            }, new
            {
                products  = new List <CseProductInfo>(rawProductsList.Select(x => (CseProductInfo)x.Clone())),
                merchants = new List <CseMerchantInfo>(merchantsList.Select(x => (CseMerchantInfo)x.Clone()))
            });

            return(productsList);
        }