Ejemplo n.º 1
0
        /// <summary>
        /// Generates a <code>HLAAttributeAttribute</code>.
        /// </summary>
        private void GenerateHLAAttributeAttribute(int localIndentLevel, System.IO.StreamWriter ps, AttributeDescriptor attributeDescriptor)
        {
            IHLAattribute attr      = attributeDescriptor.attribute;
            string        indentStr = GenerateIndentString(localIndentLevel);
            string        newLine   = "," + Environment.NewLine + indentStr + "              ";

            ps.Write(indentStr + "[HLAAttribute(Name = \"" + attributeDescriptor.Name + "\"");
            ps.Write("," + Environment.NewLine + indentStr + "                ");
            ps.Write("Sharing = " + attr.Sharing.GetType() + "." + attr.Sharing);
            if (!String.IsNullOrEmpty(attr.NameNotes))
            {
                ps.Write(newLine);
                ps.Write("NameNotes = \"" + attr.NameNotes + "\"");
            }

            if (!String.IsNullOrEmpty(attr.SharingNotes))
            {
                ps.Write(newLine);
                ps.Write("SharingNotes = \"" + attr.SharingNotes + "\"");
            }
            if (!String.IsNullOrEmpty(attr.Semantics))
            {
                ps.Write(newLine);
                ps.Write("Semantics = \"" + attr.Semantics + "\"");
            }
            if (!String.IsNullOrEmpty(attr.SemanticsNotes))
            {
                ps.Write(newLine);
                ps.Write("SemanticsNotes = \"" + attr.SemanticsNotes + "\"");
            }
            if (!String.IsNullOrEmpty(attr.DataType))
            {
                ps.Write(newLine);
                ps.Write("DataType = \"" + attr.DataType + "\"");
            }
            ps.Write(newLine);
            ps.Write("UpdateType = " + attr.UpdateType.GetType() + "." + attr.UpdateType);
            if (!String.IsNullOrEmpty(attr.UpdateCondition))
            {
                ps.Write(newLine);
                ps.Write("UpdateCondition = \"" + attr.UpdateCondition + "\"");
            }
            ps.Write(newLine);
            ps.Write("OwnerShip = " + attr.Ownership.GetType() + "." + attr.Ownership);
            if (!String.IsNullOrEmpty(attr.Transportation))
            {
                ps.Write(newLine);
                ps.Write("Transportation = \"" + attr.Transportation + "\"");
            }

            ps.Write(newLine);
            ps.Write("Order = " + attr.Order.GetType() + "." + attr.Order);

            if (!String.IsNullOrEmpty(attr.Dimensions))
            {
                ps.Write(newLine);
                ps.Write("Dimensions = \"" + attr.Dimensions + "\"");
            }
            ps.WriteLine(")]");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLAAttributePropertiesInformationValue(IHLAattribute attr, System.Reflection.PropertyInfo method, object pValue)
     : base(attr, method)
 {
     this.value = pValue;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLAAttributePropertiesInformation(IHLAattribute attr, System.Reflection.PropertyInfo method)
 {
     attrInfo = attr;
     propInfo = method;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLAAttributePropertiesInformationValue(IHLAattribute attr, System.Reflection.PropertyInfo method, object pValue)
     : base(attr, method)
 {
     this.value = pValue;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public HLAAttributePropertiesInformation(IHLAattribute attr, System.Reflection.PropertyInfo method)
 {
     attrInfo = attr;
     propInfo = method;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Generates an object instance proxy source file.
        /// </summary>
        /// <param name="classElement">the object instance class element containing the relevant
        /// information
        /// </param>
        /// <param name="superClassName">the name of the proxy superclass
        /// </param>
        /// <exception cref=""> TypeConflictException if a type conflict is detected
        /// </exception>
        private void GenerateObjectInstanceProxy(System.IO.StreamWriter stream, List <string> generatedObjectClass, ObjectClassDescriptor objDescriptor, String superClassName)
        {
            if (objDescriptor == null)
            {
                return;
            }
            else if (objDescriptor.ParentDescriptors.Count != 0)
            {
                ObjectClassDescriptor parentDescriptor = objDescriptor.ParentDescriptors[0];
                if (!generatedObjectClass.Contains(parentDescriptor.Name))
                {
                    GenerateObjectClassInterface(stream, generatedObjectClass, parentDescriptor, superClassName);
                }
            }

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

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

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


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

                    System.String packageName = GetPackageName(qualifiedClassName);

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


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

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

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

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

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

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

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

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

                bool first = true;

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

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

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

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

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

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

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

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


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

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

                if (stream == null)
                {
                    indentLevel--;
                    indentStr = GenerateIndentString(indentLevel);
                    sw.WriteLine(indentStr + "}");
                    sw.Flush();
                    sw.Close();
                }
            }
            catch (System.IO.IOException ioe)
            {
                System.Console.Error.WriteLine("Error generating object instance proxy: " + ioe);
            }
        }