/// <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(")]"); }
public static List <AttributeDescriptor> CreateAttributeDescriptors() { var result = new List <AttributeDescriptor> { AttributeDescriptor.ForInteger("remoteId", typeof(Client)), AttributeDescriptor.ForDate("createdDate", typeof(Client)), AttributeDescriptor.ForDate("lastChangedDate", typeof(Client)), AttributeDescriptor.ForSomething("createdBy", typeof(Client), typeof(User), typeof(RemoteUser)), AttributeDescriptor.ForSomething("lastChangedBy", typeof(Client), typeof(User), typeof(RemoteUser)), AttributeDescriptor.ForInteger("optimisticLockVersion", typeof(Client)), }; return(result); }
protected void SendInfoAboutObjects(IList <HLAobjectRoot> objects, HLAsubscribeObjectClassAttributesMessage msg) { foreach (HLAobjectRoot obj in objects) { // if it is a local object and its class handle is equal to the object class handle sent if (obj.HLAprivilegeToDeleteObject && obj.ClassHandle.Equals(msg.HLAobjectClass)) { parent.RegisterObjectInstance(obj); IList <HLAattributeHandleValuePair> propertyValuePair = new List <HLAattributeHandleValuePair>(); // TODO ANGEL: Esto es incorrecto y esta mal. Puede haber propiedades que no sean remotas foreach (IAttributeHandle attribute in msg.HLAattributeList) { AttributeDescriptor ad = parent.descriptorManager.GetAttributeDescriptor(attribute); if (ad == null) { throw new InvalidAttributeHandle(attribute.ToString()); } else { PropertyInfo pi = obj.GetType().BaseType.GetProperty(ad.Name); if (!ad.Name.Equals("HLAprivilegeToDeleteObject") && pi != null) { object value = pi.GetValue(obj, null); if (value != null) { propertyValuePair.Add(new HLAattributeHandleValuePair(((XRTIAttributeHandle)ad.Handle).Identifier, value)); } } } } HLAattributeHandleValuePair[] propertyValuePairArray = new HLAattributeHandleValuePair[propertyValuePair.Count]; propertyValuePair.CopyTo(propertyValuePairArray, 0); // TODO ANGEL: Que pasa con el userTag parent.UpdateAttributeValues(obj.InstanceHandle, propertyValuePairArray, null); } } }
protected List <AttributeDescriptor> CreateAttributeDescriptors() { List <AttributeDescriptor> result = new List <AttributeDescriptor>(); //result.Add(new DefaultDescriptor("remoteId", GetClass(), typeof(int))); //result.Add(new DefaultDescriptor("createdDate", GetClass(), typeof(DateTime))); //result.Add(new DefaultDescriptor("lastChangedDate", GetClass(), typeof(DateTime))); //result.Add(new ReferenceDescriptor("createdBy", GetClass(), typeof(User))); //result.Add(new ReferenceDescriptor("lastChangedBy", GetClass(), typeof(User))); //result.Add(new DefaultDescriptor("optimisticLockVersion", GetClass(), typeof(int))); result.Add(AttributeDescriptor.ForInteger("remoteId", GetClass())); result.Add(AttributeDescriptor.ForDate("createdDate", GetClass())); result.Add(AttributeDescriptor.ForDate("lastChangedDate", this.GetClass())); result.Add(AttributeDescriptor.ForUser("createdBy", this.GetClass())); result.Add(AttributeDescriptor.ForUser("lastChangedBy", this.GetClass())); result.Add(AttributeDescriptor.ForInteger("optimisticLockVersion", this.GetClass())); return(result); }
public void Filter(ControllerDescriptor controllerDescriptor) { MethodDescriptor methodDescriptor = controllerDescriptor.Methods[0]; AttributeDescriptor attributeDescriptor = methodDescriptor.CustomAttributes[0]; //Change HTTP method to GET attributeDescriptor.Constructor = typeof(HttpGetAttribute).GetConstructor(new[] { typeof(string) }); //Change route to start with "api/v1/greeter" attributeDescriptor.ConstructorArgs[0] = "api/v1/greeter/" + (string)attributeDescriptor.ConstructorArgs[0]; ParameterDescriptor parameterDescriptor = methodDescriptor.Parameters[0]; //Add FromQuery attribute parameterDescriptor.CustomAttributes.Add( new AttributeDescriptor { Constructor = typeof(FromQueryAttribute).GetConstructor(Type.EmptyTypes), ConstructorArgs = new object[0] }); }
/// <summary> /// Parses an <see cref="AttributeData"/> into a descriptive class instance. /// </summary> /// <typeparam name="T">The instance to parse into.</typeparam> /// <param name="data">The <see cref="AttributeData"/> to parse.</param> /// <returns>The parsed object.</returns> public static T ParseInto <T>(this AttributeData data) where T : new() { var result = new T(); // Build the descriptor var desc = new AttributeDescriptor(); var props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var prop in props) { desc.WithParameter(prop.Name, prop.GetValue(result)); } // Parse var values = data.Parse(desc); foreach (var prop in props) { prop.SetValue(result, values[prop.Name]); } return(result); }
public static AttributeDescriptor ForDate(string name, AttributeDescriptor attributeDescriptor) { return(new DefaultDescriptor(name, attributeDescriptor, typeof(DateTime))); }
public static AttributeDescriptor ForDate(string name, AttributeDescriptor attributeDescriptor, Type referenceType) { return(new ReferenceDescriptor(name, attributeDescriptor, referenceType, typeof(DateTime))); }
protected AttributeDescriptor(string name, AttributeDescriptor attributeDescriptor, Type type) { this.name = name; this.attributeDescriptor = attributeDescriptor; this.type = type; }
public static AttributeDescriptor ForInteger(string name, AttributeDescriptor attributeDescriptor) { return(new DefaultDescriptor(name, attributeDescriptor, typeof(int))); }
public GeometryAttribute(IArray <T> data, AttributeDescriptor descriptor) : base(descriptor, data.Count) { Data = data; int arity; DataType dataType; if (typeof(T) == typeof(sbyte)) { (arity, dataType) = (1, DataType.dt_int8); } else if (typeof(T) == typeof(byte)) { (arity, dataType) = (1, DataType.dt_int8); } else if (typeof(T) == typeof(Byte2)) { (arity, dataType) = (2, DataType.dt_int8); } else if (typeof(T) == typeof(Byte3)) { (arity, dataType) = (3, DataType.dt_int8); } else if (typeof(T) == typeof(Byte4)) { (arity, dataType) = (4, DataType.dt_int8); } else if (typeof(T) == typeof(short)) { (arity, dataType) = (1, DataType.dt_int16); } else if (typeof(T) == typeof(int)) { (arity, dataType) = (1, DataType.dt_int32); } else if (typeof(T) == typeof(Int2)) { (arity, dataType) = (2, DataType.dt_int32); } else if (typeof(T) == typeof(Int3)) { (arity, dataType) = (3, DataType.dt_int32); } else if (typeof(T) == typeof(Int4)) { (arity, dataType) = (4, DataType.dt_int32); } else if (typeof(T) == typeof(long)) { (arity, dataType) = (1, DataType.dt_int64); } else if (typeof(T) == typeof(float)) { (arity, dataType) = (1, DataType.dt_float32); } else if (typeof(T) == typeof(Vector2)) { (arity, dataType) = (2, DataType.dt_float32); } else if (typeof(T) == typeof(Vector3)) { (arity, dataType) = (3, DataType.dt_float32); } else if (typeof(T) == typeof(Vector4)) { (arity, dataType) = (4, DataType.dt_float32); } else if (typeof(T) == typeof(Matrix4x4)) { (arity, dataType) = (16, DataType.dt_float32); } else if (typeof(T) == typeof(double)) { (arity, dataType) = (1, DataType.dt_float64); } else if (typeof(T) == typeof(DVector2)) { (arity, dataType) = (2, DataType.dt_float64); } else if (typeof(T) == typeof(DVector3)) { (arity, dataType) = (3, DataType.dt_float64); } else if (typeof(T) == typeof(DVector4)) { (arity, dataType) = (4, DataType.dt_float64); } else { throw new Exception($"Unsupported data type {typeof(T)}"); } // Check that the computed data type is consistent with the descriptor if (dataType != Descriptor.DataType) { throw new Exception($"DataType was {dataType} but expected {Descriptor.DataType}"); } // Check that the computed data arity is consistent with the descriptor if (arity != Descriptor.DataArity) { throw new Exception($"DatArity was {arity} but expected {Descriptor.DataArity}"); } }
/// <summary> /// This method validates a single one item in data dictionary against its attribute descriptor. /// </summary> /// <param name="attributeDescriptor">Descriptor of attribute the data to validate are from</param> /// <param name="dataDictionaryValues">Data dictionary values to validate</param> /// <param name="validReferencesIdsDictionary">Dictionary of valid references</param> /// <returns>List of messages.</returns> List <Message> validateOneAttribute(AttributeDescriptor attributeDescriptor, List <object> dataDictionaryValues, Dictionary <string, List <long> > validReferencesIdsDictionary) { var messages = new List <Message>(); // Required // If attribute is required and there are no input data, or they are empty or the first element is empty return error message if (attributeDescriptor.Required == true && (dataDictionaryValues == null || dataDictionaryValues.Count == 0 || dataDictionaryValues[0].ToString() == "")) { var message = new Message(MessageTypeEnum.Error, 6002, new List <string>() { attributeDescriptor.Name }, attributeDescriptor.Name); messages.Add(message); return(messages); } // If the attribute is not required and is empty, no validation is needed, so return empty messages if (dataDictionaryValues == null || dataDictionaryValues.Count == 0 || dataDictionaryValues[0].ToString() == "") { return(messages); } // General data types later used for Min and Max validation bool isNumber = false; double parsedNumber = 0; bool isText = false; bool isReference = false; // Type bool hasTypeError = false; switch (attributeDescriptor.Type) { case "color": if (!Regex.Match(dataDictionaryValues[0].ToString(), "^#(?:[0-9a-fA-F]{3}){1,2}$").Success) { hasTypeError = true; } break; case "date": try { DateTime parsedDate = DateTime.Parse(dataDictionaryValues[0].ToString()); } catch (FormatException) { hasTypeError = true; } break; case "datetime": DateTime parsedDateTime; if (!DateTime.TryParse(dataDictionaryValues[0].ToString(), out parsedDateTime)) { hasTypeError = true; } break; case "email": try { var validEmailAddress = new System.Net.Mail.MailAddress(dataDictionaryValues[0].ToString()); } catch { hasTypeError = true; } break; case "month": try { DateTime parsedMonth = DateTime.ParseExact(dataDictionaryValues[0].ToString(), "yyyy-MM", CultureInfo.InvariantCulture); } catch (FormatException) { hasTypeError = true; } break; case "int": isNumber = true; // Valid integer number values are C# ints int parsedInt; if (!int.TryParse(dataDictionaryValues[0].ToString(), out parsedInt)) { hasTypeError = true; } parsedNumber = parsedInt; break; case "float": isNumber = true; // Valid floatiog point number values are C# floats try { // CultureInfo.InvariantCulture is necessary since server might have different culture parsedNumber = float.Parse(dataDictionaryValues[0].ToString(), CultureInfo.InvariantCulture); } catch (FormatException) { hasTypeError = true; } break; case "year": isNumber = true; // Valid year values are between -9999 and 9999 int parsedYear; if (!int.TryParse(dataDictionaryValues[0].ToString(), out parsedYear) || parsedYear < -9999 || parsedYear > 9999) { hasTypeError = true; } parsedNumber = parsedYear; break; case "phone": if (!dataDictionaryValues[0].ToString().All(c => "0123456789!().-, ".Contains(c))) { hasTypeError = true; } break; case "string": isText = true; // String can contain anything, no type validation is needed. break; case "time": try { DateTime parsedMonth = DateTime.ParseExact(dataDictionaryValues[0].ToString(), "hh:mm", CultureInfo.InvariantCulture); } catch (FormatException) { hasTypeError = true; } break; case "url": Uri outUri; if (!Uri.TryCreate(dataDictionaryValues[0].ToString(), UriKind.RelativeOrAbsolute, out outUri)) { hasTypeError = true; } break; case "username": isText = true; // String can contain anything, no type validation is needed. break; case "bool": // Valid boolean values are 0 or 1 int parsedBool; if (!int.TryParse(dataDictionaryValues[0].ToString(), out parsedBool) || parsedBool != 0 || parsedBool != 1) { hasTypeError = true; } break; case "text": isText = true; // String can contain anything, no type validation is needed. break; default: isReference = true; // References must contain only valid ids to the referenced dataset var validIds = validReferencesIdsDictionary.FirstOrDefault(k => k.Key == attributeDescriptor.Type); if (validIds.Equals(new KeyValuePair <string, List <long> >())) { // Key error var message = new Message(MessageTypeEnum.Error, 6015, new List <string>() { attributeDescriptor.Type, attributeDescriptor.Name }, attributeDescriptor.Name); Logger.LogMessageToConsole(message); messages.Add(message); return(messages); } foreach (var item in dataDictionaryValues) { long parsedReference; // If reference is not a valid number if (!long.TryParse(item.ToString(), out parsedReference)) { var message = new Message(MessageTypeEnum.Error, 6016, new List <string>() { attributeDescriptor.Name, item.ToString() }, attributeDescriptor.Name); messages.Add(message); } // If reference id is not a valid id from database else if (!validIds.Value.Contains(parsedReference)) { var message = new Message(MessageTypeEnum.Error, 6017, new List <string>() { parsedReference.ToString(), attributeDescriptor.Name }, attributeDescriptor.Name); messages.Add(message); } } break; } // If attribute type is not reference, check that dataDictionaryValues contains only one item if (!isReference) { if (dataDictionaryValues.Count != 1) { messages.Add(new Message(MessageTypeEnum.Error, 6003, new List <string>() { attributeDescriptor.Name, dataDictionaryValues.Count.ToString() }, attributeDescriptor.Name) ); // If tehere are more items, there is no need for other validations return(messages); } } // If validations found any type errors if (hasTypeError) { messages.Add(new Message(MessageTypeEnum.Error, 6004, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Type, dataDictionaryValues[0].ToString() }, attributeDescriptor.Name) ); // If value is not correct, there is no need for other validations return(messages); } // Unique // not implemented // Min and max if (isNumber) { if (attributeDescriptor.Min != null && parsedNumber < attributeDescriptor.Min) { messages.Add(new Message(MessageTypeEnum.Error, 6005, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Min.ToString(), parsedNumber.ToString() }, attributeDescriptor.Name) ); } else if (attributeDescriptor.Max != null && parsedNumber > attributeDescriptor.Max) { messages.Add(new Message(MessageTypeEnum.Error, 6006, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Max.ToString(), parsedNumber.ToString() }, attributeDescriptor.Name) ); } } else if (isText) { if (attributeDescriptor.Min != null && dataDictionaryValues[0].ToString().Length < attributeDescriptor.Min) { messages.Add(new Message(MessageTypeEnum.Error, 6007, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Min.ToString(), dataDictionaryValues[0].ToString(), dataDictionaryValues[0].ToString().Length.ToString() }, attributeDescriptor.Name) ); } else if (attributeDescriptor.Max != null && dataDictionaryValues[0].ToString().Length > attributeDescriptor.Max) { messages.Add(new Message(MessageTypeEnum.Error, 6008, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Max.ToString(), dataDictionaryValues[0].ToString(), dataDictionaryValues[0].ToString().Length.ToString() }, attributeDescriptor.Name) ); } } else if (isReference) { if (attributeDescriptor.Min != null && dataDictionaryValues.Count < attributeDescriptor.Min) { messages.Add(new Message(MessageTypeEnum.Error, 6009, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Min.ToString(), dataDictionaryValues.Count.ToString() }, attributeDescriptor.Name) ); } else if (attributeDescriptor.Max != null && dataDictionaryValues.Count > attributeDescriptor.Max) { messages.Add(new Message(MessageTypeEnum.Error, 6010, new List <string>() { attributeDescriptor.Name, attributeDescriptor.Max.ToString(), dataDictionaryValues.Count.ToString() }, attributeDescriptor.Name) ); } } return(messages); }
/// <summary> /// This method validates single application attribute. /// </summary> /// <param name="applicationDescriptor">Application descriptor to validate</param> /// <param name="datasetDescriptor">Dataset the attribute is from</param> /// <param name="attributeDescriptor">Attribute to validate</param> /// <param name="isPassword">True if attribute is a password attribute</param> /// <returns>List of messages</returns> List <Message> validateOneAttribute(ApplicationDescriptor applicationDescriptor, DatasetDescriptor datasetDescriptor, AttributeDescriptor attributeDescriptor, bool isPassword = false) { var messages = new List <Message>(); // Attribute name cannot contain {number}, because of error messages placeholders if (Regex.IsMatch(attributeDescriptor.Name, "{[0-9]*}")) { messages.Add(new Message(MessageTypeEnum.Error, 0029, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } // Not a basic type if (!AttributeType.Types.Contains(attributeDescriptor.Type)) { var validReferences = applicationDescriptor.Datasets.Select(d => d.Name).ToList(); validReferences.Add(applicationDescriptor.SystemDatasets.UsersDatasetDescriptor.Name); // Invalid reference if (!validReferences.Contains(attributeDescriptor.Type)) { messages.Add(new Message(MessageTypeEnum.Error, 0010, new List <string>() { datasetDescriptor.Name, attributeDescriptor.Name, attributeDescriptor.Type })); } // Valid reference else { // Must have OnDeleteAction if (attributeDescriptor.OnDeleteAction == OnDeleteActionEnum.None) { messages.Add(new Message(MessageTypeEnum.Error, 0011, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } // And if attribute is in system users dataset, then the OnDeleteAction cannot be Cascade, // to prevent deleting last user of the application by accident. if (datasetDescriptor == applicationDescriptor.SystemDatasets.UsersDatasetDescriptor && attributeDescriptor.OnDeleteAction == OnDeleteActionEnum.Cascade) { messages.Add(new Message(MessageTypeEnum.Error, 0012, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name, attributeDescriptor.Type })); } // If Min is set, Required cannot be false if (attributeDescriptor.Min != null && attributeDescriptor.Required == false) { messages.Add(new Message(MessageTypeEnum.Error, 0024, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } } } // A basic type else { // Password attribute if (isPassword) { // Must have its type set to password if (attributeDescriptor.Type != "password") { messages.Add(new Message(MessageTypeEnum.Error, 0009, new List <string>() { attributeDescriptor.Name })); } // Must be required if (attributeDescriptor.Required != true) { messages.Add(new Message(MessageTypeEnum.Error, 0014, new List <string>() { attributeDescriptor.Name })); } } // Not a password else { // If isPassword flag is not set, attribute type cannot be "password" if (attributeDescriptor.Type == "password") { messages.Add(new Message(MessageTypeEnum.Error, 0015, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } } // Can not have OnDeleteAction other than None if (attributeDescriptor.OnDeleteAction != OnDeleteActionEnum.None) { messages.Add(new Message(MessageTypeEnum.Error, 0013, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } } // All types // Safer can be set only for password if (!isPassword) { if (attributeDescriptor.Safer != null) { messages.Add(new Message(MessageTypeEnum.Error, 0016, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } } // Min <= Max if both set if (attributeDescriptor.Min != null && attributeDescriptor.Max != null && attributeDescriptor.Min > attributeDescriptor.Max) { messages.Add(new Message(MessageTypeEnum.Error, 0017, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } // Min and Max cannot be set for color, date, datetime, email, month, phone, time, url and bool if (attributeDescriptor.Type == "color" || attributeDescriptor.Type == "date" || attributeDescriptor.Type == "datetime" || attributeDescriptor.Type == "email" || attributeDescriptor.Type == "month" || attributeDescriptor.Type == "phone" || attributeDescriptor.Type == "time" || attributeDescriptor.Type == "url" || attributeDescriptor.Type == "bool") { if (attributeDescriptor.Min != null) { messages.Add(new Message(MessageTypeEnum.Error, 0027, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } if (attributeDescriptor.Max != null) { messages.Add(new Message(MessageTypeEnum.Error, 0028, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } } else // Attributes that can have Min and Max set { // Min > 0 and Max > 0 for text, string, username, password and references if (attributeDescriptor.Type == "text" || attributeDescriptor.Type == "string" || attributeDescriptor.Type == "username" || attributeDescriptor.Type == "password" || !AttributeType.Types.Contains(attributeDescriptor.Type)) { // Min > 0 if (attributeDescriptor.Min != null && attributeDescriptor.Min <= 0) { messages.Add(new Message(MessageTypeEnum.Error, 0018, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } // Max > 0 if (attributeDescriptor.Max != null && attributeDescriptor.Max <= 0) { messages.Add(new Message(MessageTypeEnum.Error, 0019, new List <string>() { attributeDescriptor.Name, datasetDescriptor.Name })); } } } return(messages); }
/// <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(); }
public ReferenceDescriptor(string name, AttributeDescriptor attributeDescriptor, Type referenceType, Type type) : base(name, attributeDescriptor, type) { this.referenceType = referenceType; }
public BooleanDescriptor(string name, AttributeDescriptor attributeDescriptor, Type type) : base(name, attributeDescriptor, type) { }
internal static NativeAttributeDescriptor ToNative(this AttributeDescriptor desc) => new NativeAttributeDescriptor { Name = desc.Name.ToUtf8(), Value = desc.Value.ToUtf8() };
/// <summary> Notifies this object that an attribute of interest has been /// added to the descriptor manager. /// /// </summary> /// <param name="ad">the attribute descriptor /// </param> protected internal virtual void AttributeAdded(AttributeDescriptor ad) { AddAttributeDescriptor(ad); }
/// <summary> /// Removes an attribute descriptor. /// </summary> /// <param name="ad">the attribute descriptor to Remove /// </param> public virtual void RemoveAttributeDescriptor(AttributeDescriptor ad) { if (attributeNameDescriptorMap[ad.Name] == ad) { attributeNameDescriptorMap.Remove(ad.Name); } if (attributeHandleDescriptorMap[ad.Handle] == ad) { attributeHandleDescriptorMap.Remove(ad.Handle); } }
/// <summary> /// Adds an attribute descriptor. /// </summary> /// <param name="ad">the attribute descriptor to Add /// </param> public virtual void AddAttributeDescriptor(AttributeDescriptor ad) { attributeNameDescriptorMap[ad.Name] = ad; attributeHandleDescriptorMap[ad.Handle] = ad; }
public DefaultDescriptor(string name, AttributeDescriptor attributeDescriptor, Type type) : base(name, attributeDescriptor, type) { }
/// <summary> /// Parses the <see cref="AttributeData"/> based on an <see cref="AttributeDescriptor"/>. /// </summary> /// <param name="data">The <see cref="AttributeData"/> to parse.</param> /// <param name="descriptor">The <see cref="AttributeDescriptor"/> to parse based on.</param> /// <returns>The associated parameter names and values.</returns> public static IReadOnlyDictionary <string, object?> Parse(this AttributeData data, AttributeDescriptor descriptor) => descriptor.Parse(data);
private static Completion CreateAttributeCompletion(AttributeDescriptor attribute) { return(new Completion(attribute.DisplayName, attribute.DisplayName, attribute.Description, null, null)); }
/// <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); } }