public Task <bool> DeviceCameOnline(Device device) { try { if (ServiceConnections.Any(x => x.Value.ID == device.ID)) { DataService.WriteEvent(new EventLog() { EventType = EventType.Info, OrganizationID = device.OrganizationID, Message = $"Device connection for {device?.DeviceName} was denied because it is already connected." }); return(Task.FromResult(false)); } var ip = Context.GetHttpContext()?.Connection?.RemoteIpAddress; if (ip != null && ip.IsIPv4MappedToIPv6) { ip = ip.MapToIPv4(); } device.PublicIP = ip?.ToString(); if (DataService.AddOrUpdateDevice(device, out var updatedDevice)) { Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); var userIDs = BrowserHub.ConnectionIdToUserLookup.Values.Select(x => x.Id); var filteredUserIDs = DataService.FilterUsersByDevicePermission(userIDs, Device.ID); var connectionIds = BrowserHub.ConnectionIdToUserLookup .Where(x => x.Value.OrganizationID == Device.OrganizationID && filteredUserIDs.Contains(x.Value.Id)) .Select(x => x.Key) .ToList(); BrowserHubContext.Clients.Clients(connectionIds).SendAsync("DeviceCameOnline", Device); return(Task.FromResult(true)); } else { // Organization wasn't found. return(Task.FromResult(false)); } } catch (Exception ex) { DataService.WriteEvent(ex, Device?.OrganizationID); } Context.Abort(); return(Task.FromResult(false)); }
public async Task DeviceCameOnline(Device device) { try { if (ServiceConnections.Any(x => x.Value.ID == device.ID)) { DataService.WriteEvent(new EventLog() { EventType = EventTypes.Info, OrganizationID = device.OrganizationID, Message = $"Device connection for {device?.DeviceName} was denied because it is already connected." }); Context.Abort(); return; } if (DataService.AddOrUpdateDevice(device, out var updatedDevice)) { Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); var onlineOrganizationUsers = BrowserSocketHub.ConnectionIdToUserLookup .Where(x => x.Value.OrganizationID == Device.OrganizationID); var authorizedUsers = DataService.GetUsersWithAccessToDevice(onlineOrganizationUsers.Select(x => x.Value.Id), Device); var connectionIds = onlineOrganizationUsers .Where(onlineUser => authorizedUsers.Any(authorizedUser => authorizedUser.Id == onlineUser.Value.Id)) .Select(x => x.Key) .ToList(); await BrowserHub.Clients.Clients(connectionIds).SendAsync("DeviceCameOnline", Device); } else { // Organization wasn't found. await Clients.Caller.SendAsync("UninstallClient"); } } catch (Exception ex) { DataService.WriteEvent(ex); throw; } }
public Task <bool> DeviceCameOnline(Device device) { try { if (ServiceConnections.Any(x => x.Value.ID == device.ID)) { DataService.WriteEvent(new EventLog() { EventType = EventType.Info, OrganizationID = device.OrganizationID, Message = $"Device connection for {device?.DeviceName} was denied because it is already connected." }); return(Task.FromResult(false)); } if (DataService.AddOrUpdateDevice(device, out var updatedDevice)) { Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); var connectionIds = BrowserSocketHub.ConnectionIdToUserLookup .Where(x => x.Value.OrganizationID == Device.OrganizationID) .Select(x => x.Key) .ToList(); BrowserHub.Clients.Clients(connectionIds).SendAsync("DeviceCameOnline", Device); return(Task.FromResult(true)); } else { // Organization wasn't found. return(Task.FromResult(false)); } } catch (Exception ex) { DataService.WriteEvent(ex); } Context.Abort(); return(Task.FromResult(false)); }
public async Task DeviceHeartbeat(Device device) { if (CheckForDeviceBan(device.ID, device.DeviceName)) { return; } var ip = Context.GetHttpContext()?.Connection?.RemoteIpAddress; if (ip != null && ip.IsIPv4MappedToIPv6) { ip = ip.MapToIPv4(); } device.PublicIP = ip?.ToString(); if (CheckForDeviceBan(device.PublicIP)) { return; } _dataService.AddOrUpdateDevice(device, out var updatedDevice); Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); var userIDs = _circuitManager.Connections.Select(x => x.User.Id); var filteredUserIDs = _dataService.FilterUsersByDevicePermission(userIDs, Device.ID); var connections = _circuitManager.Connections .Where(x => x.User.OrganizationID == Device.OrganizationID && filteredUserIDs.Contains(x.User.Id)); foreach (var connection in connections) { _ = connection.InvokeCircuitEvent(CircuitEventName.DeviceUpdate, Device); } await CheckForPendingSriptRuns(); }
public Task DeviceHeartbeat(Device device) { if (CheckForDeviceBan(device.ID, device.DeviceName)) { return(Task.CompletedTask); } var ip = Context.GetHttpContext()?.Connection?.RemoteIpAddress; if (ip != null && ip.IsIPv4MappedToIPv6) { ip = ip.MapToIPv4(); } device.PublicIP = ip?.ToString(); if (CheckForDeviceBan(device.PublicIP)) { return(Task.CompletedTask); } DataService.AddOrUpdateDevice(device, out var updatedDevice); Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); var userIDs = BrowserHub.ConnectionIdToUserLookup.Values.Select(x => x.Id); var filteredUserIDs = DataService.FilterUsersByDevicePermission(userIDs, Device.ID); var connectionIds = BrowserHub.ConnectionIdToUserLookup .Where(x => x.Value.OrganizationID == Device.OrganizationID && filteredUserIDs.Contains(x.Value.Id)) .Select(x => x.Key) .ToList(); return(BrowserHubContext.Clients.Clients(connectionIds).SendAsync("DeviceHeartbeat", Device)); }
public Task <bool> DeviceCameOnline(Device device) { try { if (CheckForDeviceBan(device.ID, device.DeviceName)) { return(Task.FromResult(false)); } if (ServiceConnections.Any(x => x.Value.ID == device.ID)) { _dataService.WriteEvent(new EventLog() { EventType = EventType.Info, OrganizationID = device.OrganizationID, Message = $"Device connection for {device?.DeviceName} was denied because it is already connected." }); return(Task.FromResult(false)); } var ip = Context.GetHttpContext()?.Connection?.RemoteIpAddress; if (ip != null && ip.IsIPv4MappedToIPv6) { ip = ip.MapToIPv4(); } device.PublicIP = ip?.ToString(); if (CheckForDeviceBan(device.PublicIP)) { return(Task.FromResult(false)); } if (_dataService.AddOrUpdateDevice(device, out var updatedDevice)) { Device = updatedDevice; ServiceConnections.AddOrUpdate(Context.ConnectionId, Device, (id, d) => Device); var userIDs = _circuitManager.Connections.Select(x => x.User.Id); var filteredUserIDs = _dataService.FilterUsersByDevicePermission(userIDs, Device.ID); var connections = _circuitManager.Connections .Where(x => x.User.OrganizationID == Device.OrganizationID && filteredUserIDs.Contains(x.User.Id)); foreach (var connection in connections) { connection.InvokeCircuitEvent(CircuitEventName.DeviceUpdate, Device); } return(Task.FromResult(true)); } else { // Organization wasn't found. return(Task.FromResult(false)); } } catch (Exception ex) { _dataService.WriteEvent(ex, device?.OrganizationID); } Context.Abort(); return(Task.FromResult(false)); }