Beispiel #1
0
        private const string LED_CODE = "LED"; // LED equipment code

        #endregion Fields

        #region Methods

        private static void HandleNotifications(IClientService service, Device device, CancellationToken token)
        {
            try
            {
                var timestamp = DateTime.UtcNow;
                while (true)
                {
                    // poll notification from the server
                    var notifications = service.PollNotifications(device.Id.Value, timestamp, token);
                    if (notifications == null)
                        continue;

                    // display information about received notification
                    foreach (var notification in notifications.Where(n =>
                        n.Name == "equipment" && n.GetParameter("equipment") == LED_CODE))
                    {
                        var message = "Device sent LED state change notification, new state: {0}";
                        Console.WriteLine(string.Format(message, notification.GetParameter("state")));
                    }

                    // update last received notification timestamp
                    timestamp = notifications.Max(n => n.Timestamp.Value);
                }
            }
            catch (OperationCanceledException)
            {
                return;
            }
        }