예제 #1
0
        /// <summary> 
        /// Generates a <code>HLAInteractionClass</code>.
        /// </summary>
        private void GenerateHLAInteractionClassAttribute(int localIndentLevel, System.IO.StreamWriter ps, InteractionClassDescriptor interactionDescriptor)
        {
            string indentStr = GenerateIndentString(localIndentLevel);
            string newLine = "," + Environment.NewLine + indentStr + "                ";
            ps.Write(indentStr + "[HLAInteractionClass(Name = \"" + interactionDescriptor.Name + "\"");
            ps.Write(newLine);
            ps.Write("Sharing = " + interactionDescriptor.interactionClass.Sharing.GetType() + "." + interactionDescriptor.interactionClass.Sharing);
            ps.Write(newLine);
            ps.Write("Order = " + interactionDescriptor.interactionClass.Order.GetType() + "." + interactionDescriptor.interactionClass.Order);

            if (!String.IsNullOrEmpty(interactionDescriptor.interactionClass.SharingNotes))
            {
                ps.Write(newLine);
                ps.Write("SharingNotes = \"" + interactionDescriptor.interactionClass.SharingNotes + "\"");
            }
            if (!String.IsNullOrEmpty(interactionDescriptor.interactionClass.Semantics))
            {
                ps.Write(newLine);
                ps.Write("Semantics = \"" + interactionDescriptor.interactionClass.Semantics + "\"");
            }
            if (!String.IsNullOrEmpty(interactionDescriptor.interactionClass.SemanticsNotes))
            {
                ps.Write(newLine);
                ps.Write("SemanticsNotes = \"" + interactionDescriptor.interactionClass.SemanticsNotes + "\"");
            }
            if (!String.IsNullOrEmpty(interactionDescriptor.interactionClass.Dimensions))
            {
                ps.Write(newLine);
                ps.Write("Dimensions = \"" + interactionDescriptor.interactionClass.Dimensions + "\"");
            }
            if (!String.IsNullOrEmpty(interactionDescriptor.interactionClass.Transportation))
            {
                ps.Write(newLine);
                ps.Write("Transportation = \"" + interactionDescriptor.interactionClass.Transportation + "\"");
            }
            if (!String.IsNullOrEmpty(interactionDescriptor.interactionClass.NameNotes))
            {
                ps.Write(newLine);
                ps.Write("NameNotes = \"" + interactionDescriptor.interactionClass.NameNotes + "\"");
            }
            ps.WriteLine(")]");
        }
 /// <summary> 
 /// Notifies this object that an interaction class of interest has been
 /// added to the descriptor manager.
 /// </summary>
 /// <param name="icd">the interaction class descriptor
 /// </param>
 protected internal virtual void InteractionClassAdded(InteractionClassDescriptor icd)
 {
     parentDescriptors.Add(icd);
 }
 /// <summary>
 /// Adds a parent descriptor.
 /// </summary>
 /// <param name="pd">the parent descriptor to Add
 /// </param>
 public virtual void AddParentDescriptor(InteractionClassDescriptor pd)
 {
     this.parentDescriptors.Add(pd);
 }
예제 #4
0
        /// <summary> 
        /// Prints the receive interaction block for the specified interaction class
        /// element and its sub-elements.
        /// </summary>
        /// <param name="sw">the stream to print to
        /// </param>
        /// <param name="interaction">the interaction class element to process
        /// </param>
        /// <param name="first">whether or not this is the first block being printed
        /// </param>
        /// <returns> the new value for <code>first</code>: <code>true</code> if the first
        /// block has not been printed, <code>false</code> if it has been
        /// </returns>
        /// <exception cref=""> TypeConflictException if a type conflict is detected
        /// </exception>
        private bool PrintReceiveInteractionBlock(System.IO.StreamWriter ps, InteractionClassDescriptor interactionClass, string listener, bool first, int indentLevel)
        {
            string indentStr = GenerateIndentString(indentLevel);

            System.String interaction = interactionClass.Name;

            if (interactionClass.interactionClass.Sharing != HLAsharingType.Neither)
            {
                if (first)
                {
                    ps.WriteLine(indentStr + "if(msg is " + interaction + "Message)");

                    first = false;
                }
                else
                {
                    ps.WriteLine(indentStr + "else if(msg is " + interaction + "Message)");
                }

                ps.WriteLine(indentStr + "{");
                indentStr = GenerateIndentString(indentLevel + 1);
                ps.WriteLine(indentStr + "foreach(IInteractionListener il in manager.InteractionListeners)");
                ps.WriteLine(indentStr + "{");
                ps.WriteLine(GenerateIndentString(indentLevel + 2) + "if (il is " + listener + ")");
                ps.WriteLine(GenerateIndentString(indentLevel + 3) + "(il as " + listener + ").OnReceive" + interaction + "(msg as " + interaction + "Message);");
                ps.WriteLine(GenerateIndentString(indentLevel + 2) + "else");
                ps.WriteLine(GenerateIndentString(indentLevel + 3) + "il.ReceiveInteraction(msg);");
                ps.WriteLine(indentStr + "}"); //Foreach
                indentStr = GenerateIndentString(indentLevel);
                ps.WriteLine(indentStr + "}"); //if
            }
            return first;
        }
예제 #5
0
        /// <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 PrintInteractionClassSerializerRegistration(System.IO.StreamWriter ps, int indentLevel, InteractionClassDescriptor interactionDescriptor)
        {
            string indentStr = GenerateIndentString(indentLevel);

            String interactionMessageName = GetInteractionMessageName(interactionDescriptor.interactionClass.Name);
            String interactionMessageSerializer = interactionMessageName + "XrtiSerializer";

            ps.WriteLine();
            ps.WriteLine(indentStr + "objType = typeof(" + interactionMessageName + ");");
            ps.WriteLine(indentStr + "manager.AddReceiveInteractionDelegate(objType, \"" + interactionDescriptor.interactionClass.Name + "\", new InteractionManager.ReceiveInteractionDelegate(this.ReceiveInteraction));");
            ps.WriteLine(indentStr + "handle = ((XRTIInteractionClassHandle)manager.DescriptorManager.GetInteractionClassDescriptor(\"" + interactionDescriptor.interactionClass.Name + "\").Handle).Identifier;");
            ps.WriteLine(indentStr + "serializerMngr.RegisterSerializer(objType, handle, new " + interactionMessageSerializer + "(serializerMngr));");
        }
예제 #6
0
        /// <summary> 
        /// Generates Interactions Class serializers.
        /// </summary>
        private void GenerateInteractionsSerializers(System.IO.StreamWriter stream, List<string> generatedInteractiontList,
            InteractionClassDescriptor interactionClassDescriptor, string superInteractionName,
            int originalIndentLevel)
        {
            if (interactionClassDescriptor == null)
            {
                return;
            }
            else if (interactionClassDescriptor.ParentDescriptors.Count != 0)
            {
                InteractionClassDescriptor parentDescriptor = interactionClassDescriptor.ParentDescriptors[0];
                if (!generatedInteractiontList.Contains(parentDescriptor.Name))
                    GenerateInteractionsMessages(stream, generatedInteractiontList, parentDescriptor, superInteractionName);
            }
            generatedInteractiontList.Add(interactionClassDescriptor.Name);
            try
            {
                System.IO.StreamWriter sw;
                int indentLevel = originalIndentLevel;
                string indentStr = GenerateIndentString(indentLevel);
                HLAinteractionClass interactionClass = interactionClassDescriptor.interactionClass;
                String interaction = interactionClass.Name;
                List<ParameterDescriptor> parametersDescriptor = interactionClassDescriptor.ParameterDescriptors;
                String interactionMessageName = GetInteractionMessageName(interaction);
                String qualifiedInteractionName = packagePrefix + interactionMessageName + "XrtiSerializer";
                bool hasParent = true;
                if (stream == null)
                {
                    String path = qualifiedInteractionName.Replace('.', Path.DirectorySeparatorChar) + ".cs";

                    System.IO.FileInfo sourceFile = new System.IO.FileInfo(targetDirectory.FullName + Path.DirectorySeparatorChar + 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(qualifiedInteractionName);

                    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;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Serializers.XrtiEncoding;");
                }
                else
                {
                    sw = stream;
                }
                sw.WriteLine();
                //------------------------------------------ Generation of MessageSerializer -----------------------------------
                sw.WriteLine();
                sw.WriteLine(indentStr + "///<summary>");
                sw.Write(FormatCommentBody(indentLevel, "A HLA serializer for " + interactionMessageName + "."));
                sw.WriteLine(indentStr + "///</summary>");

                if (!String.IsNullOrEmpty(superInteractionName))
                {
                    sw.Write(indentStr + "public class " + interactionMessageName + "XrtiSerializer : " +
                                           GetInteractionMessageName(superInteractionName) + "XrtiSerializer");

                    if (interactionClassDescriptor.ParentDescriptors.Count > 0)
                    {
                        foreach (InteractionClassDescriptor parent in interactionClassDescriptor.ParentDescriptors)
                        {
                            if (!parent.Name.Equals(superInteractionName))
                            {
                                sw.WriteLine(",");
                                sw.Write("                 " + Spacer(interactionMessageName) + "         " +
                                    GetInteractionMessageName(parent.Name) + "XrtiSerializer");
                            }
                        }
                    }
                }
                else
                {
                    sw.Write(indentStr + "public class " + interactionMessageName + "XrtiSerializer");

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

                        InteractionClassDescriptor parent;
                        int length = interactionClassDescriptor.ParentDescriptors.Count;
                        for (int i = 0; i < length; i++)
                        {
                            parent = interactionClassDescriptor.ParentDescriptors[i];
                            sw.Write(GetInteractionMessageName(parent.Name) + "XrtiSerializer");

                            if (i < length - 1)
                            {
                                sw.WriteLine(",");
                                sw.Write("                 " + Spacer(interactionMessageName + "XrtiSerializer") + "         ");
                            }
                        }
                    }
                    else
                    {
                        sw.WriteLine(": BaseInteractionMessageXrtiSerializer");
                        hasParent = false;
                    }

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

                sw.WriteLine(indentStr + "///<summary> Constructor </summary>");
                sw.WriteLine(indentStr + "public " + interactionMessageName + "XrtiSerializer(XrtiSerializerManager manager)");
                sw.WriteLine(indentStr + ": base(manager)");
                sw.WriteLine(indentStr + "{");
                sw.WriteLine(indentStr + "}");
                sw.WriteLine();
                sw.WriteLine(indentStr + "///<summary> Writes this " + interactionMessageName + " to the specified stream.</summary>");
                sw.WriteLine(indentStr + "///<param name=\"writer\"> the output stream to write to</param>");
                sw.WriteLine(indentStr + "///<param name=\"obj\"> the object 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 obj)");
                sw.WriteLine(indentStr + "{");
                indentStr = GenerateIndentString(indentLevel + 1);
                if (parametersDescriptor.Count > 0)
                {
                    sw.WriteLine(indentStr + "try");
                    sw.WriteLine(indentStr + "{");
                    if (hasParent)
                        sw.WriteLine(GenerateIndentString(indentLevel + 2) + "base.Serialize(writer, obj);");

                    foreach (ParameterDescriptor parameter in interactionClassDescriptor.ParameterDescriptors)
                    {
                        System.String parameterName = parameter.Name;
                        System.String parameterType = parameter.DataType;
                        PrintSerializationBlock(sw, indentLevel + 2, 'i', parameterType, "((" + interactionMessageName + ") obj)." + BuildPropertyName(parameter.Name, interactionMessageName), "writer");
                    }
                    sw.WriteLine(indentStr + "}");
                    sw.WriteLine(indentStr + "catch(System.IO.IOException ioe)");
                    sw.WriteLine(indentStr + "{");
                    sw.WriteLine(GenerateIndentString(indentLevel + 2) + "throw new RTIinternalError(ioe.ToString());");
                    sw.WriteLine(indentStr + "}");
                }
                indentStr = GenerateIndentString(indentLevel);
                sw.WriteLine(indentStr + "}");
                sw.WriteLine();
                sw.WriteLine(indentStr + "///<summary> Reads this " + interactionMessageName + " from the specified stream.</summary>");
                sw.WriteLine(indentStr + "///<param name=\"reader\"> the input stream to read from</param>");
                sw.WriteLine(indentStr + "///<returns> the object</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 msg)");
                sw.WriteLine(indentStr + "{");
                indentStr = GenerateIndentString(indentLevel + 1);
                sw.WriteLine(indentStr + interactionMessageName + " decodedValue;");
                sw.WriteLine(indentStr + "if (!(msg is " + interactionMessageName + "))");
                sw.WriteLine(indentStr + "{");
                string indent2 = GenerateIndentString(indentLevel + 2);
                sw.WriteLine(indent2 + "decodedValue = new " + interactionMessageName + "();");
                sw.WriteLine(indent2 + "BaseInteractionMessage baseMsg = msg as BaseInteractionMessage;");
                sw.WriteLine(indent2 + "decodedValue.InteractionClassHandle = baseMsg.InteractionClassHandle;");
                sw.WriteLine(indent2 + "decodedValue.FederationExecutionHandle = baseMsg.FederationExecutionHandle;");
                sw.WriteLine(indent2 + "decodedValue.UserSuppliedTag = baseMsg.UserSuppliedTag;");
                sw.WriteLine(indentStr + "}");
                sw.WriteLine(indentStr + "else");
                sw.WriteLine(indentStr + "{");
                sw.WriteLine(indent2 + "decodedValue = msg as " + interactionMessageName + ";");
                sw.WriteLine(indentStr + "}");
                if (hasParent)
                {
                    sw.WriteLine(indentStr + "object tmp = decodedValue;");
                    sw.WriteLine(indentStr + "decodedValue = base.Deserialize(reader, ref tmp) as " + interactionMessageName + ";");
                    //sw.WriteLine(indentStr + interactionMessageName + " msg = (" + interactionMessageName + ") base.Deserialize(reader);");
                }
                else
                {
                    sw.WriteLine();
                    //sw.WriteLine(indentStr + interactionMessageName + " msg = new " + interactionMessageName + "();");
                }
                if (parametersDescriptor.Count > 0)
                {
                    sw.WriteLine(indentStr + "try");
                    sw.WriteLine(indentStr + "{");
                    foreach (ParameterDescriptor parameter in parametersDescriptor)
                    {
                        System.String parameterName = parameter.Name;
                        System.String parameterType = parameter.DataType;
                        PrintDeserializationBlock(sw, indentLevel + 2, 'i', parameterType, "decodedValue." + BuildPropertyName(parameter.Name, interactionMessageName), "reader");
                    }
                    sw.WriteLine(indentStr + "}");
                    sw.WriteLine(indentStr + "catch(System.IO.IOException ioe)");
                    sw.WriteLine(indentStr + "{");
                    sw.WriteLine(GenerateIndentString(indentLevel + 2) + "throw new RTIinternalError(ioe.ToString());");
                    sw.WriteLine(indentStr + "}");
                }
                sw.WriteLine(indentStr + "return decodedValue;");

                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)
            {
                if (log.IsErrorEnabled)
                    log.Error("Error generating object instance interface: " + ioe);
            }
        }
예제 #7
0
        /// <summary> 
        /// Generates Interactions Class.
        /// </summary>
        private void GenerateInteractionsMessages(System.IO.StreamWriter stream, List<string> generatedInteractiontList,
            InteractionClassDescriptor interactionClassDescriptor, string superInteractionName)
        {
            if (interactionClassDescriptor == null)
            {
                return;
            }
            else if (interactionClassDescriptor.ParentDescriptors.Count != 0)
            {
                InteractionClassDescriptor parentDescriptor = interactionClassDescriptor.ParentDescriptors[0];
                if (!generatedInteractiontList.Contains(parentDescriptor.Name))
                    GenerateInteractionsMessages(stream, generatedInteractiontList, parentDescriptor, superInteractionName);
            }
            generatedInteractiontList.Add(interactionClassDescriptor.Name);
            try
            {
                System.IO.StreamWriter sw;
                int indentLevel = 0;
                string indentStr = GenerateIndentString(indentLevel);
                HLAinteractionClass interactionClass = interactionClassDescriptor.interactionClass;
                String interaction = interactionClass.Name;
                List<ParameterDescriptor> parametersDescriptor = interactionClassDescriptor.ParameterDescriptors;
                String interactionMessageName = GetInteractionMessageName(interaction);
                String qualifiedInteractionName = packagePrefix + interactionMessageName;

                if (stream == null)
                {
                    String path = qualifiedInteractionName.Replace('.', Path.DirectorySeparatorChar) + ".cs";

                    System.IO.FileInfo sourceFile = new System.IO.FileInfo(targetDirectory.FullName + Path.DirectorySeparatorChar + 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(qualifiedInteractionName);

                    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;");
                    sw.WriteLine(indentStr + "using Sxta.Rti1516.Serializers.XrtiEncoding;");

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

                //------------------------------------------ Generation of Message -----------------------------------
                sw.WriteLine();
                bool hasParent = true;
                if (!string.IsNullOrEmpty(interactionClass.Semantics))
                {
                    sw.WriteLine(indentStr + "///<summary>");
                    sw.Write(FormatCommentBody(indentLevel, "Message for " + interaction + " iteraction : " + interactionClass.Semantics));
                    sw.WriteLine(indentStr + "///</summary>");

                }
                else
                {
                    sw.WriteLine(indentStr + "///<summary> Message for " + interaction + " iteraction : " + interaction + " classSerializerHelperName.</summary>");
                }
                GenerateHLAInteractionClassAttribute(indentLevel, sw, interactionClassDescriptor);
                if (!String.IsNullOrEmpty(superInteractionName))
                {
                    sw.Write(indentStr + "public class " + interactionMessageName + " : " + GetInteractionMessageName(superInteractionName));

                    if (interactionClassDescriptor.ParentDescriptors.Count > 0)
                    {
                        foreach (InteractionClassDescriptor parent in interactionClassDescriptor.ParentDescriptors)
                        {
                            if (!parent.Name.Equals(superInteractionName))
                            {
                                sw.Write(", " + GetInteractionMessageName(parent.Name));
                            }
                        }
                        sw.WriteLine();
                    }
                    else
                    {
                        hasParent = false;
                    }
                }
                else
                {
                    sw.Write(indentStr + "public class " + interactionMessageName);

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

                        InteractionClassDescriptor parent;
                        int length = interactionClassDescriptor.ParentDescriptors.Count;
                        for (int i = 0; i < length; i++)
                        {
                            parent = interactionClassDescriptor.ParentDescriptors[i];
                            sw.Write(GetInteractionMessageName(parent.Name));

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

                foreach (ParameterDescriptor parameter in parametersDescriptor)
                {
                    System.String parameterName = BuildFieldName(parameter.Name, interaction + "Message");
                    System.String parameterPropertyName = BuildPropertyName(parameter.Name, interaction + "Message");
                    System.String parameterType = parameter.DataType;
                    System.String parameterNativeType = NativeTypeForDataType(parameterType);

                    sw.WriteLine(indentStr + parameterNativeType + " " + parameterName + ";");

                    sw.WriteLine();
                    if (!string.IsNullOrEmpty(parameter.Semantics))
                    {
                        sw.Write(FormatCommentBody(indentLevel, "<summary>" + parameter.Semantics + "</summary>"));
                    }
                    else
                    {
                        sw.WriteLine(indentStr + "///<summary> Gets/Sets the value of the " + parameter.Name + " parameter </summary>");
                    }

                    GenerateHLAInteractionParameterAttribute(indentLevel, sw, parameter);
                    sw.WriteLine(indentStr + "public " + parameterNativeType + " " + parameterPropertyName);
                    sw.WriteLine(indentStr + "{");
                    sw.WriteLine(GenerateIndentString(indentLevel + 1) + "get { return " + parameterName + ";}");
                    sw.WriteLine(GenerateIndentString(indentLevel + 1) + "set { " + parameterName + " = value;}");
                    sw.WriteLine(indentStr + "}");
                    sw.WriteLine();
                }

                sw.WriteLine(indentStr + "///<summary> Returns a string representation of this " + interactionMessageName + ". </summary>");
                sw.WriteLine(indentStr + "///<returns> a string representation of this " + interactionMessageName + "</returns>");
                sw.WriteLine(indentStr + "public override string ToString()");
                sw.WriteLine(indentStr + "{");
                if (!hasParent)
                {
                    sw.WriteLine(indentStr + "    return \"" + interactionMessageName + "();");
                }
                else
                {
                    sw.Write(indentStr + "    return \"" + interactionMessageName + "(\" + base.ToString()");
                }
                foreach (ParameterDescriptor parameter in parametersDescriptor)
                {
                    System.String parameterName = parameter.Name;
                    System.String parameterType = parameter.DataType;
                    sw.WriteLine();
                    sw.Write(indentStr + "           + \", " + Capitalize(parameterName) + ": \" + " + BuildPropertyName(parameter.Name, interactionMessageName));

                }
                if (hasParent)
                    sw.WriteLine(" + \")\";");
                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);
            }
        }
예제 #8
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);
                        }
                    }
                }
            }
        }
예제 #9
0
 /// <summary> 
 /// Adds an interaction class descriptor.
 /// </summary>
 /// <param name="icd">the interaction class descriptor to Add
 /// </param>
 public virtual void AddInteractionClassDescriptor(InteractionClassDescriptor icd)
 {
     interactionClassNameDescriptorMap[icd.Name] = icd;
     interactionClassHandleDescriptorMap[icd.Handle] = icd;
 }
예제 #10
0
 /// <summary> 
 /// Adds a listener for parameters with the specified handle.
 /// </summary>
 /// <param name="handle">the parameter handle of interest
 /// </param>
 /// <param name="icd">the interaction class descriptor to notify
 /// </param>
 protected internal virtual void AddParameterListener(IParameterHandle handle, InteractionClassDescriptor icd)
 {
     parameterHandleListenerMap[handle] = icd;
 }
예제 #11
0
        /// <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();
        }
예제 #12
0
        /// <summary> 
        /// Adds a listener for interaction classes with a particular name.
        /// </summary>
        /// <param name="name">the interaction class name of interest
        /// </param>
        /// <param name="icd">the interaction class descriptor to notify
        /// </param>
        protected internal virtual void AddInteractionClassListener(System.String name, InteractionClassDescriptor icd)
        {
            System.Collections.ArrayList v = interactionClassNameListenersMap[name];

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

            v.Add(icd);
        }
예제 #13
0
        /// <summary> 
        /// Removes an interaction class descriptor.
        /// </summary>
        /// <param name="icd">the interaction class descriptor to Remove
        /// </param>
        public virtual void RemoveInteractionClassDescriptor(InteractionClassDescriptor icd)
        {
            if (interactionClassNameDescriptorMap[icd.Name] == icd)
            {
                interactionClassNameDescriptorMap.Remove(icd.Name);
            }

            if (interactionClassHandleDescriptorMap[icd.Handle] == icd)
            {
                interactionClassHandleDescriptorMap.Remove(icd.Handle);
            }
        }
예제 #14
0
        private TreeNode AddInteractionTreeNode(TreeNode rootNode, InteractionClassDescriptor interactionDescriptor)
        {
            TreeNodeCollection parentNodes;
            if (interactionDescriptor.ParentDescriptors.Count != 0)
            {
                TreeNode parentNode = AddInteractionTreeNode(rootNode, interactionDescriptor.ParentDescriptors[0]);
                parentNodes = parentNode.Nodes;
            }
            else
                parentNodes = rootNode.Nodes;

            TreeNode tmpNode = FindNode(parentNodes, interactionDescriptor.Name);
            if (tmpNode != null)
                return tmpNode;
            else
            {
                TreeNode node = new TreeNode(interactionDescriptor.Name);
                node.ImageIndex = 1;
                node.SelectedImageIndex = 1;
                HLAInteractionClassPropertiesInformation nodeInfo = new HLAInteractionClassPropertiesInformation(interactionDescriptor.interactionClass, null);
                node.Tag = nodeInfo;
                parentNodes.Add(node);

                return node;
            }
        }
예제 #15
0
 /// <summary>
 /// Adds a parent descriptor.
 /// </summary>
 /// <param name="pd">the parent descriptor to Add
 /// </param>
 public virtual void AddParentDescriptor(InteractionClassDescriptor pd)
 {
     this.parentDescriptors.Add(pd);
 }
예제 #16
0
 /// <summary>
 /// Notifies this object that an interaction class of interest has been
 /// added to the descriptor manager.
 /// </summary>
 /// <param name="icd">the interaction class descriptor
 /// </param>
 protected internal virtual void InteractionClassAdded(InteractionClassDescriptor icd)
 {
     parentDescriptors.Add(icd);
 }