Exemplo n.º 1
0
        /// <summary>
        /// Notifies peer about Item entered area.
        /// </summary>
        public override void OnItemEnter(ItemSnapshot snapshot)
        {
            base.OnItemEnter(snapshot);
            var item = snapshot.Source;
            var subscribeEvent = new ItemSubscribed
            {
                ItemId = item.Id,
                ItemType = item.Type,
                Position = snapshot.Position,
                PropertiesRevision = snapshot.PropertiesRevision,
                InterestAreaId = this.Id,
                Rotation = snapshot.Rotation
            };

            var eventData = new EventData((byte)EventCode.ItemSubscribed, subscribeEvent);
            this.peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
        }
        private OperationResponse ItemOperationSubscribeItem(Item item, SubscribeItem operation)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            this.interestItems.SubscribeItem(item);

            var subscribeEvent = new ItemSubscribed
            {
                ItemId = item.Id,
                ItemType = item.Type,
                Position = item.Position,
                PropertiesRevision = item.PropertiesRevision,
                Rotation = item.Rotation
            };

            var eventData = new EventData((byte)EventCode.ItemSubscribed, subscribeEvent);
            this.Peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });

            if (operation.PropertiesRevision.HasValue == false || operation.PropertiesRevision.Value != item.PropertiesRevision)
            {
                var properties = new ItemPropertiesSet
                    {
                        ItemId = item.Id,
                        PropertiesRevision = item.PropertiesRevision,
                        PropertiesSet = new Hashtable(item.Properties)
                    };
                var propEventData = new EventData((byte)EventCode.ItemPropertiesSet, properties);
                this.Peer.SendEvent(propEventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
            }

            // don't send response
            operation.OnComplete();
            return null;
        }