public async Task StartAsync(CancellationToken cancellationToken) { var locationsList = new List <string> { "1", "2", "3", "4" }; while (!cancellationToken.IsCancellationRequested) { foreach (var location in locationsList) { var connectionId = LocationMappings.GetConnectionId(location); if (!string.IsNullOrWhiteSpace(connectionId)) { await _hubContext.Clients.Client(connectionId).SendAsync(receiveWorkMethodName); } else { await _hubContext.Clients.Groups(LocationsAreaMapper.GetLocationName(location)).SendAsync(receiveWorkMethodName); } await Task.Delay(30000); } } }
/// <summary> /// Adds a location mapping for the provided access mapping and location /// to the service definition. Note that if a mapping already exists for /// the provided access mapping, it will be overwritten. /// </summary> /// <param name="accessMapping">The access mapping this location mapping is for. /// This access mapping must already be registered in the LocationService. To create /// a new access mapping, see LocationService.ConfigureAccessMapping</param> /// <param name="location">This value must be null if the RelativeToSetting /// for this ServiceDefinition is something other than FullyQualified. If /// this ServiceDefinition has a RelativeToSetting of FullyQualified, this /// value must not be null and should be the location where this service resides /// for this access mapping.</param> public void AddLocationMapping(AccessMapping accessMapping, String location) { if (RelativeToSetting != RelativeToSetting.FullyQualified) { throw new InvalidOperationException(WebApiResources.RelativeLocationMappingErrorMessage()); } // Make sure the location has a value if (location == null) { throw new ArgumentException(WebApiResources.FullyQualifiedLocationParameter()); } // See if an entry for this access mapping already exists, if it does, overwrite it. foreach (LocationMapping mapping in LocationMappings) { if (VssStringComparer.AccessMappingMoniker.Equals(mapping.AccessMappingMoniker, accessMapping.Moniker)) { mapping.Location = location; return; } } // This is a new entry for this access mapping, just add it. LocationMappings.Add(new LocationMapping() { AccessMappingMoniker = accessMapping.Moniker, Location = location }); }
public async Task ReceiveDeviceConnected(string deviceId, string areaName, string locationNumber) { UserMappings.AddDeviceConnected(deviceId, Context.ConnectionId); LocationMappings.MapDeviceToLocation(locationNumber, Context.ConnectionId); await Groups.AddToGroupAsync(Context.ConnectionId, areaName); }