Example #1
0
        /// <inheritdoc/>
        public int CompareTo(object obj)
        {
            PageVisit other = obj as PageVisit;

            if (this.UriStem.Equals(other.UriStem, StringComparison.InvariantCultureIgnoreCase) && this.UriQuery.Equals(other.UriQuery, StringComparison.InvariantCultureIgnoreCase))
            {
                return(0);
            }

            return(other.ActivityDate.CompareTo(this.ActivityDate));
        }
Example #2
0
        /// <summary>
        /// Registers the catalog page visit
        /// </summary>
        /// <param name="nodeId">ID of the catalog node</param>
        /// <param name="nodeType">Type of the catalog node</param>
        /// <param name="pageTitle">Title of the page</param>
        /// <remarks>This is intended for use with page tracking</remarks>
        public static void RegisterPageVisit(int nodeId, CatalogNodeType nodeType, string pageTitle)
        {
            //REGISTER THE PAGEVIEW FOR PERSISTENT PAGE TRACKING
            CommerceBuilder.Reporting.PageView.RegisterCatalogNode(nodeId, nodeType);

            HttpContext context  = HttpContext.Current;
            string      uriStem  = context.Request.Url.AbsolutePath;
            string      uriQuery = context.Request.Url.Query.TrimStart("?".ToCharArray());

            // CHECK IF ITS ALREADY IN LIST
            IList <PageVisit> pageVisits = GetUserPageVisits();
            PageVisit         pageVisit  = pageVisits.FirstOrDefault(p => (p.UriStem == uriStem && p.UriQuery == uriQuery));

            if (pageVisit != null)
            {
                pageVisit.ActivityDate = LocaleHelper.LocalNow;
                pageVisit.VisitCount++;
                pageVisits.Sort();
            }
            else
            {
                // ADD THE NEW PAGE VISIT
                pageVisit = new PageVisit();
                pageVisit.ActivityDate    = LocaleHelper.LocalNow;
                pageVisit.CatalogNodeId   = nodeId;
                pageVisit.CatalogNodeType = nodeType;
                pageVisit.PageTitle       = pageTitle;
                pageVisit.UriStem         = uriStem;
                pageVisit.UriQuery        = uriQuery;
                pageVisit.VisitCount      = 1;
                pageVisits.Sort();

                // ADD IT TO COLLECTION
                pageVisits.Add(pageVisit);

                // ENSURE MAXIMUM SIZE, REMOVE FROM END IF IT EXCEEDS THE SIZE
                if (pageVisits.Count > _cacheSize)
                {
                    for (int i = _cacheSize; i < pageVisits.Count; i++)
                    {
                        pageVisits.RemoveAt(i);
                    }
                }
            }
        }