/// <summary>
        /// Tracks current user
        /// </summary>
        public void TrackCurrentUser()
        {
            try
            {
                if (!this.Enabled ||
                    !InstallerHelper.ConnectionStringIsSet() ||
                    HttpContext.Current == null)
                    return;

                lock (s_lock)
                {
                    //getting current user info (OnlineUserInfo)
                    OnlineUserInfo oui = null;

                    //user list
                    Dictionary<Guid, OnlineUserInfo> userList = null;
                    if (NopContext.Current.User != null && !NopContext.Current.User.IsGuest)
                    {
                        //registered user
                        userList = GetRegisteredUserList();

                        //find user info
                        if (userList.ContainsKey(NopContext.Current.User.CustomerGuid))
                        {
                            oui = userList[NopContext.Current.User.CustomerGuid];
                        }

                        //create new user if existing one was not found
                        if (oui == null)
                        {
                            oui = new OnlineUserInfo();
                            oui.OnlineUserGuid = NopContext.Current.User.CustomerGuid;
                            oui.CreatedOn = DateTime.UtcNow;
                            userList.Add(oui.OnlineUserGuid, oui);
                        }

                        //update other properties
                        oui.LastVisit = DateTime.UtcNow;
                        oui.LastPageVisited = CommonHelper.GetThisPageUrl(true);
                        oui.IPAddress = NopContext.Current.UserHostAddress;
                        oui.AssociatedCustomerId = NopContext.Current.User.CustomerId;
                        HttpContext.Current.Response.Cookies.Remove(TRACKINGCOOKIENAME);
                    }
                    else
                    {
                        //guest
                        userList = GetAnonymousUserList();

                        //find user info
                        string cookieValue = string.Empty;
                        if ((HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME] != null) && (HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME].Value != null))
                        {
                            cookieValue = HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME].Value;
                        }
                        if (!string.IsNullOrEmpty(cookieValue))
                        {
                            Guid onlineUserGuid = Guid.Empty;
                            Guid.TryParse(cookieValue, out onlineUserGuid);
                            if (onlineUserGuid != Guid.Empty)
                            {
                                if (userList.ContainsKey(onlineUserGuid))
                                {
                                    oui = userList[onlineUserGuid];
                                }
                            }
                        }

                        //create new user if existing one was not found
                        if (oui == null)
                        {
                            oui = new OnlineUserInfo();
                            oui.OnlineUserGuid = Guid.NewGuid();
                            oui.CreatedOn = DateTime.UtcNow;
                            userList.Add(oui.OnlineUserGuid, oui);
                        }

                        //update other properties
                        oui.LastVisit = DateTime.UtcNow;
                        oui.LastPageVisited = CommonHelper.GetThisPageUrl(true);
                        oui.IPAddress = NopContext.Current.UserHostAddress;
                        oui.AssociatedCustomerId = null;

                        //save new cookie
                        HttpCookie cookie = new HttpCookie(TRACKINGCOOKIENAME);
                        cookie.Value = oui.OnlineUserGuid.ToString();
                        cookie.Expires = DateTime.Now.AddHours(1);
                        HttpContext.Current.Response.Cookies.Remove(TRACKINGCOOKIENAME);
                        HttpContext.Current.Response.Cookies.Add(cookie);
                    }

                    //maximum online customers
                    int currentVisitors = GetAnonymousUserList().Count() + GetRegisteredUserList().Count();
                    if (currentVisitors > this.MaximumOnlineCustomers)
                    {
                        this.MaximumOnlineCustomers = currentVisitors;
                    }
                }
            }
            catch (NopException exc)
            {
                Debug.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Tracks current user
        /// </summary>
        public void TrackCurrentUser()
        {
            try
            {
                if (!this.Enabled ||
                    !InstallerHelper.ConnectionStringIsSet() ||
                    HttpContext.Current == null)
                {
                    return;
                }

                lock (s_lock)
                {
                    //getting current user info (OnlineUserInfo)
                    OnlineUserInfo oui = null;

                    //user list
                    Dictionary <Guid, OnlineUserInfo> userList = null;
                    if (NopContext.Current.User != null && !NopContext.Current.User.IsGuest)
                    {
                        //registered user
                        userList = GetRegisteredUserList();

                        //find user info
                        if (userList.ContainsKey(NopContext.Current.User.CustomerGuid))
                        {
                            oui = userList[NopContext.Current.User.CustomerGuid];
                        }

                        //create new user if existing one was not found
                        if (oui == null)
                        {
                            oui = new OnlineUserInfo();
                            oui.OnlineUserGuid = NopContext.Current.User.CustomerGuid;
                            oui.CreatedOn      = DateTime.UtcNow;
                            userList.Add(oui.OnlineUserGuid, oui);
                        }

                        //update other properties
                        oui.LastVisit            = DateTime.UtcNow;
                        oui.LastPageVisited      = CommonHelper.GetThisPageUrl(true);
                        oui.IPAddress            = NopContext.Current.UserHostAddress;
                        oui.AssociatedCustomerId = NopContext.Current.User.CustomerId;
                        HttpContext.Current.Response.Cookies.Remove(TRACKINGCOOKIENAME);
                    }
                    else
                    {
                        //guest
                        userList = GetAnonymousUserList();

                        //find user info
                        string cookieValue = string.Empty;
                        if ((HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME] != null) && (HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME].Value != null))
                        {
                            cookieValue = HttpContext.Current.Request.Cookies[TRACKINGCOOKIENAME].Value;
                        }
                        if (!string.IsNullOrEmpty(cookieValue))
                        {
                            Guid onlineUserGuid = Guid.Empty;
                            Guid.TryParse(cookieValue, out onlineUserGuid);
                            if (onlineUserGuid != Guid.Empty)
                            {
                                if (userList.ContainsKey(onlineUserGuid))
                                {
                                    oui = userList[onlineUserGuid];
                                }
                            }
                        }

                        //create new user if existing one was not found
                        if (oui == null)
                        {
                            oui = new OnlineUserInfo();
                            oui.OnlineUserGuid = Guid.NewGuid();
                            oui.CreatedOn      = DateTime.UtcNow;
                            userList.Add(oui.OnlineUserGuid, oui);
                        }

                        //update other properties
                        oui.LastVisit            = DateTime.UtcNow;
                        oui.LastPageVisited      = CommonHelper.GetThisPageUrl(true);
                        oui.IPAddress            = NopContext.Current.UserHostAddress;
                        oui.AssociatedCustomerId = null;

                        //save new cookie
                        HttpCookie cookie = new HttpCookie(TRACKINGCOOKIENAME);
                        cookie.Value   = oui.OnlineUserGuid.ToString();
                        cookie.Expires = DateTime.Now.AddHours(1);
                        HttpContext.Current.Response.Cookies.Remove(TRACKINGCOOKIENAME);
                        HttpContext.Current.Response.Cookies.Add(cookie);
                    }

                    //maximum online customers
                    int currentVisitors = GetAnonymousUserList().Count() + GetRegisteredUserList().Count();
                    if (currentVisitors > this.MaximumOnlineCustomers)
                    {
                        this.MaximumOnlineCustomers = currentVisitors;
                    }
                }
            }
            catch (NopException exc)
            {
                Debug.WriteLine(exc.ToString());
            }
        }
 protected string GetLastPageVisitedInfo(OnlineUserInfo oui)
 {
     string result= string.Empty;
     if (!String.IsNullOrEmpty(oui.LastPageVisited))
     {
         result = string.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", oui.LastPageVisited);
     }
     return result;
 }
        protected string GetCustomerInfo(OnlineUserInfo oui)
        {
            string customerInfo = string.Empty;
            if (oui.AssociatedCustomerId.HasValue)
            {
                var customer = CustomerManager.GetCustomerById(oui.AssociatedCustomerId.Value);
                if (customer != null)
                {
                    customerInfo = string.Format("{0} (<a href=\"CustomerDetails.aspx?CustomerID={1}\">{2}</a>)", Server.HtmlEncode(customer.FullName), customer.CustomerId, Server.HtmlEncode(customer.Email));
                }
                else
                {
                    customerInfo = GetLocaleResourceString("Admin.OnlineCustomers.CustomerInfoColumn.Guest");
                }
            }
            else
            {
                customerInfo = GetLocaleResourceString("Admin.OnlineCustomers.CustomerInfoColumn.Guest");
            }

            return customerInfo;
        }
 protected string GetLocationInfo(OnlineUserInfo oui)
 {
     string result= string.Empty;
     try
     {
         string countryName = GeoCountryLookup.LookupCountryName(oui.IPAddress);
         result = Server.HtmlEncode(countryName);
     }
     catch (Exception exc)
     {
         Debug.WriteLine(exc.ToString());
     }
     return result;
 }