null checks on code hub
This commit is contained in:
parent
056d810909
commit
e9441d510e
@ -10,11 +10,17 @@ namespace BinaryDad.Coding.Hubs
|
|||||||
{
|
{
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
{
|
{
|
||||||
Users.Sessions[Context.ConnectionId].Html = code;
|
if (Users.Sessions.TryGetValue(Context.ConnectionId, out User value))
|
||||||
|
{
|
||||||
|
value.Html = code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (index == 1)
|
else if (index == 1)
|
||||||
{
|
{
|
||||||
Users.Sessions[Context.ConnectionId].Css = code;
|
if (Users.Sessions.TryGetValue(Context.ConnectionId, out User value))
|
||||||
|
{
|
||||||
|
value.Css = code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only send to all if it's a teacher
|
// only send to all if it's a teacher
|
||||||
@ -27,10 +33,13 @@ namespace BinaryDad.Coding.Hubs
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveName(string name, string color)
|
public async Task SaveName(string name, string color)
|
||||||
|
{
|
||||||
|
if (!Users.Sessions.ContainsKey(Context.ConnectionId))
|
||||||
{
|
{
|
||||||
Users.Sessions[Context.ConnectionId].Id = Context.ConnectionId;
|
Users.Sessions[Context.ConnectionId].Id = Context.ConnectionId;
|
||||||
Users.Sessions[Context.ConnectionId].Name = name;
|
Users.Sessions[Context.ConnectionId].Name = name;
|
||||||
Users.Sessions[Context.ConnectionId].Color = string.IsNullOrWhiteSpace(color) ? "white" : color;
|
Users.Sessions[Context.ConnectionId].Color = string.IsNullOrWhiteSpace(color) ? "white" : color;
|
||||||
|
}
|
||||||
|
|
||||||
await Clients.All.SendAsync("UsersList", Users.Sessions);
|
await Clients.All.SendAsync("UsersList", Users.Sessions);
|
||||||
}
|
}
|
||||||
@ -48,8 +57,11 @@ namespace BinaryDad.Coding.Hubs
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnDisconnectedAsync(Exception exception)
|
public override async Task OnDisconnectedAsync(Exception exception)
|
||||||
|
{
|
||||||
|
if (Users.Sessions.ContainsKey(Context.ConnectionId))
|
||||||
{
|
{
|
||||||
Users.Sessions.Remove(Context.ConnectionId);
|
Users.Sessions.Remove(Context.ConnectionId);
|
||||||
|
}
|
||||||
|
|
||||||
await Clients.All.SendAsync("UsersList", Users.Sessions);
|
await Clients.All.SendAsync("UsersList", Users.Sessions);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user