Example #1
0
        /// <summary>
        /// Sends a notification on behalf of the specified device.
        /// </summary>
        /// <param name="sender">Sender <see cref="DeviceBase"/> object.</param>
        /// <param name="notification"><see cref="DeviceNotification"/> object to send.</param>
        public void SendNotification(DeviceBase sender, DeviceNotification notification)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }

            Logger.InfoFormat("Sending notification '{0}' from device {1} ({2})", notification.Name, sender.ID, sender.Name);

            try
            {
                var cNotification = new Notification(notification.Name.Trim(),
                                                     notification.Parameters == null ? null : notification.Parameters.DeepClone());
                DeviceClient.SendNotification(sender.ID, sender.Key, cNotification);
            }
            catch (Exception ex)
            {
                // critical error - log and fault the service
                Logger.Error(string.Format("Exception while sending notification '{0}' from device {1} ({2})", notification.Name, sender.ID, sender.Name), ex);
                throw;
            }
        }
Example #2
0
 public void SendNotification(DeviceNotification notification)
 {
     _host.SendNotification(_device, notification);
 }