private HLAattributeHandleValuePair[] CreateAttributesHandleValuePairList(IDictionary <string, object> methodNameValueMap, IObjectInstanceHandle instanceHandle) { HLAattributeHandleValuePair[] attributeHandleValuePairList = new HLAattributeHandleValuePair[methodNameValueMap.Count]; ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(instanceHandle); IObjectClassHandle och = oid.ClassHandle; ObjectClassDescriptor ocd = rti.descriptorManager.GetObjectClassDescriptor(och); int count = 0; foreach (KeyValuePair <string, object> entry in methodNameValueMap) { if (log.IsDebugEnabled) { log.Debug("The method " + entry.Key + " from object " + instanceHandle + " has been called; new value:" + entry.Value + "; parameter type = " + entry.Value.GetType()); } attributeHandleValuePairList[count] = new HLAattributeHandleValuePair(); attributeHandleValuePairList[count].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor(entry.Key).Handle).Identifier; attributeHandleValuePairList[count].AttributeValue = entry.Value; count++; } return(attributeHandleValuePairList); }
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); } }
private string GetAttributeName(object instance, long attributeHandle) { IObjectClassHandle whichClass = ((HLAobjectRoot)instance).ClassHandle; IAttributeHandle theHandle = new XRTIAttributeHandle(attributeHandle); ObjectClassDescriptor ocd = rti.descriptorManager.GetObjectClassDescriptor(whichClass); if (ocd == null) { throw new InvalidObjectClassHandle(whichClass.ToString()); } else { AttributeDescriptor ad = ocd.GetAttributeDescriptor(theHandle); if (ad == null) { throw new InvalidAttributeHandle(theHandle.ToString()); } else { return(ad.Name); } } }
protected void ProcessHLAupdateAttributeValues(HLAupdateAttributeValuesMessage msg) { // Metafederation RO message if (msg.FederationExecutionHandle == HLAobjectRoot.METAFEDERATION_EXECUTION_HANDLE) { ObjectInstanceDescriptor oid = parent.descriptorManager.GetObjectInstanceDescriptor(new XRTIObjectInstanceHandle(msg.ObjectInstanceHandle)); ObjectClassDescriptor ocd = parent.descriptorManager.GetObjectClassDescriptor("Sxtafederate"); bool timePropertyFound = false; if (oid.ClassHandle.Equals(ocd.Handle)) { if (msg.AttributeHandleValuePairList.Length > 0) { for (int i = 0; i < msg.AttributeHandleValuePairList.Length && !timePropertyFound; i++) { HLAattributeHandleValuePair pair = msg.AttributeHandleValuePairList[i]; string propertyName = ocd.GetAttributeDescriptor(new XRTIAttributeHandle(pair.AttributeHandle)).Name; if (propertyName.Equals("HLAlogicalTime") || propertyName.Equals("HLAlookahead") || propertyName.Equals("HLApendingTime") || propertyName.Equals("HLALITS")) // propertyName.Equals("HLAtimeManagerState") || propertyName.Equals("HLAtimeConstrained") || propertyName.Equals("HLAtimeRegulating")) { timePropertyFound = true; } } if (timePropertyFound) { form.UpdateTimeManagementValueLabels(); } } } } }
private void PublishAndSubscribeFederationObjectClass(string fddFederationFOM, long federationExecutionHandle) { DescriptorManager federationDescriptorManager = new DescriptorManager(fddFederationFOM); foreach (ObjectClassDescriptor ocd in federationDescriptorManager.ObjectClassDescriptors) { if (ocd.Name != "HLAobjectRoot") { ObjectClassDescriptor ocdReal = descriptorManager.GetObjectClassDescriptor(ocd.Name); CreateAndSendSubscribeMessage(federationExecutionHandle, this.federate.HLAfederateHandle, ocdReal); } } }
private HLAattributeHandleValuePair[] CreateAttributeHandleValuePairList(string methodName, object newValue, IObjectInstanceHandle instanceHandle) { ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(instanceHandle); IObjectClassHandle och = oid.ClassHandle; ObjectClassDescriptor ocd = rti.descriptorManager.GetObjectClassDescriptor(och); HLAattributeHandleValuePair[] attributeHandleValuePairList = new HLAattributeHandleValuePair[1]; attributeHandleValuePairList[0] = new HLAattributeHandleValuePair(); attributeHandleValuePairList[0].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor(methodName).Handle).Identifier; attributeHandleValuePairList[0].AttributeValue = newValue; return(attributeHandleValuePairList); }
public object UpdateAttributeValuesProxyObject(object instance, IDictionary <string, object> methodNameValueMap) { if (instance is HLAobjectRoot) { HLAobjectRoot obj = instance as HLAobjectRoot; ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(obj.ClassHandle); foreach (KeyValuePair <string, object> entry in methodNameValueMap) { if (log.IsDebugEnabled) { log.Debug("The method " + entry.Key + " from object " + obj.InstanceHandle + " has been called; new value:" + entry.Value + "; parameter type = " + entry.Value.GetType()); } HLAAttributeAttribute attr = obj.tableMethodInfo2Attr[entry.Key]; attr.propInfo.GetSetMethod().Invoke(obj, new object[] { entry.Value }); } } return(instance); }
///<summary> ///Notifies that the box is already in its house ///</summary> ///<param name="msg"> the message associated with the interaction</param> ///<exception cref="InteractionClassNotRecognized"> if the interaction class was not recognized</exception> ///<exception cref="InteractionParameterNotRecognized"> if a parameter of the interaction was not /// recognized</exception> ///<exception cref="InteractionClassNotSubscribed"> if the federate had not subscribed to the /// interaction class</exception> ///<exception cref="FederateInternalError"> if an error occurs in the federate</exception> public void OnReceiveBoxInHouse(BoxInHouseMessage msg) { ILogicalTime time = timeFactory.Decode(msg.Time, 0); if (log.IsDebugEnabled) { log.Debug("Received BoxInHouseMessage [time = " + time + "]"); } form.UpdateBoxInHouseTimeLabel(time); ObjectInstanceDescriptor oid = rti.descriptorManager.GetObjectInstanceDescriptor(home.InstanceHandle); IObjectClassHandle och = oid.ClassHandle; ObjectClassDescriptor ocd = rti.descriptorManager.GetObjectClassDescriptor(och); HLAattributeHandleValuePair[] handleValuePairList = new HLAattributeHandleValuePair[1]; handleValuePairList[0] = new HLAattributeHandleValuePair(); handleValuePairList[0].AttributeHandle = ((XRTIAttributeHandle)ocd.GetAttributeDescriptor("BoxesCount").Handle).Identifier; handleValuePairList[0].AttributeValue = 1; rti.UpdateAttributeValues(home.InstanceHandle, handleValuePairList, new byte[1], time); }
public object CreateProxyObject(string objectName, long objectInstanceHandle, long objectClassHandle) { //ObjectInstanceDescriptor oid = descriptorManager.GetObjectInstanceDescriptor(new XRTIObjectInstanceHandle(objectInstanceHandle)); //ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(oid.ClassHandle); ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(new XRTIObjectClassHandle(objectClassHandle)); HLAProxyAttribute attr = new HLAProxyAttribute(); attr.ObjectClassHandle = objectClassHandle; attr.ObjectInstanceHandle = objectInstanceHandle; attr.ObjectName = ocd.Name; object obj = HLAobjectRoot.NewRemoteInstance(ocd.NativeName, attr); if (log.IsDebugEnabled) { log.Debug("The constructor of object " + objectName + " has been called"); } //return Activator.CreateInstance(ocd.NativeName, null, new object[] { attr }); return(obj); }
public object UpdateAttributeValuesProxyObject(object instance, HLAattributeHandleValuePair[] methodNameValueMap) { if (instance is HLAobjectRoot) { HLAobjectRoot obj = instance as HLAobjectRoot; ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(obj.ClassHandle); foreach (HLAattributeHandleValuePair entry in methodNameValueMap) { if (log.IsDebugEnabled) { log.Debug("The method " + entry.AttributeHandle + " from object " + obj.InstanceHandle + " has been called; new value:" + entry.AttributeValue + "; parameter type = " + entry.AttributeValue.GetType()); } string attrName = ocd.GetAttributeDescriptor(new XRTIAttributeHandle(entry.AttributeHandle)).Name; HLAAttributeAttribute attr = obj.AttrTable[attrName]; attr.propInfo.GetSetMethod().Invoke(obj, new object[] { entry.AttributeValue }); //obj.GetType().BaseType.GetProperty(attrName).GetSetMethod().Invoke(obj, new object[] { entry.AttributeValue }); } } return(instance); }
protected void ProcessHLAupdateAttributeValuesMetafederation(HLAupdateAttributeValuesMessage msg) { Lrc.ReflectAttributeValuesExtCallback callback = new Lrc.ReflectAttributeValuesExtCallback(this.parent.MetaFederateAmbassador, new XRTIObjectInstanceHandle(msg.ObjectInstanceHandle), msg.AttributeHandleValuePairList, msg.UserSuppliedTag); callback.Call(); ObjectInstanceDescriptor oid = parent.descriptorManager.GetObjectInstanceDescriptor(new XRTIObjectInstanceHandle(msg.ObjectInstanceHandle)); ObjectClassDescriptor ocd = parent.descriptorManager.GetObjectClassDescriptor("Sxtafederate"); bool timePropertyFound = false; if (oid.ClassHandle.Equals(ocd.Handle)) { if (msg.AttributeHandleValuePairList.Length > 0) { for (int i = 0; i < msg.AttributeHandleValuePairList.Length && !timePropertyFound; i++) { HLAattributeHandleValuePair pair = msg.AttributeHandleValuePairList[i]; string propertyName = ocd.GetAttributeDescriptor(new XRTIAttributeHandle(pair.AttributeHandle)).Name; if (propertyName.Equals("HLAlogicalTime") || propertyName.Equals("HLAlookahead") || propertyName.Equals("HLApendingTime") || propertyName.Equals("HLALITS") || propertyName.Equals("HLAtimeManagerState") || propertyName.Equals("HLAtimeConstrained") || propertyName.Equals("HLAtimeRegulating")) { timePropertyFound = true; } } if (timePropertyFound) { parent.UpdateFederate(); } } } }
/// <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(); } } }
//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"); }
/// <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> /// 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> /// 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); } }
/// <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); } } } }