using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Tango.TCC.Service.DTO; namespace Tango.TCC.Service.Hubs { public class ResultsHub : Hub { private static IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext(); private static Dictionary _connectionsDevices; public ResultsHub() { _connectionsDevices = new Dictionary(); } public void Hello() { } public void setDevice(String deviceId) { if(String.IsNullOrEmpty(deviceId)) { _connectionsDevices.Remove(Context.ConnectionId); } else { _connectionsDevices[Context.ConnectionId] = deviceId; } } public static void PushResult(ResultDTO result) { foreach (var item in _connectionsDevices.ToList().Where(x => x.Value == result.Email)) { hubContext.Clients.Client(item.Key).setRealTimeResult(result); } } } }