示例#1
0
        public void UnsubsrcibeFromDeviceCommands()
        {
            var subscriptions = _subscriptionManager.GetSubscriptions(Connection);

            foreach (var subscription in subscriptions)
            {
                if (subscription.Keys.Contains(CurrentDevice.ID))
                {
                    _subscriptionManager.Unsubscribe(Connection, subscription.Id);
                }
            }

            SendSuccessResponse();
        }
示例#2
0
        /// <summary>
        /// Notifies the user about new device command.
        /// </summary>
        /// <action>command/insert</action>
        /// <response>
        ///     <parameter name="subscriptionId" type="guid">Identifier of the associated subscription.</parameter>
        ///     <parameter name="deviceGuid" type="string">Device unique identifier.</parameter>
        ///     <parameter name="command" cref="DeviceCommand">A <see cref="DeviceCommand"/> resource representing the command.</parameter>
        /// </response>
        public void HandleDeviceCommand(int deviceId, int commandId, string name)
        {
            var subscriptions = _deviceSubscriptionManagerForCommands.GetSubscriptions(deviceId);

            if (subscriptions.Any())
            {
                Device        device  = null;
                DeviceCommand command = null;
                foreach (var subscription in subscriptions)
                {
                    var names = (string[])subscription.Data;
                    if (names != null && !names.Contains(name))
                    {
                        continue;
                    }

                    if (command == null)
                    {
                        command = DataContext.DeviceCommand.Get(commandId);
                    }

                    if (device == null)
                    {
                        device = DataContext.Device.Get(deviceId);
                    }

                    Notify(subscription.Connection, subscription.Id, command, device);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Notifies the user about new device notification.
        /// </summary>
        /// <action>notification/insert</action>
        /// <response>
        ///     <parameter name="subscriptionId" type="guid">Identifier of the associated subscription.</parameter>
        ///     <parameter name="deviceGuid" type="string">Device unique identifier.</parameter>
        ///     <parameter name="notification" cref="DeviceNotification">A <see cref="DeviceNotification"/> resource representing the notification.</parameter>
        /// </response>
        public void HandleDeviceNotification(int deviceId, int notificationId, string name)
        {
            var subscriptions = _deviceSubscriptionManagerForNotifications.GetSubscriptions(deviceId);

            if (subscriptions.Any())
            {
                Device             device       = null;
                DeviceNotification notification = null;
                foreach (var subscription in subscriptions)
                {
                    var names = (string[])subscription.Data;
                    if (names != null && !names.Contains(name))
                    {
                        continue;
                    }

                    if (notification == null)
                    {
                        notification = DataContext.DeviceNotification.Get(notificationId);
                    }

                    if (device == null)
                    {
                        device = DataContext.Device.Get(deviceId);
                    }

                    Notify(subscription.Connection, subscription.Id, notification, device);
                }
            }
        }