/// <summary> /// Creates a new instance. /// </summary> public HLAFixedRecordDataAttribute() { baseInfo = new HLAFixedRecordData(); }
/// <summary> /// Generates a <code>HLAFixedRecordDataAttribute</code>. /// </summary> private void GenerateHLAFixedRecordDataAttribute(int localIndentLevel, System.IO.StreamWriter ps, HLAFixedRecordData fixedRecord) { string indentStr = GenerateIndentString(localIndentLevel); string newLine = "," + Environment.NewLine + indentStr + " "; ps.Write(indentStr + "[HLAFixedRecordData(Name = \"" + fixedRecord.Name + "\""); if (!String.IsNullOrEmpty(fixedRecord.Encoding)) { ps.Write(newLine); ps.Write("Encoding = \"" + fixedRecord.Encoding + "\""); } if (!String.IsNullOrEmpty(fixedRecord.EncodingNotes)) { ps.Write(newLine); ps.Write("EncodingNotes = \"" + fixedRecord.EncodingNotes + "\""); } if (!String.IsNullOrEmpty(fixedRecord.Semantics)) { ps.Write(newLine); ps.Write("Semantics = \"" + fixedRecord.Semantics + "\""); } if (!String.IsNullOrEmpty(fixedRecord.SemanticsNotes)) { ps.Write(newLine); ps.Write("SemanticsNotes = \"" + fixedRecord.SemanticsNotes + "\""); } if (!String.IsNullOrEmpty(fixedRecord.NameNotes)) { ps.Write(newLine); ps.Write("NameNotes = \"" + fixedRecord.NameNotes + "\""); } ps.WriteLine(")]"); }
/// <summary> /// Generates a fixed record data type class. /// </summary> private void GenerateFixedRecordDataType(System.IO.StreamWriter stream, HLAFixedRecordData fixedRecord) { int indentLevel = 0; string indentStr = GenerateIndentString(indentLevel); System.String typeName = fixedRecord.Name; try { System.IO.StreamWriter ps; if (stream == null) { String qualifiedTypeName = packagePrefix + typeName; String path = qualifiedTypeName.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); ps = new System.IO.StreamWriter(fos); System.String packageName = GetPackageName(qualifiedTypeName); if (packageName != null) { ps.WriteLine(indentStr + "namespace " + packageName); } else { ps.WriteLine(indentStr + "namespace Sxta.Rti1516.Proxies"); } ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "using System;"); ps.WriteLine(indentStr + "using System.IO;"); ps.WriteLine(); ps.WriteLine(indentStr + "using Sxta.Rti1516.Reflection;"); } else { ps = stream; } ps.WriteLine(); if (!string.IsNullOrEmpty(fixedRecord.Semantics)) { PrintClassComment(ps, fixedRecord.Semantics, indentLevel); } else { PrintClassComment(ps, "Autogenerated fixed record data type.", indentLevel); } ps.WriteLine(indentStr + "[Serializable]"); GenerateHLAFixedRecordDataAttribute(indentLevel, ps, fixedRecord); ps.WriteLine(indentStr + "public struct " + typeName); ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); IList<HLARecordField> fields = fixedRecord.RecordFields; bool first = true; for (int i = 0; i < fields.Count; i++) { HLARecordField field = fields[i]; if (NativeTypeForDataType(field.DataType) != null) { if (!string.IsNullOrEmpty(field.Semantics)) { PrintVariableComment(ps, field.Semantics, indentLevel); } else { PrintVariableComment(ps, "Field #" + i + ".", indentLevel); } string propertyRecordFieldName = BuildRecordFieldPropertyName(field.Name, typeName); string nativeFieldName = BuildRecordFieldName(field.Name, typeName, propertyRecordFieldName); ps.WriteLine(indentStr + "private " + NativeTypeForDataType(field.DataType) + " " + nativeFieldName + ";"); ps.WriteLine(); } } //---------------------------------------- // FixedRecordDataType.constructor //---------------------------------------- /* Structs dont have parameterless constructors ps.WriteLine(indentStr + "///<summary>Default constructor.</summary>"); ps.WriteLine(indentStr + "public " + typeName + "()"); ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); ps.WriteLine(); */ //---------------------------------------- // FixedRecordDataType.ToString //---------------------------------------- ps.WriteLine(indentStr + "///<summary> Returns a string representation of this " + typeName + ". </summary>"); ps.WriteLine(indentStr + "///<returns> a string representation of this " + typeName + "</returns>"); ps.WriteLine(indentStr + "public override String ToString()"); ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "return \"" + typeName + "(\" +"); first = true; for (int i = 0; i < fields.Count; i++) { HLARecordField field = fields[i]; System.String nativeType = NativeTypeForDataType(field.DataType); string propertyRecordFieldName = BuildRecordFieldPropertyName(field.Name, typeName); string nativefieldName = BuildRecordFieldName(field.Name, typeName, propertyRecordFieldName); if (nativeType != null) { if (!first) { ps.WriteLine(" + \", \" +"); } else { first = false; } ps.Write(indentStr + " \"" + field.Name + ": \" + " + nativefieldName); } } ps.WriteLine(" + "); ps.WriteLine(indentStr + " \")\";"); indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); //---------------------------------------- // FixedRecordDataType.Attributes (Gets/Sets) //---------------------------------------- for (int i = 0; i < fields.Count; i++) { HLARecordField field = fields[i]; System.String propertyRecordFieldName = BuildRecordFieldPropertyName(field.Name, typeName); System.String fieldName = BuildRecordFieldName(field.Name, typeName, propertyRecordFieldName); System.String fieldType = field.DataType; System.String fieldNativeType = NativeTypeForDataType(fieldType); if (fieldNativeType != null) { ps.WriteLine(); ps.WriteLine(indentStr + "///<summary>"); ps.WriteLine(indentStr + "/// Gets/Sets the value of the " + field.Name + " field."); ps.WriteLine(indentStr + "///</summary>"); GenerateHLARecordFieldAttribute(indentLevel, ps, field); ps.WriteLine(indentStr + "public " + fieldNativeType + " " + propertyRecordFieldName); ps.WriteLine(indentStr + "{"); ps.WriteLine(indentStr + " set {" + fieldName + " = value; }"); ps.WriteLine(indentStr + " get { return " + fieldName + "; }"); ps.WriteLine(indentStr + "}"); ps.WriteLine(); } } indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); if (stream == null) { indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); ps.Flush(); ps.Close(); } } catch (System.IO.IOException ioe) { System.Console.Error.WriteLine("Error generating fixed record data type: " + ioe); } }
/// <summary> /// Generates a serializer class for the fixed record data type class. /// </summary> private void GenerateFixedRecordDataTypeSerializers(System.IO.StreamWriter stream, HLAFixedRecordData fixedRecord, int indentLevel) { string indentStr = GenerateIndentString(indentLevel); String typeName = fixedRecord.Name; String typeNameSerializer = typeName + "XrtiSerializer"; try { System.IO.StreamWriter ps; if (stream == null) { String qualifiedTypeName = packagePrefix + typeNameSerializer; String path = qualifiedTypeName.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); ps = new System.IO.StreamWriter(fos); System.String packageName = GetPackageName(qualifiedTypeName); if (packageName != null) { ps.WriteLine(indentStr + "namespace " + packageName); } else { ps.WriteLine(indentStr + "namespace Sxta.Rti1516.Proxies"); } ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "using System;"); ps.WriteLine(indentStr + "using System.IO;"); ps.WriteLine(); ps.WriteLine(indentStr + "using HlaEncodingReader = Sxta.Rti1516.Serializers.XrtiEncoding.HlaEncodingReader;"); ps.WriteLine(indentStr + "using HlaEncodingWriter = Sxta.Rti1516.Serializers.XrtiEncoding.HlaEncodingWriter;"); } else { ps = stream; } ps.WriteLine(); ps.WriteLine(); PrintClassComment(ps, "Serializes and deserializes " + typeName + " objects into and from HLA formats.", indentLevel); ps.WriteLine(indentStr + "public sealed class " + typeNameSerializer); ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); //---------------------------------------- // FixedRecordDataType.Serializer.Serialize //---------------------------------------- ps.WriteLine(indentStr + "///<summary>"); ps.WriteLine(indentStr + "/// Writes this " + typeName + " to the specified stream."); ps.WriteLine(indentStr + "///</summary>"); ps.WriteLine(indentStr + "///<param name=\"writer\"> the output stream to write to</param>"); ps.WriteLine(indentStr + "///<param name=\"obj\"> the object to serialize</param>"); ps.WriteLine(indentStr + "///<exception cref=\"IOException\"> if an error occurs</exception>"); ps.WriteLine(indentStr + "public static void Serialize(HlaEncodingWriter writer, " + typeName + " obj)"); ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); IList<HLARecordField> fields = fixedRecord.RecordFields; for (int i = 0; i < fields.Count; i++) { HLARecordField field = fields[i]; if (NativeTypeForDataType(field.Name) != null) { PrintSerializationBlock(ps, indentLevel, 'i', field.DataType, "obj." + BuildRecordFieldPropertyName(field.Name, typeNameSerializer), "writer"); } } indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); ps.WriteLine(); //---------------------------------------- // FixedRecordDataType.Serializer.Deserialize //---------------------------------------- ps.WriteLine(); ps.WriteLine(indentStr + "///<summary>"); ps.WriteLine(indentStr + "/// Reads and returns a " + typeName + " from the specified stream."); ps.WriteLine(indentStr + "///</summary>"); ps.WriteLine(indentStr + "///<param name=\"reader\"> the input stream to read from</param>"); ps.WriteLine(indentStr + "///<returns> the decoded value</returns>"); ps.WriteLine(indentStr + "///<exception cref=\"IOException\"> if an error occurs</exception>"); ps.WriteLine(indentStr + "public static " + typeName + " Deserialize(HlaEncodingReader reader)"); ps.WriteLine(indentStr + "{"); indentLevel++; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + typeName + " decodedValue = new " + typeName + "();"); ps.WriteLine(); for (int i = 0; i < fields.Count; i++) { HLARecordField field = fields[i]; if (NativeTypeForDataType(field.Name) != null) { PrintDeserializationBlock(ps, indentLevel, 'i', field.DataType, "decodedValue." + BuildRecordFieldPropertyName(field.Name, typeNameSerializer), "reader"); } } ps.WriteLine(indentStr + "return decodedValue;"); indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); ps.WriteLine(); indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); ps.WriteLine(); if (stream == null) { indentLevel--; indentStr = GenerateIndentString(indentLevel); ps.WriteLine(indentStr + "}"); ps.Flush(); ps.Close(); } } catch (System.IO.IOException ioe) { System.Console.Error.WriteLine("Error generating fixed record data type: " + ioe); } }
/// <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(); }