예제 #1
0
 public string IsTeacherLoggedIn()
 {
     using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
     {
         return(db.IsTeacherLogged());
     }
 }
예제 #2
0
        public override async System.Threading.Tasks.Task OnConnected()
        {
            var name      = Context.User.Identity.Name;
            var isTeacher = Context.User.IsInRole("Teacher");

            using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
            {
                await db.HandleUserConnections(Context, name, isTeacher);

                var connections = db.GetAllValidConnections();
                if (isTeacher)
                {
                    foreach (var c in connections)
                    {
                        Clients.Client(c.HubConnectionID).userConnected(new HubUser
                        {
                            Name      = name,
                            IsTeacher = true
                        });
                    }
                }
                else
                {
                    foreach (var c in connections)
                    {
                        Clients.Client(c.HubConnectionID).userConnected(new HubUser
                        {
                            Name      = name,
                            IsTeacher = false
                        });
                    }
                }
            }
            await base.OnConnected();
        }
예제 #3
0
 public IEnumerable <string> GetConnectedStudents()
 {
     using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
     {
         return(db.GetConnectedStudents());
     }
 }
예제 #4
0
 public void TeacherStopped()
 {
     Clients.AllExcept(Context.ConnectionId).teacherStoppedExplicitly();
     using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
     {
         db.RemoveAllHubConnections();
     }
 }
예제 #5
0
 public void CancelControlFromTeacher(string user)
 {
     using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
     {
         var con = db.GetStudentHubConnection(user);
         if (con != null)
         {
             Clients.Client(con.HubConnectionID).cancelFromTeacher();
         }
     }
 }
예제 #6
0
 public override async System.Threading.Tasks.Task OnDisconnected(bool stopCalled)
 {
     try
     {
         using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
         {
             await db.UpdateUserConnection(Context.ConnectionId, false);
         }
         //send out the disconnect
         using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
         {
             var isTeacher   = Context.User.IsInRole("Teacher");
             var connections = db.GetAllValidConnections();
             if (isTeacher)
             {
                 foreach (var c in connections)
                 {
                     Clients.Client(c.HubConnectionID).userDisconnected(new HubUser
                     {
                         Name      = Context.User.Identity.Name,
                         IsTeacher = true
                     }, stopCalled);
                 }
                 //if (stopCalled)
                 //{
                 //    db.RemoveAllHubConnections();
                 //}
             }
             else
             {
                 foreach (var c in connections)
                 {
                     Clients.Client(c.HubConnectionID).userDisconnected(new HubUser
                     {
                         Name      = Context.User.Identity.Name,
                         IsTeacher = false
                     }, stopCalled);
                 }
             }
         }
     }
     catch (Exception e)
     {
         var msg = e.Message;
         throw;
     }
     await base.OnDisconnected(stopCalled);
 }
예제 #7
0
 public override async System.Threading.Tasks.Task OnReconnected()
 {
     try
     {
         using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
         {
             await db.UpdateUserConnection(Context.ConnectionId, true);
         }
         using (var db = new EDCWebApp.DAL.EDCLoginUserContext())
         {
             var connections = db.GetAllValidConnections();
             var isTeacher   = Context.User.IsInRole("Teacher");
             if (isTeacher)
             {
                 foreach (var c in connections)
                 {
                     Clients.Client(c.HubConnectionID).userReconnected(new HubUser
                     {
                         Name      = Context.User.Identity.Name,
                         IsTeacher = true
                     });
                 }
             }
             else
             {
                 foreach (var c in connections)
                 {
                     Clients.Client(c.HubConnectionID).userReconnected(new HubUser
                     {
                         Name      = Context.User.Identity.Name,
                         IsTeacher = false
                     });
                 }
             }
         }
     }
     catch (Exception e)
     {
         var msg = e.Message;
     }
     await base.OnReconnected();
 }