예제 #1
0
        /// <summary>
        ///     Subscribes the calling client to the item matching the provided FQN.
        /// </summary>
        /// <remarks>
        ///     Registers an event handler to the Changed event for the item, adds the client to the SignalR group for the item's
        ///     FQN, Subscribes the client to the item within the HubManager and calls the subscribeSuccess() method on the calling client.
        /// </remarks>
        /// <param name="arg">The Fully Qualified name of the Item to which to subscribe.</param>
        public void Subscribe(object arg)
        {
            string castFQN = (string)arg;

            // Item foundItem = manager.ProviderRegistry.FindItem(castFQN);
            Item foundItem = manager.GetManager <IModelManager>().FindItem(castFQN);

            if (foundItem != default(Item))
            {
                if (hubManager.GetClientSubscriptions(Context.ConnectionId).Contains(foundItem.FQN))
                {
                    logger.Info(GetLogPrefix() + "is already subscribed to '" + foundItem.FQN + "'.");
                }
                else
                {
                    foundItem.Changed += hubManager.OnChange;
                    Groups.Add(Context.ConnectionId, foundItem.FQN);
                    hubManager.Subscribe(foundItem.FQN, Context.ConnectionId);
                    Clients.Caller.subscribeSuccess(castFQN);

                    logger.Info(GetLogPrefix() + "subscribed to '" + foundItem.FQN + "'.");

                    logger.Info("SignalR Item '" + foundItem.FQN + "' now has " + hubManager.GetSubscriptions(foundItem.FQN).Count + " subscriber(s).");

                    // force a read event to populate the initial value client side
                    InvokeRead(foundItem);
                }
            }
            else
            {
                Clients.Caller.subscribeError(castFQN);
                logger.Info("Unable to subscribe to '" + castFQN + "'; the Item can't be found.");
            }
        }
예제 #2
0
        /// <summary>
        ///     Subscribes the calling client to the logger.
        /// </summary>
        /// <remarks>
        ///     Registers an event handler to the Changed event for the item, adds the client to the SignalR group for the item's
        ///     FQN, Subscribes the client to the item within the HubManager and calls the subscribeSuccess() method on the calling client.
        /// </remarks>
        /// <param name="arg">The Fully Qualified name of the Item to which to subscribe.</param>
        public void Subscribe(object arg)
        {
            Groups.Add(Context.ConnectionId, "Logger");
            hubManager.Subscribe("Logger", Context.ConnectionId);
            Clients.Caller.subscribeSuccess("Logger");

            logger.Info(GetLogPrefix() + "subscribed to the Logger.");

            logger.Info("SignalR Logger now has " + hubManager.GetSubscriptions("Logger").Count + " subscriber(s).");
        }