public OperationDetails EditSizeAttribute(string arabicName, string englishName, long Id, long SizeCatId) { SizeAttribute option = _unitOfWork.SizeAttributeRepository.Get(c => c.Id == Id).FirstOrDefault(); option.SizeCatId = SizeCatId; option.DateModefied = DateTime.Now; _unitOfWork.SizeAttributeRepository.Update(option); long arabicLang = (long)Langs.Arabic; long englishLang = (long)Langs.English; SizeAttributeDescription arabicDesciption = option.SizeAttributeDescriptions.Where(c => c.LanguageId == arabicLang).FirstOrDefault(); SizeAttributeDescription englishDesciption = option.SizeAttributeDescriptions.Where(c => c.LanguageId == englishLang).FirstOrDefault(); arabicDesciption.Name = arabicName; arabicDesciption.DateModefied = DateTime.Now; englishDesciption.Name = englishName; englishDesciption.DateModefied = DateTime.Now; _unitOfWork.SizeAttributeDescriptionRepository.Update(arabicDesciption); _unitOfWork.SizeAttributeDescriptionRepository.Update(englishDesciption); _unitOfWork.Save(); return(new OperationDetails(true, "تم التعديل بنجاح", option.Id.ToString())); }
public OperationDetails AddSizeAttribute(string arabicName, string englishName, long SizeCategoryId) { SizeAttribute option = new SizeAttribute(); option.DateAdded = DateTime.Now; option.DateModefied = DateTime.Now; OptionHelper sizeCat = _unitOfWork.OptionHelperRepository.Get(c => c.Id == SizeCategoryId).FirstOrDefault(); option.SizeCatId = SizeCategoryId; option = _unitOfWork.SizeAttributeRepository.Insert(option); SizeAttributeDescription arabicDesciption = new SizeAttributeDescription(); SizeAttributeDescription englishDesciption = new SizeAttributeDescription(); arabicDesciption.Name = arabicName; arabicDesciption.SizeAttributeId = option.Id; arabicDesciption.DateAdded = DateTime.Now; arabicDesciption.DateModefied = DateTime.Now; arabicDesciption.LanguageId = (long)Langs.Arabic; englishDesciption.Name = englishName; englishDesciption.SizeAttributeId = option.Id; englishDesciption.DateAdded = DateTime.Now; englishDesciption.DateModefied = DateTime.Now; englishDesciption.LanguageId = (long)Langs.English; _unitOfWork.SizeAttributeDescriptionRepository.Insert(arabicDesciption); _unitOfWork.SizeAttributeDescriptionRepository.Insert(englishDesciption); _unitOfWork.Save(); return(new OperationDetails(true, "تمت الإضافة بنجاح", option.Id.ToString())); }
/// <summary> /// Parses a URDF <mesh> element from XML. /// </summary> /// <param name="node">The XML node of a <mesh> element</param> /// <returns>A Mesh object parsed from the XML</returns> public override Mesh Parse(XmlNode node) { ValidateXmlNode(node); XmlAttribute fileNameAttribute = GetAttributeFromNode(node, UrdfSchema.FILE_NAME_ATTRIBUTE_NAME); XmlAttribute scaleAttribute = GetAttributeFromNode(node, UrdfSchema.SCALE_ATTRIBUTE_NAME); XmlAttribute sizeAttribute = GetAttributeFromNode(node, UrdfSchema.SIZE_ATTRIBUTE_NAME); string fileName = ParseFileName(fileNameAttribute); ScaleAttribute scale = ParseScaleAttribute(scaleAttribute); SizeAttribute size = ParseSizeAttribute(sizeAttribute); Mesh.Builder builder = new Mesh.Builder(fileName); if (scale != null) { builder.SetScale(scale); } if (size != null) { builder.SetSize(size); } return(builder.Build()); }
/// <summary> /// Parses a URDF <box> element from XML. /// </summary> /// <param name="node">The XML node of a <box> element. MUST NOT BE NULL</param> /// <returns>A Box object parsed from the XML</returns> public override Box Parse(XmlNode node) { ValidateXmlNode(node); XmlAttribute sizeAttribute = GetAttributeFromNode(node, UrdfSchema.SIZE_ATTRIBUTE_NAME); SizeAttribute size = new SizeAttribute(DEFAULT_VALUE, DEFAULT_VALUE, DEFAULT_VALUE); if (sizeAttribute == null) { LogMissingRequiredAttribute(UrdfSchema.SIZE_ATTRIBUTE_NAME); } else { if (!RegexUtils.IsMatchNDoubles(sizeAttribute.Value, 3)) { LogMalformedAttribute(UrdfSchema.SIZE_ATTRIBUTE_NAME); } else { double[] values = RegexUtils.MatchDoubles(sizeAttribute.Value); size = new SizeAttribute(values[0], values[1], values[2]); } } return(new Box(size)); }
private static Attribute ConvertToSize(XmlNhvmRuleConverterArgs rule) { NhvmSize sizeRule = (NhvmSize)rule.schemaRule; int min = int.MinValue; int max = int.MaxValue; if (sizeRule.minSpecified) { min = sizeRule.min; } if (sizeRule.maxSpecified) { max = sizeRule.max; } log.Info(string.Format("Converting to Size attribute with min {0}, max {1}", min, max)); SizeAttribute thisAttribute = new SizeAttribute(); thisAttribute.Min = min; thisAttribute.Max = max; if (sizeRule.message != null) { thisAttribute.Message = sizeRule.message; } AssignTagsFromString(thisAttribute, sizeRule.tags); return(thisAttribute); }
/// <summary> /// Creates a new instance of Mesh with the specified file name, specified scale and specified size. /// An Mesh.Builder must be used to instantiate a Mesh with optional properties as specified. /// </summary> /// <param name="fileName">The mesh object file name. MUST NOT BE EMPTY</param> /// <param name="scale">The scale of the mesh object. MUST NOT BE NULL</param> /// <param name="size">The size of the mesh object. MAY BE NULL</param> private Mesh(string fileName, ScaleAttribute scale, SizeAttribute size) { Preconditions.IsNotEmpty(fileName, "Mesh file name property must not be null or empty"); Preconditions.IsNotNull(scale, "Mesh scale property must not be null"); this.FileName = fileName; this.Scale = scale; this.Size = size; }
/// <summary> /// Creates a new instance of Box. /// </summary> /// <param name="size">The side lengths of the box</param> public Box(SizeAttribute size) { Preconditions.IsNotNull(size, "Box size property must not be null"); Preconditions.IsTrue(size.Length > 0, "The length of a box must be greater than 0"); Preconditions.IsTrue(size.Width > 0, "The width of a box must be greater than 0"); Preconditions.IsTrue(size.Height > 0, "The height of a box must be greater than 0"); this.Size = size; }
/// <summary> /// Create native marshaller. /// </summary> /// <param name="type">Type of struct.</param> /// <param name="switchValue">Switch attribute value if presents.</param> /// <param name="sizeValue">Size attribute value if presents.</param> /// <param name="lengthValue">Length attribute value if presents.</param> /// <param name="marshalDesccriptor">marshal descriptor</param> /// <returns>created marshaller</returns> private static Marshaler CreateNativeMarshaller( Type type, object switchValue, object sizeValue, object lengthValue, bool force32Bit, int align, out MarshalingDescriptor marshalDesccriptor ) { MarshalingConfiguration mc = NativeMarshalingConfiguration.Configuration; if (align != -1) { mc.Alignment = align; } if (force32Bit) { mc.IntPtrSize = 4; } Marshaler marshaller = new Marshaler(mc); SwitchAttribute switchAttr = null; SizeAttribute sizeAttr = null; LengthAttribute lengthAttr = null; string nameSuffix = DateTime.UtcNow.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture); if (switchValue != null) { string switchSymbolName = "switch_" + nameSuffix; marshaller.DefineSymbol(switchSymbolName, switchValue); switchAttr = new SwitchAttribute(switchSymbolName); } if (sizeValue != null) { string sizeSymbolName = "size_" + nameSuffix; marshaller.DefineSymbol(sizeSymbolName, sizeValue); sizeAttr = new SizeAttribute(sizeSymbolName); } if (lengthValue != null) { string lengthSymbolName = "length_" + nameSuffix; marshaller.DefineSymbol(lengthSymbolName, lengthValue); lengthAttr = new LengthAttribute(lengthSymbolName); } TypeCustomAttributeProvider attrProvider = new TypeCustomAttributeProvider(switchAttr, sizeAttr, lengthAttr); marshalDesccriptor = new MarshalingDescriptor(type, attrProvider); return(marshaller); }
public void EqualsAndHash() { SizeAttribute size = new SizeAttribute(1, 2, 3); SizeAttribute same = new SizeAttribute(1, 2, 3); SizeAttribute diff = new SizeAttribute(7, 7, 7); Assert.IsTrue(size.Equals(size)); Assert.IsFalse(size.Equals(null)); Assert.IsTrue(size.Equals(same)); Assert.IsTrue(same.Equals(size)); Assert.IsFalse(size.Equals(diff)); Assert.AreEqual(size.GetHashCode(), same.GetHashCode()); Assert.AreNotEqual(size.GetHashCode(), diff.GetHashCode()); }
public void ParseMeshNoScale() { string fileName = "fileName"; SizeAttribute size = new SizeAttribute(4, 5, 6); string xml = String.Format("<mesh filename='{0}' size='{1} {2} {3}'/>", fileName, size.Length, size.Width, size.Height); this.xmlDoc.Load(XmlReader.Create(new StringReader(xml))); Mesh mesh = this.parser.Parse(this.xmlDoc.DocumentElement); Assert.AreEqual(fileName, mesh.FileName); Assert.AreEqual(new ScaleAttribute(1, 1, 1), mesh.Scale); Assert.AreEqual(size, mesh.Size); }
public void ParseMeshNoFileName() { ScaleAttribute scale = new ScaleAttribute(1, 2, 3); SizeAttribute size = new SizeAttribute(4, 5, 6); string xml = String.Format("<mesh scale='{0} {1} {2}' size='{3} {4} {5}'/>", scale.X, scale.Y, scale.Z, size.Length, size.Width, size.Height); this.xmlDoc.Load(XmlReader.Create(new StringReader(xml))); Mesh mesh = this.parser.Parse(this.xmlDoc.DocumentElement); Assert.AreEqual(Mesh.DEFAULT_FILE_NAME, mesh.FileName); Assert.AreEqual(scale, mesh.Scale); Assert.AreEqual(size, mesh.Size); }
protected virtual void InitializeAttributes() { Type nodeType = GetType(); _hasDebugOverride = Attribute.GetCustomAttribute(nodeType, typeof(DebugOverrideAttribute)) != null; _isObsolete = Attribute.GetCustomAttribute(nodeType, typeof(ObsoleteAttribute)) != null; _isExperimental = Attribute.GetCustomAttribute(nodeType, typeof(ExperimentalAttribute)) != null; InputCountAttribute inputCountAttribute = (InputCountAttribute) Attribute.GetCustomAttribute(nodeType, typeof(InputCountAttribute)); _inputCount = inputCountAttribute == null ? 0 : inputCountAttribute.count; InputLabelsAttribute inputAttribute = (InputLabelsAttribute) Attribute.GetCustomAttribute(nodeType, typeof(InputLabelsAttribute)); _inputLabels = inputAttribute == null ? new string[0] : inputAttribute.labels; OutputCountAttribute outputCountAttribute = (OutputCountAttribute) Attribute.GetCustomAttribute(nodeType, typeof(OutputCountAttribute)); _outputCount = outputCountAttribute == null ? 0 : outputCountAttribute.count; OutputLabelsAttribute outputAttribute = (OutputLabelsAttribute) Attribute.GetCustomAttribute(nodeType, typeof(OutputLabelsAttribute)); _outputLabels = outputAttribute == null ? new string[0] : outputAttribute.labels; #if UNITY_EDITOR SkinAttribute skinAttribute = (SkinAttribute) Attribute.GetCustomAttribute(nodeType, typeof(SkinAttribute)); _backgroundSkinId = skinAttribute != null ? skinAttribute.backgroundSkinId : "NodeBodyBg"; _titleSkinId = skinAttribute != null ? skinAttribute.titleSkinId : "NodeTitleBg"; SizeAttribute sizeAttribute = (SizeAttribute) Attribute.GetCustomAttribute(nodeType, typeof(SizeAttribute)); _size = sizeAttribute != null ? new Vector2(sizeAttribute.width, sizeAttribute.height) : Vector2.one; DisableBaseGUIAttribute disableBaseGuiAttribute = (DisableBaseGUIAttribute) Attribute.GetCustomAttribute(nodeType, typeof(DisableBaseGUIAttribute)); _baseGUIEnabled = disableBaseGuiAttribute == null; CategoryAttribute categoryAttribute = (CategoryAttribute) Attribute.GetCustomAttribute(nodeType, typeof(CategoryAttribute)); Category = categoryAttribute.type; //_iconTexture = iconAttribute != null ? IconManager.GetIcon(iconAttribute.iconId) : DashEditorCore.EditorConfig.theme.GetNodeIconByCategory(categoryAttribute.type); // _nodeBackgroundColor = DashEditorCore.EditorConfig.theme.GetNodeBackgroundColorByCategory(categoryAttribute.type); // // _titleBackgroundColor = DashEditorCore.EditorConfig.theme.GetNodeTitleBackgroundColorByCategory(categoryAttribute.type); // // _titleTextColor = DashEditorCore.EditorConfig.theme.GetNodeTitleTextColorByCategory(categoryAttribute.type); #endif _attributesInitialized = true; }
public void ConstructMeshWithSize() { string fileName = "fileName"; double length = 1; double width = 2; double height = 3; SizeAttribute size = new SizeAttribute(length, width, height); Mesh mesh = new Mesh.Builder(fileName).SetSize(size).Build(); Assert.AreEqual(fileName, mesh.FileName); Assert.IsNotNull(mesh.Scale); Assert.AreEqual(size, mesh.Size); Assert.AreEqual(length, size.Length); Assert.AreEqual(width, size.Width); Assert.AreEqual(height, size.Height); }
public void ConstructBox() { double length = 1; double width = 2; double height = 3; SizeAttribute size = new SizeAttribute(length, width, height); Box box = new Box(size); Assert.AreEqual(size, box.Size); Assert.AreEqual(size.Length, length); Assert.AreEqual(size.Width, width); Assert.AreEqual(size.Height, height); Assert.AreNotEqual(size.Length, 0); Assert.AreNotEqual(size.Width, 0); Assert.AreNotEqual(size.Height, 0); }
public void IsValid() { var v = new SizeAttribute(); Assert.IsTrue(v.IsValid(new int[0], null)); v = new SizeAttribute(1, 3); Assert.IsTrue(v.IsValid(new int[1], null)); Assert.IsTrue(v.IsValid(new int[3], null)); Assert.IsTrue(v.IsValid(null, null)); Assert.IsFalse(v.IsValid(new int[0], null)); Assert.IsFalse(v.IsValid(new int[4], null)); // Assert.IsFalse(v.IsValid("465", null)); <= if size can validate a string then is not a big problem Assert.IsFalse(v.IsValid(123456, null)); }
public void ConstructSizeAttribute() { double length = 1; double width = 2; double height = 3; SizeAttribute size = new SizeAttribute(length, width, height); Assert.AreEqual(length, size.Length); Assert.AreEqual(width, size.Width); Assert.AreEqual(height, size.Height); Assert.AreNotEqual(length, size.Width); Assert.AreNotEqual(length, size.Height); Assert.AreNotEqual(width, size.Length); Assert.AreNotEqual(width, size.Height); Assert.AreNotEqual(height, size.Length); Assert.AreNotEqual(height, size.Width); }
public void IsValidWithGenericCollections() { var v = new SizeAttribute(); Assert.IsTrue(v.IsValid(new HashSet <int>(), null)); v = new SizeAttribute(1, 3); Assert.IsTrue(v.IsValid(new HashSet <int> { 1 }, null)); Assert.IsTrue(v.IsValid(new HashSet <int> { 1, 2, 3 }, null)); Assert.IsFalse(v.IsValid(new HashSet <int> { 1, 2, 3, 4, 5, 6 }, null)); }
public void ConstructMeshWithScaleAndSize() { string fileName = "fileName"; double scaleX = 1; double scaleY = 2; double scaleZ = 3; ScaleAttribute scale = new ScaleAttribute(scaleX, scaleY, scaleZ); double length = 11; double width = 22; double height = 33; SizeAttribute size = new SizeAttribute(length, width, height); Mesh mesh = new Mesh.Builder(fileName).SetScale(scale).SetSize(size).Build(); Assert.AreEqual(fileName, mesh.FileName); Assert.AreEqual(scale, mesh.Scale); Assert.AreEqual(scaleX, mesh.Scale.X); Assert.AreEqual(scaleY, mesh.Scale.Y); Assert.AreEqual(scaleZ, mesh.Scale.Z); Assert.AreEqual(size, mesh.Size); Assert.AreEqual(length, size.Length); Assert.AreEqual(width, size.Width); Assert.AreEqual(height, size.Height); }
private SizeAttribute ParseSizeAttribute(XmlAttribute sizeAttribute) { SizeAttribute size = null; if (sizeAttribute == null) { LogMissingOptionalAttribute(UrdfSchema.SIZE_ATTRIBUTE_NAME); } else { if (!RegexUtils.IsMatchNDoubles(sizeAttribute.Value, 3)) { LogMalformedAttribute(UrdfSchema.SIZE_ATTRIBUTE_NAME); } else { double[] values = RegexUtils.MatchDoubles(sizeAttribute.Value); size = new SizeAttribute(values[0], values[1], values[2]); } } return(size); }
//public List<SizeAttributeValueDTO> GetSizeAttributeValuesBySizeAttributeId(long Id) //{ // List<SizeAttributeValueDTO> dtos = new List<SizeAttributeValueDTO>(); // List<SizeAttributeMedian> sizeAttributesValues = _unitOfWork.SizeAttributeMedianRepository.Get(c => c.SizeAttributeId == Id).ToList(); // foreach (var AttributeValue in sizeAttributesValues) // { // SizeAttributeValueDTO dto = new SizeAttributeValueDTO(); // dto.SizeAttributeId = AttributeValue.SizeAttributeId; // dto.Id = AttributeValue.Id; // dto.DateModified = AttributeValue.DateModefied ?? AttributeValue.DateModefied.Value; // dto.SizeValueId = AttributeValue.SizeValueId; // dto.SizeValueName = _unitOfWork.SizeHelperRepository.Get(c => c.Id == AttributeValue.SizeValueId).Select(g => g.ArabicName).FirstOrDefault(); // dto.SizeCategoryName = _unitOfWork.SizeHelperRepository.Get(c => c.Id == AttributeValue.SizeValueId).Select(g => g.ArabicSizeCategoryName).FirstOrDefault(); // dto.Value = AttributeValue.Value; // dtos.Add(dto); // } // return dtos; //} public AddSizeAttributeDTO GetSizeAttributeById(long Id) { AddSizeAttributeDTO addDTO = new AddSizeAttributeDTO(); SizeAttribute sizeAttribute = _unitOfWork.SizeAttributeRepository.Get(c => c.Id == Id).FirstOrDefault(); long arabicLang = (long)Langs.Arabic; long englishLang = (long)Langs.English; addDTO.SizeAttribute = new SizeAttributeDTO { ArabicName = _unitOfWork.SizeAttributeDescriptionRepository.Get(c => c.SizeAttributeId == Id && c.LanguageId == arabicLang).Select(g => g.Name).FirstOrDefault(), EnglishName = _unitOfWork.SizeAttributeDescriptionRepository.Get(c => c.SizeAttributeId == Id && c.LanguageId == englishLang).Select(g => g.Name).FirstOrDefault(), Id = Id, SizeCategoryId = sizeAttribute.SizeCatId, DateModified = sizeAttribute.DateModefied ?? sizeAttribute.DateModefied.Value }; //addDTO.SizeAttributeValues = GetSizeAttributeValuesBySizeAttributeId(Id); addDTO.SizeAttributeValues = new List <SizeAttributeValueDTO>(); addDTO.SizesCategories = _productManagerService.GetAllSizeOptions(); return(addDTO); }
public void Initialize() { if (isInitialized) { return; } lock (this.initializeLock) { Dictionary <string, FieldInfo> rowFields; Dictionary <string, PropertyInfo> rowProperties; GetRowFieldsAndProperties(out rowFields, out rowProperties); foreach (var fieldInfo in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)) { if (fieldInfo.FieldType.IsSubclassOf(typeof(Field))) { var field = (Field)fieldInfo.GetValue(this); PropertyInfo property; if (!rowProperties.TryGetValue(fieldInfo.Name, out property)) { property = null; } ColumnAttribute column = null; DisplayNameAttribute display = null; SizeAttribute size = null; ExpressionAttribute expression = null; ScaleAttribute scale = null; MinSelectLevelAttribute selectLevel = null; ForeignKeyAttribute foreignKey = null; LeftJoinAttribute foreignJoin = null; DefaultValueAttribute defaultValue = null; TextualFieldAttribute textualField = null; DateTimeKindAttribute dateTimeKind = null; FieldFlags addFlags = (FieldFlags)0; FieldFlags removeFlags = (FieldFlags)0; if (property != null) { column = property.GetCustomAttribute <ColumnAttribute>(false); display = property.GetCustomAttribute <DisplayNameAttribute>(false); size = property.GetCustomAttribute <SizeAttribute>(false); expression = property.GetCustomAttribute <ExpressionAttribute>(false); scale = property.GetCustomAttribute <ScaleAttribute>(false); selectLevel = property.GetCustomAttribute <MinSelectLevelAttribute>(false); foreignKey = property.GetCustomAttribute <ForeignKeyAttribute>(false); foreignJoin = property.GetCustomAttributes <LeftJoinAttribute>(false).FirstOrDefault(x => x.ToTable == null && x.OnCriteria == null); defaultValue = property.GetCustomAttribute <DefaultValueAttribute>(false); textualField = property.GetCustomAttribute <TextualFieldAttribute>(false); dateTimeKind = property.GetCustomAttribute <DateTimeKindAttribute>(false); var insertable = property.GetCustomAttribute <InsertableAttribute>(false); var updatable = property.GetCustomAttribute <UpdatableAttribute>(false); if (insertable != null && !insertable.Value) { removeFlags |= FieldFlags.Insertable; } if (updatable != null && !updatable.Value) { removeFlags |= FieldFlags.Updatable; } foreach (var attr in property.GetCustomAttributes <SetFieldFlagsAttribute>(false)) { addFlags |= attr.Add; removeFlags |= attr.Remove; } } if (ReferenceEquals(null, field)) { if (property == null) { throw new InvalidProgramException(String.Format( "Field {0} in type {1} is null and has no corresponding property in entity!", fieldInfo.Name, rowType.Name)); } object[] prm = new object[7]; prm[0] = this; // owner prm[1] = column == null ? property.Name : (column.Name.TrimToNull() ?? property.Name); prm[2] = display != null ? new LocalText(display.DisplayName) : null; prm[3] = size != null ? size.Value : 0; prm[4] = (FieldFlags.Default ^ removeFlags) | addFlags; prm[5] = null; prm[6] = null; FieldInfo storage; if (rowFields.TryGetValue("_" + property.Name, out storage) || rowFields.TryGetValue("m_" + property.Name, out storage) || rowFields.TryGetValue(property.Name, out storage)) { prm[5] = CreateFieldGetMethod(storage); prm[6] = CreateFieldSetMethod(storage); } field = (Field)Activator.CreateInstance(fieldInfo.FieldType, prm); fieldInfo.SetValue(this, field); } else { if (size != null) { throw new InvalidProgramException(String.Format( "Field size '{0}' in type {1} can't be overridden by Size attribute!", fieldInfo.Name, rowType.Name)); } if (display != null) { field.Caption = new LocalText(display.DisplayName); } if ((int)addFlags != 0 || (int)removeFlags != 0) { field.Flags = (field.Flags ^ removeFlags) | addFlags; } if (column != null && String.Compare(column.Name, field.Name, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidProgramException(String.Format( "Field name '{0}' in type {1} can't be overridden by Column name attribute!", fieldInfo.Name, rowType.Name)); } } if (scale != null) { field.Scale = scale.Value; } if (defaultValue != null) { field.DefaultValue = defaultValue.Value; } if (selectLevel != null) { field.MinSelectLevel = selectLevel.Value; } if (expression != null) { field.Expression = expression.Value; } if (foreignKey != null) { field.ForeignTable = foreignKey.Table; field.ForeignField = foreignKey.Field; } if (foreignJoin != null) { field.ForeignJoinAlias = new LeftJoin(this.joins, field.ForeignTable, foreignJoin.Alias, new Criteria(foreignJoin.Alias, field.ForeignField) == new Criteria(field)); } if (textualField != null) { field.textualField = textualField.Value; } if (dateTimeKind != null && field is DateTimeField) { ((DateTimeField)field).DateTimeKind = dateTimeKind.Value; } if (property != null) { if (property.PropertyType != null && field is IEnumTypeField) { if (property.PropertyType.IsEnum) { (field as IEnumTypeField).EnumType = property.PropertyType; } else { var nullableType = Nullable.GetUnderlyingType(property.PropertyType); if (nullableType != null && nullableType.IsEnum) { (field as IEnumTypeField).EnumType = nullableType; } } } foreach (var attr in property.GetCustomAttributes <LeftJoinAttribute>()) { if (attr.ToTable != null && attr.OnCriteria != null) { new LeftJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.Alias, attr.OnCriteria) == new Criteria(field)); } } field.PropertyName = property.Name; this.byPropertyName[field.PropertyName] = field; field.CustomAttributes = property.GetCustomAttributes(false); } } } foreach (var attr in this.rowType.GetCustomAttributes <LeftJoinAttribute>()) { new LeftJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.OnCriteria)); } foreach (var attr in this.rowType.GetCustomAttributes <OuterApplyAttribute>()) { new OuterApply(this.joins, attr.InnerQuery, attr.Alias); } var propertyDescriptorArray = new PropertyDescriptor[this.Count]; for (int i = 0; i < this.Count; i++) { var field = this[i]; propertyDescriptorArray[i] = new FieldDescriptor(field); } this.propertyDescriptors = new PropertyDescriptorCollection(propertyDescriptorArray); InferTextualFields(); AfterInitialize(); } isInitialized = true; }
public void Initialize() { if (isInitialized) { return; } lock (this.initializeLock) { Dictionary <string, FieldInfo> rowFields; Dictionary <string, IPropertyInfo> rowProperties; GetRowFieldsAndProperties(out rowFields, out rowProperties); var expressionSelector = new DialectExpressionSelector(connectionKey); var rowCustomAttributes = this.rowType.GetCustomAttributes().ToList(); foreach (var fieldInfo in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)) { if (fieldInfo.FieldType.IsSubclassOf(typeof(Field))) { var field = (Field)fieldInfo.GetValue(this); IPropertyInfo property; if (!rowProperties.TryGetValue(fieldInfo.Name, out property)) { property = null; } ColumnAttribute column = null; DisplayNameAttribute display = null; SizeAttribute size = null; ExpressionAttribute expression = null; ScaleAttribute scale = null; MinSelectLevelAttribute selectLevel = null; ForeignKeyAttribute foreignKey = null; LeftJoinAttribute leftJoin = null; InnerJoinAttribute innerJoin = null; DefaultValueAttribute defaultValue = null; TextualFieldAttribute textualField = null; DateTimeKindAttribute dateTimeKind = null; PermissionAttributeBase readPermission = null; PermissionAttributeBase insertPermission = null; PermissionAttributeBase updatePermission = null; FieldFlags addFlags = (FieldFlags)0; FieldFlags removeFlags = (FieldFlags)0; OriginPropertyDictionary propertyDictionary = null; if (property != null) { var origin = property.GetAttribute <OriginAttribute>(); column = property.GetAttribute <ColumnAttribute>(); display = property.GetAttribute <DisplayNameAttribute>(); size = property.GetAttribute <SizeAttribute>(); var expressions = property.GetAttributes <ExpressionAttribute>(); if (expressions.Any()) { expression = expressionSelector.GetBestMatch(expressions, x => x.Dialect); } scale = property.GetAttribute <ScaleAttribute>(); selectLevel = property.GetAttribute <MinSelectLevelAttribute>(); foreignKey = property.GetAttribute <ForeignKeyAttribute>(); leftJoin = property.GetAttributes <LeftJoinAttribute>() .FirstOrDefault(x => x.ToTable == null && x.OnCriteria == null); innerJoin = property.GetAttributes <InnerJoinAttribute>() .FirstOrDefault(x => x.ToTable == null && x.OnCriteria == null); defaultValue = property.GetAttribute <DefaultValueAttribute>(); textualField = property.GetAttribute <TextualFieldAttribute>(); dateTimeKind = property.GetAttribute <DateTimeKindAttribute>(); readPermission = property.GetAttribute <ReadPermissionAttribute>(); insertPermission = property.GetAttribute <InsertPermissionAttribute>() ?? property.GetAttribute <ModifyPermissionAttribute>() ?? readPermission; updatePermission = property.GetAttribute <UpdatePermissionAttribute>() ?? property.GetAttribute <ModifyPermissionAttribute>() ?? readPermission; if (origin != null) { propertyDictionary = propertyDictionary ?? OriginPropertyDictionary.GetPropertyDictionary(this.rowType); try { if (!expressions.Any() && expression == null) { expression = new ExpressionAttribute(propertyDictionary.OriginExpression( property.Name, origin, expressionSelector, "", rowCustomAttributes)); } if (display == null) { display = new DisplayNameAttribute(propertyDictionary.OriginDisplayName(property.Name, origin)); } if (size == null) { size = propertyDictionary.OriginAttribute <SizeAttribute>(property.Name, origin); } if (scale == null) { scale = propertyDictionary.OriginAttribute <ScaleAttribute>(property.Name, origin); } } catch (DivideByZeroException) { throw new InvalidProgramException(String.Format( "Infinite recursion detected while determining origins " + "for property '{0}' on row type '{1}'", property.Name, rowType.FullName)); } } var insertable = property.GetAttribute <InsertableAttribute>(); var updatable = property.GetAttribute <UpdatableAttribute>(); if (insertable != null && !insertable.Value) { removeFlags |= FieldFlags.Insertable; } if (updatable != null && !updatable.Value) { removeFlags |= FieldFlags.Updatable; } foreach (var attr in property.GetAttributes <SetFieldFlagsAttribute>()) { addFlags |= attr.Add; removeFlags |= attr.Remove; } } if (ReferenceEquals(null, field)) { if (property == null) { throw new InvalidProgramException(String.Format( "Field {0} in type {1} is null and has no corresponding property in entity!", fieldInfo.Name, rowType.Name)); } object[] prm = new object[7]; prm[0] = this; // owner prm[1] = column == null ? property.Name : (column.Name.TrimToNull() ?? property.Name); prm[2] = display != null ? new LocalText(display.DisplayName) : null; prm[3] = size != null ? size.Value : 0; var defaultFlags = FieldFlags.Default; if (fieldInfo.FieldType.GetCustomAttribute <NotMappedAttribute>() != null) { defaultFlags |= FieldFlags.NotMapped; } prm[4] = (defaultFlags ^ removeFlags) | addFlags; prm[5] = null; prm[6] = null; FieldInfo storage; if (rowFields.TryGetValue("_" + property.Name, out storage) || rowFields.TryGetValue("m_" + property.Name, out storage) || rowFields.TryGetValue(property.Name, out storage)) { prm[5] = CreateFieldGetMethod(storage); prm[6] = CreateFieldSetMethod(storage); } field = (Field)Activator.CreateInstance(fieldInfo.FieldType, prm); fieldInfo.SetValue(this, field); } else { if (size != null) { throw new InvalidProgramException(String.Format( "Field size '{0}' in type {1} can't be overridden by Size attribute!", fieldInfo.Name, rowType.FullName)); } if (display != null) { field.Caption = new LocalText(display.DisplayName); } if ((int)addFlags != 0 || (int)removeFlags != 0) { field.Flags = (field.Flags ^ removeFlags) | addFlags; } if (column != null && String.Compare(column.Name, field.Name, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidProgramException(String.Format( "Field name '{0}' in type {1} can't be overridden by Column name attribute!", fieldInfo.Name, rowType.FullName)); } } if (scale != null) { field.Scale = scale.Value; } if (defaultValue != null) { field.DefaultValue = defaultValue.Value; } if (selectLevel != null) { field.MinSelectLevel = selectLevel.Value; } if (expression != null) { field.Expression = expression.Value; } if (foreignKey != null) { field.ForeignTable = foreignKey.Table; field.ForeignField = foreignKey.Field; } if ((leftJoin != null || innerJoin != null) && field.ForeignTable.IsEmptyOrNull()) { throw new InvalidProgramException(String.Format("Property {0} of row type {1} has a [LeftJoin] or [InnerJoin] attribute " + "but its foreign table is undefined. Make sure it has a valid [ForeignKey] attribute!", fieldInfo.Name, rowType.FullName)); } if ((leftJoin != null || innerJoin != null) && field.ForeignField.IsEmptyOrNull()) { throw new InvalidProgramException(String.Format("Property {0} of row type {1} has a [LeftJoin] or [InnerJoin] attribute " + "but its foreign field is undefined. Make sure it has a valid [ForeignKey] attribute!", fieldInfo.Name, rowType.FullName)); } if (leftJoin != null) { field.ForeignJoinAlias = new LeftJoin(this.joins, field.ForeignTable, leftJoin.Alias, new Criteria(leftJoin.Alias, field.ForeignField) == new Criteria(field)); } if (innerJoin != null) { field.ForeignJoinAlias = new InnerJoin(this.joins, field.ForeignTable, innerJoin.Alias, new Criteria(innerJoin.Alias, field.ForeignField) == new Criteria(field)); } if (textualField != null) { field.textualField = textualField.Value; } if (dateTimeKind != null && field is DateTimeField) { ((DateTimeField)field).DateTimeKind = dateTimeKind.Value; } if (readPermission != null) { field.readPermission = readPermission.Permission ?? "?"; } if (insertPermission != null) { field.insertPermission = insertPermission.Permission ?? "?"; } if (updatePermission != null) { field.updatePermission = updatePermission.Permission ?? "?"; } if (property != null) { if (property.PropertyType != null && field is IEnumTypeField) { if (property.PropertyType.IsEnum) { (field as IEnumTypeField).EnumType = property.PropertyType; } else { var nullableType = Nullable.GetUnderlyingType(property.PropertyType); if (nullableType != null && nullableType.IsEnum) { (field as IEnumTypeField).EnumType = nullableType; } } } foreach (var attr in property.GetAttributes <LeftJoinAttribute>()) { if (attr.ToTable != null && attr.OnCriteria != null) { new LeftJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.Alias, attr.OnCriteria) == new Criteria(field)); } } foreach (var attr in property.GetAttributes <InnerJoinAttribute>()) { if (attr.ToTable != null && attr.OnCriteria != null) { new InnerJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.Alias, attr.OnCriteria) == new Criteria(field)); } } field.PropertyName = property.Name; this.byPropertyName[field.PropertyName] = field; field.customAttributes = property.GetAttributes <Attribute>().ToArray(); } } } foreach (var attr in rowCustomAttributes.OfType <LeftJoinAttribute>()) { new LeftJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.OnCriteria)); } foreach (var attr in rowCustomAttributes.OfType <InnerJoinAttribute>()) { new InnerJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.OnCriteria)); } foreach (var attr in rowCustomAttributes.OfType <OuterApplyAttribute>()) { new OuterApply(this.joins, attr.InnerQuery, attr.Alias); } #if !COREFX var propertyDescriptorArray = new PropertyDescriptor[this.Count]; for (int i = 0; i < this.Count; i++) { var field = this[i]; propertyDescriptorArray[i] = new FieldDescriptor(field); } this.propertyDescriptors = new PropertyDescriptorCollection(propertyDescriptorArray); #endif InferTextualFields(); AfterInitialize(); } isInitialized = true; }
protected bool Equals(SizeAttribute other) { return(Length.Equals(other.Length) && Width.Equals(other.Width) && Height.Equals(other.Height)); }
public Builder SetSize(SizeAttribute size) { this.size = size; return(this); }
public void KnownRulesConvertAssing() { NhvMapping map = XmlMappingLoader.GetXmlMappingFor(typeof(WellKnownRules)); NhvmClass cm = map.@class[0]; XmlClassMapping rm = new XmlClassMapping(cm); MemberInfo mi; List <Attribute> attributes; mi = typeof(WellKnownRules).GetField("AP"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); Assert.AreEqual("A string value", ((ACustomAttribute)attributes[0]).Value1); Assert.AreEqual(123, ((ACustomAttribute)attributes[0]).Value2); Assert.AreEqual("custom message", ((ACustomAttribute)attributes[0]).Message); mi = typeof(WellKnownRules).GetField("StrProp"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); NotEmptyAttribute nea = FindAttribute <NotEmptyAttribute>(attributes); Assert.AreEqual("not-empty message", nea.Message); NotNullAttribute nna = FindAttribute <NotNullAttribute>(attributes); Assert.AreEqual("not-null message", nna.Message); NotNullNotEmptyAttribute nnea = FindAttribute <NotNullNotEmptyAttribute>(attributes); Assert.AreEqual("notnullnotempty message", nnea.Message); LengthAttribute la = FindAttribute <LengthAttribute>(attributes); Assert.AreEqual("length message", la.Message); Assert.AreEqual(1, la.Min); Assert.AreEqual(10, la.Max); PatternAttribute pa = FindAttribute <PatternAttribute>(attributes); Assert.AreEqual("pattern message", pa.Message); Assert.AreEqual("[0-9]+", pa.Regex); Assert.AreEqual(RegexOptions.Compiled, pa.Flags); EmailAttribute ea = FindAttribute <EmailAttribute>(attributes); Assert.AreEqual("email message", ea.Message); IPAddressAttribute ipa = FindAttribute <IPAddressAttribute>(attributes); Assert.AreEqual("ipAddress message", ipa.Message); EANAttribute enaa = FindAttribute <EANAttribute>(attributes); Assert.AreEqual("ean message", enaa.Message); CreditCardNumberAttribute ccna = FindAttribute <CreditCardNumberAttribute>(attributes); Assert.AreEqual("creditcardnumber message", ccna.Message); IBANAttribute iban = FindAttribute <IBANAttribute>(attributes); Assert.AreEqual("iban message", iban.Message); mi = typeof(WellKnownRules).GetField("DtProp"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); FutureAttribute fa = FindAttribute <FutureAttribute>(attributes); Assert.AreEqual("future message", fa.Message); PastAttribute psa = FindAttribute <PastAttribute>(attributes); Assert.AreEqual("past message", psa.Message); mi = typeof(WellKnownRules).GetField("DecProp"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); DigitsAttribute dga = FindAttribute <DigitsAttribute>(attributes); Assert.AreEqual("digits message", dga.Message); Assert.AreEqual(5, dga.IntegerDigits); Assert.AreEqual(2, dga.FractionalDigits); MinAttribute mina = FindAttribute <MinAttribute>(attributes); Assert.AreEqual("min message", mina.Message); Assert.AreEqual(100, mina.Value); MaxAttribute maxa = FindAttribute <MaxAttribute>(attributes); Assert.AreEqual("max message", maxa.Message); Assert.AreEqual(200, maxa.Value); DecimalMaxAttribute decimalmaxa = FindAttribute <DecimalMaxAttribute>(attributes); Assert.AreEqual("decimal max message", decimalmaxa.Message); Assert.AreEqual(200.1m, decimalmaxa.Value); DecimalMinAttribute decimalmina = FindAttribute <DecimalMinAttribute>(attributes); Assert.AreEqual("decimal min message", decimalmina.Message); Assert.AreEqual(99.9m, decimalmina.Value); mi = typeof(WellKnownRules).GetField("BProp"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); AssertTrueAttribute ata = FindAttribute <AssertTrueAttribute>(attributes); Assert.AreEqual("asserttrue message", ata.Message); AssertFalseAttribute afa = FindAttribute <AssertFalseAttribute>(attributes); Assert.AreEqual("assertfalse message", afa.Message); mi = typeof(WellKnownRules).GetField("ArrProp"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); SizeAttribute sa = FindAttribute <SizeAttribute>(attributes); Assert.AreEqual("size message", sa.Message); Assert.AreEqual(2, sa.Min); Assert.AreEqual(9, sa.Max); mi = typeof(WellKnownRules).GetField("Pattern"); attributes = new List <Attribute>(rm.GetMemberAttributes(mi)); PatternAttribute spa = FindAttribute <PatternAttribute>(attributes); Assert.AreEqual("{validator.pattern}", spa.Message); Assert.AreEqual(@"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", spa.Regex); Assert.AreEqual(RegexOptions.CultureInvariant | RegexOptions.IgnoreCase, spa.Flags); }