예제 #1
0
        /// <summary>
        /// Build a new instance using  XML data
        /// </summary>
        /// <param name="enumeratedDataElement"></param>
        public HLAEnumeratedData(System.Xml.XmlElement enumeratedDataElement)
            : base(enumeratedDataElement)
        {
            Representation = enumeratedDataElement.GetAttribute("representation");
            RepresentationNotes = enumeratedDataElement.GetAttribute("representationNotes");
            Semantics = ReplaceNewLines(enumeratedDataElement.GetAttribute("semantics"));
            SemanticsNotes = enumeratedDataElement.GetAttribute("semanticsNotes");

            System.Xml.XmlNodeList nl = enumeratedDataElement.GetElementsByTagName("enumerator");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement enumeratorElement = (System.Xml.XmlElement)nl.Item(i);
                HLAEnumerator enumerator = new HLAEnumerator(enumeratorElement);
                enumerators.Add(enumerator);
            }
        }
예제 #2
0
        /// <summary>
        /// Build a new instance using  XML data
        /// </summary>
        /// <param name="enumeratedDataElement"></param>
        public HLAEnumeratedData(System.Xml.XmlElement enumeratedDataElement)
            : base(enumeratedDataElement)
        {
            Representation      = enumeratedDataElement.GetAttribute("representation");
            RepresentationNotes = enumeratedDataElement.GetAttribute("representationNotes");
            Semantics           = ReplaceNewLines(enumeratedDataElement.GetAttribute("semantics"));
            SemanticsNotes      = enumeratedDataElement.GetAttribute("semanticsNotes");

            System.Xml.XmlNodeList nl = enumeratedDataElement.GetElementsByTagName("enumerator");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement enumeratorElement = (System.Xml.XmlElement)nl.Item(i);
                HLAEnumerator         enumerator        = new HLAEnumerator(enumeratorElement);
                enumerators.Add(enumerator);
            }
        }
예제 #3
0
        // END PATCH
        /// <summary>
        /// Load descriptors from an Assembly. It uses reflection and HLA attributes in order to explore the code. 
        /// </summary>
        /// <param name="assembly"> The assembly to explore</param>
        public virtual void AddDescriptorsFromAssembly(Assembly assembly)
        {
            if (assembly != null)
            {
                if (log.IsDebugEnabled)
                    log.Debug("Assembly Name :" + assembly.FullName);
                names.Add(assembly.FullName); //TODO it is not the right name. ??
            }
            else
                return;

            HLABasicDataAttribute[] basicDataArray = (HLABasicDataAttribute[])assembly.GetCustomAttributes(typeof(HLABasicDataAttribute), false);
            foreach (HLABasicDataAttribute basicData in basicDataArray)
            {
                //TODO Check that the corresponding native type is OK (size, etc.)
                basicDataMap.Add(basicData.Name, basicData.BasicDataInfo);
            }

            HLASimpleDataAttribute[] simpleDataArray = (HLASimpleDataAttribute[])assembly.GetCustomAttributes(typeof(HLASimpleDataAttribute), false);
            foreach (HLASimpleDataAttribute simpleData in simpleDataArray)
            {
                //TODO Check that the corresponding native type is OK (size, etc.)
                simpleDataMap.Add(simpleData.Name, simpleData.SimpleDataInfo);
            }

            HLAArrayDataAttribute[] arrayDataArray = (HLAArrayDataAttribute[])assembly.GetCustomAttributes(typeof(HLAArrayDataAttribute), false);
            foreach (HLAArrayDataAttribute arrayData in arrayDataArray)
            {
                arrayDataMap.Add(arrayData.Name, arrayData.ArrayDataInfo);
            }

            // we process ONLY the visible types.
            Type[] Types = assembly.GetExportedTypes();

            // Display all the types contained in the specified assembly.
            foreach (Type oType in Types)
            {
                HLAObjectClassAttribute objectClass = (HLAObjectClassAttribute)System.Attribute.GetCustomAttribute(oType, typeof(HLAObjectClassAttribute));
                if (objectClass != null)
                {
                    ObjectClassDescriptor ocd = new ObjectClassDescriptor(objectClass.ObjectClassInfo, new XRTIObjectClassHandle(handleCounter++), new List<ObjectClassDescriptor>());

                    foreach (PropertyInfo propInfo in oType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
                    {
                        HLAAttributeAttribute[] arrayOfCustomAttributes = (HLAAttributeAttribute[])propInfo.GetCustomAttributes(typeof(HLAAttributeAttribute), false);
                        foreach (HLAAttributeAttribute custumAttr in arrayOfCustomAttributes)
                        {
                            ocd.AddAttributeDescriptor(new AttributeDescriptor(custumAttr.AttributeInfo, new XRTIAttributeHandle(handleCounter++), new XRTIDimensionHandleSet()));
                        }

                    }
                    AddObjectClassDescriptor(ocd);
                }

                HLASimpleDataAttribute simpleDataAttr = (HLASimpleDataAttribute)System.Attribute.GetCustomAttribute(oType, typeof(HLASimpleDataAttribute));
                if (simpleDataAttr != null)
                {
                    simpleDataAttr.NativeType = oType;
                    simpleDataMap.Add(simpleDataAttr.Name, simpleDataAttr.SimpleDataInfo);
                }

                HLAFixedRecordDataAttribute fixedRecordDataAttr = (HLAFixedRecordDataAttribute)System.Attribute.GetCustomAttribute(oType, typeof(HLAFixedRecordDataAttribute));
                if (fixedRecordDataAttr != null)
                {
                    fixedRecordDataAttr.NativeType = oType;
                    foreach (FieldInfo fieldInfo in oType.GetFields())
                    {
                        HLARecordFieldAttribute[] recordFieldAttrs = (HLARecordFieldAttribute[])fieldInfo.GetCustomAttributes(typeof(HLARecordFieldAttribute), false);
                        foreach (HLARecordFieldAttribute field in recordFieldAttrs)
                        {
                            fixedRecordDataAttr.FixedRecordDataInfo.RecordFields.Add(field.RecordFieldInfo);
                        }
                    }
                    fixedRecordDataMap.Add(fixedRecordDataAttr.Name, fixedRecordDataAttr.FixedRecordDataInfo);
                }

                HLAEnumeratedDataAttribute enumerateDataAttr = (HLAEnumeratedDataAttribute)System.Attribute.GetCustomAttribute(oType, typeof(HLAEnumeratedDataAttribute));
                if (enumerateDataAttr != null)
                {
                    enumerateDataAttr.NativeType = oType;
                    string[] names = Enum.GetNames(oType);
                    Array values = Enum.GetValues(oType);

                    for (int i = 0; i < names.Length; i++)
                    {
                        HLAEnumerator enumerator = new HLAEnumerator();
                        enumerator.Name = names[i];
                        enumerator.Values = ((int)(values.GetValue(i))).ToString();
                        enumerateDataAttr.EnumeratedDataInfo.Enumerators.Add(enumerator);
                    }
                    enumeratedDataMap.Add(enumerateDataAttr.Name, enumerateDataAttr.EnumeratedDataInfo);
                }

                EventInfo[] events = oType.GetEvents(BindingFlags.Public | BindingFlags.Static);
                foreach (EventInfo eventInfo in events)
                {
                    HLAInteractionClassAttribute[] interactionAttrs = (HLAInteractionClassAttribute[])eventInfo.GetCustomAttributes(typeof(HLAInteractionClassAttribute), false);
                    if (interactionAttrs.Length != 0)
                    {
                        foreach (HLAInteractionClassAttribute interacAttr in interactionAttrs)
                        {
                            InteractionClassDescriptor icd = new InteractionClassDescriptor(interacAttr.InteractionClassInfo, new XRTIInteractionClassHandle(handleCounter++));
                            Type delegateType = eventInfo.EventHandlerType;
                            MethodInfo invoke = delegateType.GetMethod("Invoke");
                            ParameterInfo[] pars = invoke.GetParameters();
                            foreach (ParameterInfo p in pars)
                            {
                                HLAInteractionParameterAttribute[] interactionParams = (HLAInteractionParameterAttribute[])p.GetCustomAttributes(typeof(HLAInteractionParameterAttribute), false);
                                if (interactionParams.Length >= 0)
                                    icd.AddParameterDescriptor(new ParameterDescriptor(interactionParams[0].ParameterInfo, new XRTIParameterHandle(handleCounter++)));
                                else
                                    icd.AddParameterDescriptor(new ParameterDescriptor(p.Name, new XRTIParameterHandle(handleCounter++)));
                            }
                            AddInteractionClassDescriptor(icd);
                        }
                    }
                }
            }
        }