private void OnProcessorInputTypeRemoved(object sender, InputTypeRegistrationEventArgs e) { var processor = (IProcessor)sender; var inputType = e.DataType; if (!typeMap.TryGetValue(inputType, out var typeProcessors)) { return; } lock (typeMapListLock) { if (typeProcessors.Remove(processor)) { if (!typeProcessors.Any()) { typeMap.TryRemove(inputType, out _); InputTypeRemoved?.Invoke(this, new InputTypeRegistrationEventArgs(inputType)); } } } }
private void OnProcessorInputTypeAdded(object sender, InputTypeRegistrationEventArgs e) { var processor = (IProcessor)sender; var inputType = e.DataType; if (typeMap.TryAdd(inputType, new List <IProcessor>())) { InputTypeAdded?.Invoke(this, new InputTypeRegistrationEventArgs(inputType)); } if (!typeMap.TryGetValue(inputType, out var typeProcessors)) { throw new Exception($"Expected type map to contain '{inputType}'"); } lock (typeMapListLock) { if (typeProcessors.Contains(processor)) { return; } typeProcessors.Add(processor); } }
private async void OnInputTypeAdded(object sender, InputTypeRegistrationEventArgs e) { await SubscribeToDataType(e.DataType); }
private async void OnInputTypeRemoved(object sender, InputTypeRegistrationEventArgs e) { await UnsubscribeFromDataType(e.DataType); }