Exemple #1
0
        /// <summary> 
        /// Generates an object instance proxy source file.
        /// </summary>
        /// <param name="classElement">the object instance class element containing the relevant
        /// information
        /// </param>
        /// <param name="superClassName">the name of the proxy superclass
        /// </param>
        /// <exception cref=""> TypeConflictException if a type conflict is detected
        /// </exception>
        private void GenerateObjectInstanceProxy(System.IO.StreamWriter stream, List<string> generatedObjectClass, ObjectClassDescriptor objDescriptor, String superClassName)
        {
            if (objDescriptor == null)
            {
                return;
            }
            else if (objDescriptor.ParentDescriptors.Count != 0)
            {
                ObjectClassDescriptor parentDescriptor = objDescriptor.ParentDescriptors[0];
                if (!generatedObjectClass.Contains(parentDescriptor.Name))
                    GenerateObjectClassInterface(stream, generatedObjectClass, parentDescriptor, superClassName);
            }

            generatedObjectClass.Add(objDescriptor.Name);
            try
            {
                System.IO.StreamWriter sw;
                int indentLevel = 0;
                string indentStr = GenerateIndentString(indentLevel);

                String className = objDescriptor.Name + "";
                String qualifiedClassName = packagePrefix + className;
                if (stream == null)
                {
                    String path = qualifiedClassName.Replace('.', '/') + ".cs";

                    System.IO.FileInfo sourceFile = new System.IO.FileInfo(targetDirectory.FullName + "\\" + path);
                    System.IO.Directory.CreateDirectory(new System.IO.FileInfo(sourceFile.DirectoryName).FullName);

                    System.IO.FileStream fos = new System.IO.FileStream(sourceFile.FullName, System.IO.FileMode.Create);
                    sw = new System.IO.StreamWriter(fos);

                    System.String packageName = GetPackageName(qualifiedClassName);

                    if (packageName != null)
                    {
                        sw.WriteLine(indentStr + "namespace " + packageName + ";");
                    }
                    else
                    {
                        sw.WriteLine(indentStr + "namespace Sxta.Rti1516.Proxies");
                    }
                    sw.WriteLine(indentStr + "{");
                    indentLevel++;
                    indentStr = GenerateIndentString(indentLevel);
                    sw.WriteLine();
                    sw.WriteLine(indentStr + "using System;");
                    sw.WriteLine(indentStr + "using System.IO;");
                    sw.WriteLine(indentStr + "using System.Collections.Generic;");
                    sw.WriteLine();
                    sw.WriteLine(indentStr + "using Hla.Rti1516;");
                    sw.WriteLine();
                    sw.WriteLine(indentStr + "using Hla.Rti1516;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Serializers.XrtiEncoding;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Reflection;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Interactions;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.BoostrapProtocol;");

                    if (!string.IsNullOrEmpty(superClassName) && superClassName.Equals("ObjectInstanceProxy"))
                    {
                        sw.WriteLine(indentStr + "using ObjectInstanceProxy = Sxta.Rti1516.XrtiUtils.ObjectInstanceProxy;");
                    }
                    else
                    {
                        String qualifiedSuperClassName = packagePrefix + superClassName;
                        String superClassPackage = GetPackageName(qualifiedSuperClassName);

                        if ((packageName == null && superClassPackage != null) ||
                            (packageName != null && superClassPackage == null) ||
                            (packageName != null && superClassPackage != null &&
                            !packageName.Equals(superClassPackage)))
                        {
                            sw.WriteLine(indentStr + "using " + qualifiedSuperClassName + ";");
                        }
                    }

                }
                else
                {
                    sw = stream;
                }
                sw.WriteLine();

                if (!string.IsNullOrEmpty(objDescriptor.objectDescription.Semantics))
                {
                    PrintClassComment(sw, objDescriptor.objectDescription.Semantics, indentLevel);
                }
                else
                {
                    PrintClassComment(sw, "Autogenerated object instance proxy.", indentLevel);
                }
                GenerateHLAObjectClassAttribute(indentLevel, sw, objDescriptor);
                if (string.IsNullOrEmpty(superClassName))
                {
                    sw.WriteLine(indentStr + "public class " + className + " : " + " I" + objDescriptor.Name);
                    if (objDescriptor.ParentDescriptors.Count > 0)
                    {
                        foreach (ObjectClassDescriptor parent in objDescriptor.ParentDescriptors)
                        {
                            if (!parent.Name.Equals(superClassName))
                            {
                                sw.WriteLine(",");
                                sw.Write("                 " + Spacer(objDescriptor.Name) + "         " + GetInterfaceName(parent.Name));
                            }
                        }
                    }

                }
                else
                {
                    sw.WriteLine(indentStr + "public class " + className + " : " + superClassName + " , I" + objDescriptor.Name);
                    foreach (ObjectClassDescriptor parent in objDescriptor.ParentDescriptors)
                    {
                        if (!parent.Name.Equals(superClassName))
                        {
                            sw.WriteLine(",");
                            sw.Write("                 " + Spacer(objDescriptor.Name) + "         " + GetInterfaceName(parent.Name));
                        }
                    }
                    sw.WriteLine("                 " + Spacer(objDescriptor.Name) + "         " + " , I" + objDescriptor.Name);
                }
                sw.WriteLine(indentStr + "{");
                sw.WriteLine();
                indentLevel++;
                indentStr = GenerateIndentString(indentLevel);

                foreach (AttributeDescriptor attrDescriptor in objDescriptor.AttributeDescriptors)
                {
                    System.String attribute = attrDescriptor.Name;
                    if (!string.IsNullOrEmpty(NativeTypeForDataType(attrDescriptor.attribute.DataType)))
                    {
                        if (!string.IsNullOrEmpty(attrDescriptor.attribute.Semantics))
                        {
                            PrintVariableComment(sw, attrDescriptor.attribute.Semantics, indentLevel);
                        }
                        else
                        {
                            PrintVariableComment(sw, "Attribute #" + attrDescriptor.Name + ".", indentLevel);
                        }

                        sw.WriteLine(indentStr + "private " + NativeTypeForDataType(attrDescriptor.attribute.DataType) + " " + BuildFieldName(attrDescriptor.Name, className) + ";");
                        sw.WriteLine();
                    }
                }

                //----------------------------------------
                // FixedRecordDataType.ToString
                //----------------------------------------

                sw.WriteLine(indentStr + "///<summary> Returns a string representation of this " + className + ". </summary>");
                sw.WriteLine(indentStr + "///<returns> a string representation of this " + className + "</returns>");
                sw.WriteLine(indentStr + "public override String ToString()");
                sw.WriteLine(indentStr + "{");
                indentLevel++;
                indentStr = GenerateIndentString(indentLevel);

                sw.WriteLine(indentStr + "return \"" + className + "(\" +");

                bool first = true;

                for (int i = 0; i < objDescriptor.AttributeDescriptors.Count; i++)
                {
                    IHLAattribute field = objDescriptor.AttributeDescriptors[i].attribute;

                    System.String nativeType = NativeTypeForDataType(field.DataType);
                    string nativefieldName = BuildFieldName(field.Name, className);

                    if (nativeType != null)
                    {
                        if (!first)
                        {
                            sw.WriteLine(" + \", \" +");
                        }
                        else
                        {
                            first = false;
                        }

                        sw.Write(indentStr + "         \"" + field.Name + ": \" + " + nativefieldName);
                    }
                }

                if (!first)
                {
                    sw.WriteLine(" + ");
                }
                sw.WriteLine(indentStr + "       \")\";");
                indentLevel--;
                indentStr = GenerateIndentString(indentLevel);
                sw.WriteLine(indentStr + "}");

                //----------------------------------------
                // FixedRecordDataType.Attributes (Gets/Sets)
                //----------------------------------------

                for (int i = 0; i < objDescriptor.AttributeDescriptors.Count; i++)
                {
                    AttributeDescriptor attrDescrip = objDescriptor.AttributeDescriptors[i];
                    IHLAattribute field = attrDescrip.attribute;

                    System.String fieldName = BuildFieldName(field.Name, className);
                    System.String capitalizedFieldName = BuildPropertyName(field.Name, className);
                    System.String fieldType = field.DataType;
                    System.String fieldNativeType = NativeTypeForDataType(fieldType);

                    if (fieldNativeType != null)
                    {
                        sw.WriteLine();
                        sw.WriteLine(indentStr + "///<summary>");
                        sw.WriteLine(indentStr + "/// Gets/Sets the value of the " + field.Name + " field.");
                        sw.WriteLine(indentStr + "///</summary>");
                        GenerateHLAAttributeAttribute(indentLevel, sw, attrDescrip);
                        sw.WriteLine(indentStr + "public " + fieldNativeType + " " + capitalizedFieldName);
                        sw.WriteLine(indentStr + "{");
                        sw.WriteLine(indentStr + "    set {" + fieldName + " = value; }");
                        sw.WriteLine(indentStr + "    get { return " + fieldName + "; }");
                        sw.WriteLine(indentStr + "}");
                        sw.WriteLine();

                    }
                }

                indentLevel--;
                indentStr = GenerateIndentString(indentLevel);
                sw.WriteLine(indentStr + "}");

                if (stream == null)
                {
                    indentLevel--;
                    indentStr = GenerateIndentString(indentLevel);
                    sw.WriteLine(indentStr + "}");
                    sw.Flush();
                    sw.Close();
                }
            }
            catch (System.IO.IOException ioe)
            {
                System.Console.Error.WriteLine("Error generating object instance proxy: " + ioe);
            }
        }
Exemple #2
0
        /// <summary> 
        /// Prints the set of serializers class for the Properties of the specified object class
        /// element.
        /// </summary>
        /// <param name="sw">the stream to print to
        /// </param>
        /// <param name="objectClassElement">the object class element to process
        /// </param>
        private void PrintObjectPropertiesSerializers(System.IO.StreamWriter stream, ObjectClassDescriptor objDescriptor, int originalIndentLevel)
        {
            foreach (AttributeDescriptor attr in objDescriptor.AttributeDescriptors)
            {
                System.IO.StreamWriter sw;
                int indentLevel = originalIndentLevel;
                string indentStr = GenerateIndentString(indentLevel);

                System.String attribute = attr.Name;
                System.String attributeType = attr.attribute.DataType;
                System.String attributeNativeType = NativeTypeForDataType(attributeType);
                string serializerName = objDescriptor.Name + "Property" + attribute;

                if (attributeNativeType != null)
                {
                    try
                    {
                        String qualifiedClassName = packagePrefix + serializerName;
                        if (stream == null)
                        {
                            String path = qualifiedClassName.Replace('.', '/') + ".cs";

                            System.IO.FileInfo sourceFile = new System.IO.FileInfo(targetDirectory.FullName + "\\" + path);
                            System.IO.Directory.CreateDirectory(new System.IO.FileInfo(sourceFile.DirectoryName).FullName);

                            System.IO.FileStream fos = new System.IO.FileStream(sourceFile.FullName, System.IO.FileMode.Create);
                            sw = new System.IO.StreamWriter(fos);

                            System.String packageName = GetPackageName(qualifiedClassName);

                            if (packageName != null)
                            {
                                sw.WriteLine(indentStr + "namespace " + packageName + ";");
                            }
                            else
                            {
                                sw.WriteLine(indentStr + "namespace Sxta.Rti1516.Proxies");
                            }
                            sw.WriteLine(indentStr + "{");
                            indentLevel++;
                            indentStr = GenerateIndentString(indentLevel);
                            sw.WriteLine();
                            sw.WriteLine(indentStr + "using System;");
                            sw.WriteLine(indentStr + "using System.IO;");
                            sw.WriteLine(indentStr + "using System.Collections.Generic;");
                            sw.WriteLine();
                            sw.WriteLine(indentStr + "using Hla.Rti1516;");
                            sw.WriteLine();
                            sw.WriteLine(indentStr + "using HlaEncodingReader = Sxta.Rti1516.Serializers.XrtiEncoding.HlaEncodingReader;");
                            sw.WriteLine(indentStr + "using HlaEncodingWriter = Sxta.Rti1516.Serializers.XrtiEncoding.HlaEncodingWriter;");
                            sw.WriteLine(indentStr + "using Sxta.Rti1516.Reflection;");
                            sw.WriteLine(indentStr + "using Sxta.Rti1516.Serializers.XrtiEncoding;");
                        }
                        else
                        {
                            sw = stream;
                        }
                        sw.WriteLine();
                        PrintClassComment(sw, "Autogenerated Serializer Helper. Serializes and deserializes " + objDescriptor.Name + "." + attribute + " parameters into and from HLA formats.", indentLevel);
                        sw.WriteLine(indentStr + "public class " + serializerName + "XrtiSerializer : BaseInteractionMessageXrtiSerializer");
                        sw.WriteLine(indentStr + "{");
                        indentLevel++;
                        indentStr = GenerateIndentString(indentLevel);
                        sw.WriteLine(indentStr + "///<summary>Constructor for the serializer of " + objDescriptor.Name + "." + attribute + " property.");
                        sw.WriteLine(indentStr + "/// </summary>");
                        sw.WriteLine(indentStr + "public " + serializerName + "XrtiSerializer(XrtiSerializerManager manager)");
                        sw.WriteLine(indentStr + ": base(manager)");
                        sw.WriteLine(indentStr + "{");
                        sw.WriteLine(indentStr + "}");
                        sw.WriteLine();

                        sw.WriteLine(indentStr + "///<summary>");
                        sw.WriteLine(indentStr + "/// Writes this " + objDescriptor.Name + "." + attribute + " to the specified stream.");
                        sw.WriteLine(indentStr + "///</summary>");
                        sw.WriteLine(indentStr + "///<param name=\"writer\"> the output stream to write to</param>");
                        sw.WriteLine(indentStr + "///<param name=\"" + attribute + "\"> the property to serialize</param>");
                        sw.WriteLine(indentStr + "///<exception cref=\"System.IO.IOException\"> if an error occurs</exception>");
                        sw.WriteLine(indentStr + "public override void Serialize(HlaEncodingWriter writer, object " + attribute + ")");
                        sw.WriteLine(indentStr + "{");
                        indentLevel++;
                        indentStr = GenerateIndentString(indentLevel);

                        sw.WriteLine(indentStr + "try");
                        sw.WriteLine(indentStr + "{");

                        PrintSerializationBlock(sw, indentLevel + 1, 'i', attributeType, "(" + attributeNativeType + ")" + attribute, "writer");

                        sw.WriteLine(indentStr + "}");
                        sw.WriteLine(indentStr + "catch(IOException ioe)");
                        sw.WriteLine(indentStr + "{");
                        sw.WriteLine(GenerateIndentString(indentLevel + 1) + "throw new RTIinternalError(ioe.ToString());");
                        sw.WriteLine(indentStr + "}");
                        sw.WriteLine();

                        indentLevel--;
                        indentStr = GenerateIndentString(indentLevel);
                        sw.WriteLine(indentStr + "}");
                        sw.WriteLine();

                        sw.WriteLine(indentStr + "///<summary>");
                        sw.WriteLine(indentStr + "/// Reads and returns a " + objDescriptor.Name + "." + attribute + " from the specified stream.");
                        sw.WriteLine(indentStr + "///</summary>");
                        sw.WriteLine(indentStr + "///<param name=\"reader\"> the input stream to read from</param>");
                        sw.WriteLine(indentStr + "///<param name=\"dummy\"> this parameter is not used</param>");
                        sw.WriteLine(indentStr + "///<returns> the decoded value</returns>");
                        sw.WriteLine(indentStr + "///<exception cref=\"System.IO.IOException\"> if an error occurs</exception>");
                        sw.WriteLine(indentStr + "public override object Deserialize(HlaEncodingReader reader, ref object dummy)");
                        sw.WriteLine(indentStr + "{");
                        indentLevel++;
                        indentStr = GenerateIndentString(indentLevel);

                        sw.WriteLine(indentStr + attributeNativeType + " decodedValue;");
                        sw.WriteLine(indentStr + "try");
                        sw.WriteLine(indentStr + "{");
                        PrintDeserializationBlock(sw, indentLevel + 1, 'i', attributeType, "decodedValue", "reader");
                        sw.WriteLine(GenerateIndentString(indentLevel + 1) + "return decodedValue;");
                        sw.WriteLine(indentStr + "}");
                        sw.WriteLine(indentStr + "catch(IOException ioe)");
                        sw.WriteLine(indentStr + "{");
                        sw.WriteLine(GenerateIndentString(indentLevel + 1) + "throw new FederateInternalError(ioe.ToString());");
                        sw.WriteLine(indentStr + "}");

                        indentLevel--;
                        indentStr = GenerateIndentString(indentLevel);
                        sw.WriteLine(indentStr + "}");

                        indentLevel--;
                        indentStr = GenerateIndentString(indentLevel);
                        sw.WriteLine(indentStr + "}");

                        if (stream == null)
                        {
                            indentLevel--;
                            indentStr = GenerateIndentString(indentLevel);
                            sw.WriteLine(indentStr + "}");
                            sw.Flush();
                            sw.Close();
                        }
                    }
                    catch (System.IO.IOException ioe)
                    {
                        System.Console.Error.WriteLine("Error generating object properties serializers: " + ioe);
                    }
                }
            }
        }
 /// <summary> Adds a parent descriptor.
 ///
 /// </summary>
 /// <param name="pd">the parent descriptor to Add
 /// </param>
 public virtual void AddParentDescriptor(ObjectClassDescriptor od)
 {
     this.parentDescriptors.Add(od);
 }
Exemple #4
0
        /// <summary> 
        /// Generates all the object class interfaces.
        /// </summary>
        private void GenerateObjectClassInterface(System.IO.StreamWriter stream, List<string> generatedObjectClass, ObjectClassDescriptor objDescriptor, String superInterfaceName)
        {
            if (objDescriptor == null)
            {
                return;
            }
            else if (objDescriptor.ParentDescriptors.Count != 0)
            {
                ObjectClassDescriptor parentDescriptor = objDescriptor.ParentDescriptors[0];
                if (!generatedObjectClass.Contains(parentDescriptor.Name))
                    GenerateObjectClassInterface(stream, generatedObjectClass, parentDescriptor, superInterfaceName);
            }

            generatedObjectClass.Add(objDescriptor.Name);
            try
            {
                System.IO.StreamWriter sw;
                int indentLevel = 0;
                string indentStr = GenerateIndentString(indentLevel);
                String interfaceName = GetInterfaceName(objDescriptor.Name);
                String qualifiedInterfaceName = packagePrefix + interfaceName;

                if (stream == null)
                {
                    String path = qualifiedInterfaceName.Replace('.', '/') + ".cs";

                    System.IO.FileInfo sourceFile = new System.IO.FileInfo(targetDirectory.FullName + "\\" + path);
                    System.IO.Directory.CreateDirectory(new System.IO.FileInfo(sourceFile.DirectoryName).FullName);
                    System.IO.FileStream fos = new System.IO.FileStream(sourceFile.FullName, System.IO.FileMode.Create);
                    sw = new System.IO.StreamWriter(fos);

                    System.String packageName = GetPackageName(qualifiedInterfaceName);

                    if (packageName != null)
                    {
                        sw.WriteLine(indentStr + "namespace " + packageName + ";");
                    }
                    else
                    {
                        sw.WriteLine(indentStr + "namespace Sxta.Rti1516.Proxies");
                    }
                    sw.WriteLine(indentStr + "{");
                    indentLevel++;
                    indentStr = GenerateIndentString(indentLevel);

                    sw.WriteLine(indentStr + "using System;");
                    sw.WriteLine();
                    sw.WriteLine(indentStr + "using Hla.Rti1516;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Reflection;");
                }
                else
                {
                    sw = stream;
                }
                sw.WriteLine();

                PrintClassComment(sw, " Autogenerated object instance interface.", indentLevel);
                //GenerateHLAObjectClassAttribute(indentLevel, sw, interactionDescriptor);
                if (superInterfaceName != null)
                {
                    sw.Write(indentStr + "public interface " + interfaceName + " : " + superInterfaceName);

                    if (objDescriptor.ParentDescriptors.Count > 0)
                    {
                        foreach (ObjectClassDescriptor parent in objDescriptor.ParentDescriptors)
                        {
                            if (!parent.Name.Equals(superInterfaceName))
                            {
                                sw.WriteLine(",");
                                sw.Write("                 " + Spacer(interfaceName) + "         " + GetInterfaceName(parent.Name));
                            }
                        }
                    }
                }
                else
                {
                    sw.Write(indentStr + "public interface " + interfaceName);

                    if (objDescriptor.ParentDescriptors.Count > 0)
                    {
                        sw.Write(" : ");

                        ObjectClassDescriptor parent;
                        int length = objDescriptor.ParentDescriptors.Count;
                        for (int i = 0; i < length; i++)
                        {
                            parent = objDescriptor.ParentDescriptors[i];
                            sw.Write(GetInterfaceName(parent.Name));

                            if (i < length - 1)
                            {
                                sw.WriteLine(",");
                                sw.Write("                 " + Spacer(interfaceName) + "         ");
                            }
                        }
                    }
                }
                sw.WriteLine();
                sw.WriteLine(indentStr + "{");
                indentLevel++;
                indentStr = GenerateIndentString(indentLevel);

                foreach (AttributeDescriptor attributeDescriptor in objDescriptor.AttributeDescriptors)
                {
                    String attribute = attributeDescriptor.Name;
                    String capitalizedAttribute = BuildPropertyName(attribute, interfaceName);
                    String attributeType = attributeDescriptor.attribute.DataType;
                    String attributeNativeType = NativeTypeForDataType(attributeType);

                    if (attributeNativeType != null)
                    {
                        sw.WriteLine();
                        sw.WriteLine(indentStr + "///<summary>Gets/Sets the value of the " + attributeDescriptor.Name + " attribute.</summary>");
                        //GenerateHLAAttributeAttribute(indentLevel, sw, parameterDescriptor);
                        if (attributeNativeType.StartsWith("HLA") && !attributeNativeType.EndsWith("[]"))
                            sw.WriteLine(indentStr + attributeNativeType + " " + capitalizedAttribute);
                        else
                            sw.WriteLine(indentStr + attributeNativeType + " " + capitalizedAttribute);
                        sw.WriteLine(indentStr + "{");
                        sw.WriteLine(GenerateIndentString(indentLevel + 1) + "get;");
                        sw.WriteLine(GenerateIndentString(indentLevel + 1) + "set;");
                        sw.WriteLine(indentStr + "}");
                    }
                }

                indentLevel--;
                indentStr = GenerateIndentString(indentLevel);
                sw.WriteLine(indentStr + "}");

                if (stream == null)
                {
                    indentLevel--;
                    indentStr = GenerateIndentString(indentLevel);
                    sw.WriteLine(indentStr + "}");
                    sw.Flush();
                    sw.Close();
                }
            }
            catch (System.IO.IOException ioe)
            {
                if (log.IsErrorEnabled)
                    log.Error("Error generating object instance interface: " + ioe);
            }
        }
        /// <summary> 
        /// Prints the set of object class handle and Properties serialization helpers for the specified object class
        /// element and its sub-elements.
        /// </summary>
        /// <param name="sw">the stream to print to
        /// </param>
        /// <param name="objectClassElement">the object class element to process
        /// </param>
        /// <exception cref=""> TypeConflictException if a type conflict is detected
        /// </exception>
        private void PrintObjectClassSerializerRegistration(System.IO.StreamWriter ps, int indentLevel, ObjectClassDescriptor objDescriptor)
        {
            string indentStr = GenerateIndentString(indentLevel);
            ps.WriteLine();
            bool firstTime = true;
            foreach (AttributeDescriptor attr in objDescriptor.AttributeDescriptors)
            {
                System.String attribute = attr.Name;
                System.String attributeType = attr.attribute.DataType;
                System.String attributeNativeType = NativeTypeForDataType(attributeType);
                string serializerName = objDescriptor.Name + "Property" + attribute;

                if (attributeNativeType != null)
                {
                    if (firstTime)
                    {
                        ps.WriteLine(indentStr + "ocd = manager.DescriptorManager.GetObjectClassDescriptor(\"" + objDescriptor.Name + "\");");
                        firstTime = false;
                    }
                    ps.WriteLine(indentStr + "handle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor(\"" + attribute + "\").Handle).Identifier;");
                    ps.WriteLine(indentStr + "serializerMngr.RegisterSerializer(null, handle, new " + serializerName + "XrtiSerializer(serializerMngr));");
                    ps.WriteLine();
                }
            }
        }
 /// <summary> Notifies this object that an object class of interest has been
 /// added to the descriptor manager.
 ///
 /// </summary>
 /// <param name="ocd">the object class descriptor
 /// </param>
 protected internal virtual void ObjectClassAdded(ObjectClassDescriptor ocd)
 {
     parentDescriptors.Add(ocd);
 }
 /// <summary> Adds a parent descriptor.
 /// 
 /// </summary>
 /// <param name="pd">the parent descriptor to Add
 /// </param>
 public virtual void AddParentDescriptor(ObjectClassDescriptor od)
 {
     this.parentDescriptors.Add(od);
 }
        /// <summary> 
        /// Removes an object class descriptor.
        /// </summary>
        /// <param name="ocd">the object class descriptor to Remove
        /// </param>
        public virtual void RemoveObjectClassDescriptor(ObjectClassDescriptor ocd)
        {
            if (objectClassNameDescriptorMap[ocd.Name] == ocd)
            {
                objectClassNameDescriptorMap.Remove(ocd.Name);
            }

            if (objectClassHandleDescriptorMap[ocd.Handle] == ocd)
            {
                objectClassHandleDescriptorMap.Remove(ocd.Handle);
            }
            if (ocd.NativeName != null && objectNativeClassNameDescriptorMap[ocd.NativeName] == ocd)
            {
                objectNativeClassNameDescriptorMap.Remove(ocd.NativeName);
            }
        }
        // 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);
                        }
                    }
                }
            }
        }
 /// <summary>
 ///  Adds an object class descriptor.
 /// </summary>
 /// <param name="ocd">the object class descriptor to Add
 /// </param>
 public virtual void AddObjectClassDescriptor(ObjectClassDescriptor ocd)
 {
     if (!objectClassNameDescriptorMap.ContainsKey(ocd.Name))
     {
         // PATCH ANGEL
         if (classNameToNativeTypeMap.ContainsKey(ocd.Name))
             ocd.nativeName = classNameToNativeTypeMap[ocd.Name];
         // END PATCH
         objectClassNameDescriptorMap.Add(ocd.Name, ocd);
         objectClassHandleDescriptorMap.Add(ocd.Handle, ocd);
         if (ocd.NativeName != null)
             objectNativeClassNameDescriptorMap.Add(ocd.NativeName, ocd);
     }
     else
     {
         if (log.IsWarnEnabled)
             log.Warn("Object Class Descriptor " + ocd.Name + " already exists. Not replaced.");
     }
 }
        /// <summary> 
        /// Adds a set of descriptors corresponding to the features contained
        /// in the specified federation description document.  Handle
        /// values will be assigned in the order that the described features are
        /// encountered in the document, starting at <code>1</code>.
        /// </summary>
        /// <param name="fdd">the parsed federation description document to interpret
        /// </param>
        public virtual void AddDescriptors(System.Xml.XmlDocument fdd)
        {
            System.Xml.XmlElement documentElement = (System.Xml.XmlElement)fdd.DocumentElement;

            objectModel = new HLAObjectModel(documentElement);

            names.Add(objectModel.Name);

            System.String version = objectModel.Version;
            if (!string.IsNullOrEmpty(version))
            {
                SupportClass.Tokenizer st = new SupportClass.Tokenizer(version, " .");
                majorVersion = System.Int32.Parse(st.NextToken());
                minorVersion = System.Int32.Parse(st.NextToken());
            }

            // First pass creates descriptors, assigns handles

            System.Xml.XmlNodeList nl = documentElement.GetElementsByTagName("basicData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement basicDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLABasicData basicData = new HLABasicData(basicDataElement);
                basicDataMap[basicData.Name] = basicData;
            }

            nl = documentElement.GetElementsByTagName("simpleData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement simpleDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLASimpleData simpleData = new HLASimpleData(simpleDataElement);
                simpleDataMap[simpleData.Name] = simpleData;
            }
            nl = documentElement.GetElementsByTagName("enumeratedData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement enumeratedDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLAEnumeratedData enumeratedData = new HLAEnumeratedData(enumeratedDataElement);
                enumeratedDataMap[enumeratedData.Name] = enumeratedData;
            }
            nl = documentElement.GetElementsByTagName("fixedRecordData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement fixedRecordDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLAFixedRecordData fixedRecordData = new HLAFixedRecordData(fixedRecordDataElement);
                fixedRecordDataMap[fixedRecordData.Name] = fixedRecordData;
            }
            nl = documentElement.GetElementsByTagName("arrayData");
            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement arrayDataElement = (System.Xml.XmlElement)nl.Item(i);
                HLAarrayDataType arrayData = new HLAarrayDataType(arrayDataElement);
                arrayDataMap[arrayData.Name] = arrayData;
            }

            nl = documentElement.GetElementsByTagName(OBJECT_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement objectClassElement = (System.Xml.XmlElement)nl.Item(i);

                ObjectClassDescriptor ocd = new ObjectClassDescriptor(objectClassElement, new XRTIObjectClassHandle(handleCounter++), new List<ObjectClassDescriptor>());
                System.Xml.XmlNodeList nl2 = objectClassElement.ChildNodes;
                for (int j = 0; j < nl2.Count; j++)
                {
                    if (nl2.Item(j) is System.Xml.XmlElement && nl2.Item(j).Name.Equals(ATTRIBUTE))
                    {
                        System.Xml.XmlElement attributeElement = (System.Xml.XmlElement)nl2.Item(j);

                        AttributeDescriptor ad = new AttributeDescriptor(attributeElement, new XRTIAttributeHandle(handleCounter++), new XRTIDimensionHandleSet(), "HLAreliable".Equals(attributeElement.GetAttribute(TRANSPORTATION)) ? TransportationType.HLA_RELIABLE : TransportationType.HLA_BEST_EFFORT, "Receive".Equals(attributeElement.GetAttribute(ORDER)) ? Hla.Rti1516.OrderType.RECEIVE : OrderType.TIMESTAMP);
                        ocd.AddAttributeDescriptor(ad);

                        // PATCH ANGEL
                        AddAttributeDescriptor(ad);
                    }
                }

                AddObjectClassDescriptor(ocd);
            }

            nl = documentElement.GetElementsByTagName(INTERACTION_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement interactionClassElement = (System.Xml.XmlElement)nl.Item(i);

                InteractionClassDescriptor icd = new InteractionClassDescriptor(interactionClassElement, new XRTIInteractionClassHandle(handleCounter++), new List<InteractionClassDescriptor>(), new XRTIDimensionHandleSet(), "HLAreliable".Equals(interactionClassElement.GetAttribute(TRANSPORTATION)) ? TransportationType.HLA_RELIABLE : TransportationType.HLA_BEST_EFFORT, "Receive".Equals(interactionClassElement.GetAttribute(ORDER)) ? Sxta.Rti1516.Reflection.HLAorderType.Receive : Sxta.Rti1516.Reflection.HLAorderType.TimeStamp);

                System.Xml.XmlNodeList nl2 = interactionClassElement.ChildNodes;

                for (int j = 0; j < nl2.Count; j++)
                {
                    if (nl2.Item(j) is System.Xml.XmlElement && nl2.Item(j).Name.Equals(PARAMETER))
                    {
                        System.Xml.XmlElement parameterElement = (System.Xml.XmlElement)nl2.Item(j);

                        icd.AddParameterDescriptor(new ParameterDescriptor(parameterElement, new XRTIParameterHandle(handleCounter++)));
                    }
                }

                AddInteractionClassDescriptor(icd);
            }

            nl = documentElement.GetElementsByTagName(DIMENSION);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement dimensionElement = (System.Xml.XmlElement)nl.Item(i);

                long upperBound = System.Int64.MaxValue;

                if (dimensionElement.HasAttribute(UPPER_BOUND))
                {
                    try
                    {
                        upperBound = System.Int64.Parse(dimensionElement.GetAttribute(UPPER_BOUND));
                    }
                    catch (System.FormatException)
                    {
                    }
                }
                AddDimensionDescriptor(new DimensionDescriptor(dimensionElement.GetAttribute(NAME), new XRTIDimensionHandle(handleCounter++), upperBound));
            }

            // Second pass resolves parents, dimensions

            nl = documentElement.GetElementsByTagName(OBJECT_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement objectClassElement = (System.Xml.XmlElement)nl.Item(i);

                ObjectClassDescriptor ocd = GetObjectClassDescriptor(objectClassElement.GetAttribute(NAME));

                if (objectClassElement.ParentNode.Name.Equals(OBJECT_CLASS))
                {
                    ocd.AddParentDescriptor(GetObjectClassDescriptor(((System.Xml.XmlElement)objectClassElement.ParentNode).GetAttribute(NAME)));
                }

                if (objectClassElement.HasAttribute(PARENTS))
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(objectClassElement.GetAttribute(PARENTS));

                    // PATCH ANGEL while (st.HasMoreTokens())
                    //{
                    ocd.ParentDescriptors.Add(GetObjectClassDescriptor(st.NextToken()));
                    //}
                }

                System.Xml.XmlNodeList nl2 = objectClassElement.ChildNodes;
                for (int j = 0; j < nl2.Count; j++)
                {
                    if (nl2.Item(j) is System.Xml.XmlElement && nl2.Item(j).Name.Equals(ATTRIBUTE))
                    {
                        System.Xml.XmlElement attributeElement = (System.Xml.XmlElement)nl2.Item(j);

                        if (attributeElement.HasAttribute(DIMENSIONS))
                        {
                            AttributeDescriptor ad = ocd.GetAttributeDescriptor(attributeElement.GetAttribute(NAME));

                            SupportClass.Tokenizer st = new SupportClass.Tokenizer(attributeElement.GetAttribute(DIMENSIONS));

                            // PATCH ANGEL while (st.HasMoreTokens())
                            //{
                            System.String dimension = st.NextToken();

                            if (!dimension.Equals("NA"))
                            {
                                ad.Dimensions.Add(GetDimensionDescriptor(dimension).Handle);
                            }
                            //}
                        }
                    }
                }
            }

            nl = documentElement.GetElementsByTagName(INTERACTION_CLASS);

            for (int i = 0; i < nl.Count; i++)
            {
                System.Xml.XmlElement interactionClassElement = (System.Xml.XmlElement)nl.Item(i);

                InteractionClassDescriptor icd = GetInteractionClassDescriptor(interactionClassElement.GetAttribute(NAME));

                if (interactionClassElement.HasAttribute(DIMENSIONS))
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(interactionClassElement.GetAttribute(DIMENSIONS));

                    // PATCH ANGEL while (st.HasMoreTokens())
                    //{
                    System.String dimension = st.NextToken();

                    if (!dimension.Equals("NA"))
                    {
                        icd.Dimensions.Add(GetDimensionDescriptor(dimension).Handle);
                    }
                    //}
                }

                if (interactionClassElement.ParentNode.Name.Equals(INTERACTION_CLASS))
                {
                    icd.AddParentDescriptor(GetInteractionClassDescriptor(((System.Xml.XmlElement)interactionClassElement.ParentNode).GetAttribute(NAME)));
                }

                if (interactionClassElement.HasAttribute(PARENTS))
                {
                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(interactionClassElement.GetAttribute(PARENTS));

                    // PATCH ANGEL while (st.HasMoreTokens())
                    //{
                    icd.AddParentDescriptor(GetInteractionClassDescriptor(st.NextToken()));
                    //}
                }
            }

            //PATCH ANGEL CheckAopFdd();
        }
        /// <summary> 
        /// Adds a listener for object classes with a particular name.
        /// </summary>
        /// <param name="name">the object class name of interest
        /// </param>
        /// <param name="ocd">the object class descriptor to notify
        /// </param>
        protected internal virtual void AddObjectClassListener(System.String name, ObjectClassDescriptor ocd)
        {
            System.Collections.ArrayList v = objectClassNameListenersMap[name];

            if (v == null)
            {
                v = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                objectClassNameListenersMap[name] = v;
            }

            v.Add(ocd);
        }
 /// <summary>
 ///  Adds a listener for attributes with the specified handle.
 /// </summary>
 /// <param name="handle">the attribute handle of interest
 /// </param>
 /// <param name="ocd">the object class descriptor to notify
 /// </param>
 protected internal virtual void AddAttributeListener(IAttributeHandle handle, ObjectClassDescriptor ocd)
 {
     attributeHandleListenerMap[handle] = ocd;
 }
Exemple #14
0
        /// <summary> 
        /// Generates a <code>HLAObjectClassAttribute</code>.
        /// </summary>
        private void GenerateHLAObjectClassAttribute(int localIndentLevel, System.IO.StreamWriter ps, ObjectClassDescriptor objDescriptor)
        {
            string indentStr = GenerateIndentString(localIndentLevel);
            string newLine = "," + Environment.NewLine + indentStr + "                ";
            ps.Write(indentStr + "[HLAObjectClass(Name = \"" + objDescriptor.Name + "\"");
            ps.Write(newLine);
            ps.Write("Sharing = " + objDescriptor.objectDescription.Sharing.GetType() + "." + objDescriptor.objectDescription.Sharing);

            if (!String.IsNullOrEmpty(objDescriptor.objectDescription.SharingNotes))
            {
                ps.Write(newLine);
                ps.Write("SharingNotes = \"" + objDescriptor.objectDescription.SharingNotes + "\"");
            }
            if (!String.IsNullOrEmpty(objDescriptor.objectDescription.Semantics))
            {
                ps.Write(newLine);
                ps.Write("Semantics = \"" + objDescriptor.objectDescription.Semantics + "\"");
            }
            if (!String.IsNullOrEmpty(objDescriptor.objectDescription.SemanticsNotes))
            {
                ps.Write(newLine);
                ps.Write("SemanticsNotes = \"" + objDescriptor.objectDescription.SemanticsNotes + "\"");
            }
            if (!String.IsNullOrEmpty(objDescriptor.objectDescription.NameNotes))
            {
                ps.Write(newLine);
                ps.Write("NameNotes = \"" + objDescriptor.objectDescription.NameNotes + "\"");
            }
            ps.WriteLine(")]");
        }
 /// <summary> Notifies this object that an object class of interest has been
 /// added to the descriptor manager.
 /// 
 /// </summary>
 /// <param name="ocd">the object class descriptor
 /// </param>
 protected internal virtual void ObjectClassAdded(ObjectClassDescriptor ocd)
 {
     parentDescriptors.Add(ocd);
 }
 //protected Dictionary<long, HLAfederation> federations = new Dictionary<long, HLAfederation>();
 //protected IAttributeHandleValueMapFactory factory = new XRTIAttributeHandleValueMapFactory();
 public LowLevelManagementObjectModelInteractionListener(XrtiExecutiveAmbassador p, String aName)
     : base(aName)
 {
     parent = p;
     federationExecutionDescriptor = parent.descriptorManager.GetObjectClassDescriptor("HLAfederationExecution");
 }
        private TreeNode AddClassTreeNode2(TreeNode rootNode, ObjectClassDescriptor objDescriptor)
        {
            TreeNodeCollection parentNodes;
            if (objDescriptor == null)
            {
                TreeNode parentNode = FindNode(rootNode.Nodes, "HLAobjectRoot");
                if (parentNode == null)
                {
                    //tv.ImageList = imageList1;

                    parentNode = new TreeNode("HLAobjectRoot");
                    parentNode.Name = "HLAobjectRoot";
                    parentNode.ImageIndex = 0;
                    parentNode.SelectedImageIndex = 0;

                    //tv.Nodes.Add(parentNode);
                    rootNode.Nodes.Add(parentNode);
                }
                return parentNode;
            }
            else if (objDescriptor.ParentDescriptors.Count != 0)
            {
                TreeNode parentNode = AddClassTreeNode2(rootNode, objDescriptor.ParentDescriptors[0]);
                parentNodes = parentNode.Nodes;
            }
            else
                //parentNodes = tv.Nodes;
                parentNodes = rootNode.Nodes;

            TreeNode tmpNode = FindNode(parentNodes, objDescriptor.Name);
            if (tmpNode != null)
                return tmpNode;
            else
            {
                TreeNode node = new TreeNode(objDescriptor.Name);
                node.ImageIndex = 0;
                node.SelectedImageIndex = 0;
                HLAObjectClassPropertiesInformation nodeInfo = new HLAObjectClassPropertiesInformation(objDescriptor.objectDescription, null);
                node.Tag = nodeInfo;

                foreach (AttributeDescriptor attributeDescriptor in objDescriptor.AttributeDescriptors)
                {
                    TreeNode nodeAttr = new TreeNode(attributeDescriptor.Name);
                    HLAAttributePropertiesInformation nodeAttrInfo = new HLAAttributePropertiesInformation(attributeDescriptor.attribute, null);
                    nodeAttr.ImageIndex = 2;
                    nodeAttr.SelectedImageIndex = 2;
                    nodeAttr.Tag = nodeAttrInfo;
                    node.Nodes.Add(nodeAttr);
                }
                parentNodes.Add(node);

                return node;
            }
        }