예제 #1
0
        protected void SendInfoAboutObjects(IList <HLAobjectRoot> objects, HLAsubscribeObjectClassAttributesMessage msg)
        {
            foreach (HLAobjectRoot obj in objects)
            {
                // if it is a local object and its class handle is equal to the object class handle sent
                if (obj.HLAprivilegeToDeleteObject && obj.ClassHandle.Equals(msg.HLAobjectClass))
                {
                    parent.RegisterObjectInstance(obj);

                    IList <HLAattributeHandleValuePair> propertyValuePair = new List <HLAattributeHandleValuePair>();

                    // TODO ANGEL: Esto es incorrecto y esta mal. Puede haber propiedades que no sean remotas
                    foreach (IAttributeHandle attribute in msg.HLAattributeList)
                    {
                        AttributeDescriptor ad = parent.descriptorManager.GetAttributeDescriptor(attribute);
                        if (ad == null)
                        {
                            throw new InvalidAttributeHandle(attribute.ToString());
                        }
                        else
                        {
                            PropertyInfo pi = obj.GetType().BaseType.GetProperty(ad.Name);

                            if (!ad.Name.Equals("HLAprivilegeToDeleteObject") && pi != null)
                            {
                                object value = pi.GetValue(obj, null);

                                if (value != null)
                                {
                                    propertyValuePair.Add(new HLAattributeHandleValuePair(((XRTIAttributeHandle)ad.Handle).Identifier, value));
                                }
                            }
                        }
                    }

                    HLAattributeHandleValuePair[] propertyValuePairArray = new HLAattributeHandleValuePair[propertyValuePair.Count];
                    propertyValuePair.CopyTo(propertyValuePairArray, 0);

                    // TODO ANGEL: Que pasa con el userTag
                    parent.UpdateAttributeValues(obj.InstanceHandle, propertyValuePairArray, null);
                }
            }
        }
        ///<summary>
        ///Notifies that the box is already in its house
        ///</summary>
        ///<param name="msg"> the message associated with the interaction</param>
        ///<exception cref="InteractionClassNotRecognized"> if the interaction class was not recognized</exception>
        ///<exception cref="InteractionParameterNotRecognized"> if a parameter of the interaction was not
        /// recognized</exception>
        ///<exception cref="InteractionClassNotSubscribed"> if the federate had not subscribed to the
        /// interaction class</exception>
        ///<exception cref="FederateInternalError"> if an error occurs in the federate</exception>
        public void OnReceiveBoxInHouse(BoxInHouseMessage msg)
        {
            ILogicalTime time = timeFactory.Decode(msg.Time, 0);

            if (log.IsDebugEnabled)
            {
                log.Debug("Received BoxInHouseMessage [time = " + time + "]");
            }

            form.UpdateBoxInHouseTimeLabel(time);

            ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(home.InstanceHandle);
            IObjectClassHandle       och = oid.ClassHandle;
            ObjectClassDescriptor    ocd = rti.descriptorManager.GetObjectClassDescriptor(och);

            HLAattributeHandleValuePair[] handleValuePairList = new HLAattributeHandleValuePair[1];
            handleValuePairList[0] = new HLAattributeHandleValuePair();
            handleValuePairList[0].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor("BoxesCount").Handle).Identifier;
            handleValuePairList[0].AttributeValue  = 1;

            rti.UpdateAttributeValues(home.InstanceHandle, handleValuePairList, new byte[1], time);
        }