private void OnNotification(ApiLibNotificationManager sender, string method, ApiVersion version, string serializedParams) { Dictionary <ApiVersion, Dictionary <string, EventInfo> > libDelegates = this.handlers[sender.Lib]; if (libDelegates != null) { Dictionary <string, EventInfo> versionDelegates = libDelegates[version]; if (versionDelegates != null) { EventInfo eventInfo = versionDelegates[method]; if (eventInfo != null) { // We expect this to be the argument in NotificationEventHandler<> Type genericArgumentType = eventInfo.EventHandlerType.GenericTypeArguments[0]; dynamic notificationResult = JsonSerializer.Deserialize(serializedParams, genericArgumentType); FieldInfo eventFieldInfo = eventInfo.DeclaringType.GetField(eventInfo.Name, BindingFlags.Instance | BindingFlags.NonPublic); dynamic eventField = eventFieldInfo.GetValue(this.Api); try { eventField.Invoke(this.Device, notificationResult); } catch { // Ignore handler errors } } } } }
public NotificationManager(DeviceDescriptor device, Api api) { this.Device = device; this.Api = api; this.initializeSubscriptions(); this.audioNotificationManager = new ApiLibNotificationManager(this.Device, ApiLib.Audio, this.getSubscriptionsForLib(ApiLib.Audio)); this.avContentNotificationManager = new ApiLibNotificationManager(this.Device, ApiLib.AvContent, this.getSubscriptionsForLib(ApiLib.AvContent)); this.systemNotificationManager = new ApiLibNotificationManager(this.Device, ApiLib.System, this.getSubscriptionsForLib(ApiLib.System)); this.audioNotificationManager.OnNotification += this.OnNotification; this.avContentNotificationManager.OnNotification += this.OnNotification; this.systemNotificationManager.OnNotification += this.OnNotification; }