/// <summary> /// Instructs the device to start observing a specific notification. /// </summary> /// <param name="name"> /// The name of the notification the device should start observing. /// </param> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation. /// </param> /// <returns> /// A <see cref="Task"/> which represents the asynchronous operation. /// </returns> public async virtual Task ObserveNotificationAsync(string name, CancellationToken cancellationToken) { var request = new NotificationProxyMessage() { Command = "ObserveNotification", Name = name, }; await this.protocol.WriteMessageAsync(request.ToPropertyList(), cancellationToken).ConfigureAwait(false); }
/// <summary> /// Reads a notification which has been relayed by the device. /// </summary> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation. /// </param> /// <returns> /// A <see cref="Task"/> which represents the asynchronous operation. /// </returns> public async virtual Task <string> ReadRelayNotificationAsync(CancellationToken cancellationToken) { var message = await this.protocol.ReadMessageAsync(cancellationToken).ConfigureAwait(false); if (message == null) { return(null); } var notificationMessage = NotificationProxyMessage.Read(message); if (notificationMessage.Command != "RelayNotification") { throw new InvalidOperationException($"The device sent an unexpected '{notificationMessage.Command}' command."); } return(notificationMessage.Name); }