/// <summary> /// /// </summary> /// <param name="objOnlineVisitorInfo"></param> /// <param name="connectionID"></param> public void AddVisitorOnline(OnlineVisitorInfo objOnlineVisitorInfo, string connectionID) { Requires.NotNull(objOnlineVisitorInfo); using (IDataContext ctx = DataContext.Instance()) { ctx.Execute(System.Data.CommandType.StoredProcedure, "MyDnnVisitorsOnline_Add", objOnlineVisitorInfo.PortalID, objOnlineVisitorInfo.VisitorGUID, objOnlineVisitorInfo.UserName, objOnlineVisitorInfo.DisplayName, objOnlineVisitorInfo.Email, objOnlineVisitorInfo.OnlineDate, objOnlineVisitorInfo.IP, objOnlineVisitorInfo.UserAgent, objOnlineVisitorInfo.LastURL, objOnlineVisitorInfo.ReferrerURL, connectionID); } string cacheKey = CachePrefix + objOnlineVisitorInfo.PortalID; DataCache.ClearCache(cacheKey); }
/// <summary> /// /// </summary> /// <param name="portalID"></param> /// <param name="visitorGUID"></param> /// <param name="name"></param> /// <param name="email"></param> /// <param name="referrerDomain"></param> public void JoinVisitor(int portalID, string visitorGUID, string name, string email, string referrerDomain) { if (PurgeVisitorOnlineTimer == null) { PurgeVisitorOnlineTimer = new Timer(new TimerCallback(this.PurgeVisitorOnline), portalID, 59000, 59000); } bool isUpdated = false; bool checkRoles = true; var visitor = VisitorOnlineManager.Instance.GetVisitorByGUID(portalID, visitorGUID); string lastUrl = this.getURL(); string userName = this.UserName; if (visitor == null) { visitor = new OnlineVisitorInfo() { VisitorGUID = visitorGUID, PortalID = portalID, UserName = userName, DisplayName = name, Email = email, OnlineDate = DateTime.Now, IP = getIpAddress(), UserAgent = getVisitorAgent(), LastURL = lastUrl, ReferrerURL = referrerDomain, }; VisitorOnlineManager.Instance.AddVisitorOnline(visitor, Context.ConnectionId); } else { VisitorOnlineManager.Instance.UpdateVisitorOnline(portalID, visitorGUID, userName, visitor.DisplayName, visitor.Email, lastUrl, Context.ConnectionId, false); isUpdated = true; } if (isUpdated) { if (!string.IsNullOrEmpty(visitor.UserName) && string.IsNullOrEmpty(userName)) // in yani user login bode va logoff shode { OfflineRoles(portalID); } else if (!string.IsNullOrEmpty(visitor.UserName) && !string.IsNullOrEmpty(userName)) // in yani user az ghabl login bode va niazi be check kardane role haye an nist { checkRoles = false; } //in ghesmat ro baraye in neveshtam ke agar visitor faghat urlesh taghir karde kole visitor ro dobare fetch nakone va faghat urlesh taghir kone if (visitor.UserName == userName) // in yani user login bode va logoff shode { visitor.LastURL = lastUrl; } else { visitor = VisitorOnlineManager.Instance.GetVisitorByGUID(portalID, visitorGUID); } Clients.Group("MyDnnVisitorsOnline").updateVisitorInfo(visitor); } else { if (!string.IsNullOrEmpty(visitor.UserName)) // agar user login shod visitor dobare bayad get shavad ta displayname va emailash ham biayad { visitor = VisitorOnlineManager.Instance.GetVisitorByGUID(portalID, visitorGUID); } Clients.Group("MyDnnVisitorsOnline").populateVisitorsOnline(visitor); } if (!string.IsNullOrEmpty(visitor.UserName) && checkRoles) //zamani ke yek karbar login mikonad bayad naghshhaye karbar baresi shavad va chenanche naghshe karbar joze listener ha bod script marbote ejra shavad { var user = UserController.GetUserByName(visitor.UserName); var rolesOnline = RoleOnlineManager.Instance.GetRolesOnline(portalID); IEnumerable <string> roles; if (user.IsSuperUser) { roles = RoleOnlineManager.Instance.GetSuperUserRoles(portalID, user.UserID); } else { roles = user.Roles; } if (!rolesOnline.Where(r => roles.Contains(r.RoleName)).Any()) { foreach (var role in roles) { RoleOnlineManager.Instance.AddRoleOnline(new OnlineRoleInfo() { PortalID = portalID, RoleName = role, OnlineDate = DateTime.Now }); } } var listeners = ListenerManager.Instance.GetListeners(portalID).Where(l => l.LoginState == LoginState.LoggedIn); foreach (var item in listeners.Join(roles, l => l.RoleName, r => r, (l, r) => l)) { Clients.All.invokeScript(item.InvokeScript); } } }