Beispiel #1
0
 private void  addConnection(string refererUrl, string remoteIP)
 {
     if (Context.Request.User.Identity.IsAuthenticated)
     {
         db.AddConnection(Context.ConnectionId, refererUrl, remoteIP, Context.Request.User.Identity.Name);
     }
     else
     {
         db.AddConnection(Context.ConnectionId, refererUrl, remoteIP);
     }
 }
        protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
        {
            DAL.ServiceContext db = new DAL.ServiceContext();
            var dbCon             = db.SignalRConnections.FirstOrDefault(ln => ln.SignalRConnectionId == context.Hub.Context.ConnectionId);

            if (dbCon == null)
            {
                //  SimpleLogger logger = new SimpleLogger();
                //  logger.Info("added connection on BeForeIncoming");
                db.AddConnection(context.Hub.Context.ConnectionId, context.Hub.Context.Request.GetRefererUrl(), context.Hub.Context.Request.GetClientIp());
            }

            //if (Enum.TryParse(context.MethodDescriptor.Name, out Enums.EnumServiceHubMethods res))
            //{
            //    var dbCon = db.SignalRConnections.FirstOrDefault(ln => ln.SignalRConnectionId == context.Hub.Context.ConnectionId);
            //    switch (res)
            //    {
            //        case Enums.EnumServiceHubMethods.JoinGroup:
            //            if (!dbCon.Groups.Contains(context.Args[0].ToString()))
            //                dbCon.Groups.Add(context.Args[0].ToString());

            //            break;
            //        case Enums.EnumServiceHubMethods.LeaveGroup:
            //            var rm = dbCon.Groups.Remove(context.Args[0].ToString());
            //            break;
            //        default:
            //            break;
            //    }
            //    db.SaveChanges();

            //}
            return(true);
        }