Exemplo n.º 1
0
        protected static Encodable readEncodable(ByteStream source, ObjectType objectType,
                                                 PropertyIdentifier propertyIdentifier, UnsignedInteger propertyArrayIndex, int contextId)
        {
            // A property array index of 0 indicates a request for the Length of an array.
            if (propertyArrayIndex != null && propertyArrayIndex.Value == 0)
            {
                return(readWrapped(source, typeof(UnsignedInteger), contextId));
            }

            if (!matchNonEndTag(source, contextId))
            {
                throw new BACnetErrorException(ErrorClass.Property, ErrorCode.MissingRequiredParameter);
            }

            PropertyTypeDefinition def = ObjectProperties.getPropertyTypeDefinition(objectType, propertyIdentifier);

            if (def == null)
            {
                return(new AmbiguousValue(source, contextId));
            }

            if (ObjectProperties.isCommandable(objectType, propertyIdentifier))
            {
                // If the object is commandable, it could be set to Null, so we need to treat it as ambiguous.
                AmbiguousValue amb = new AmbiguousValue(source, contextId);

                if (amb.IsNull)
                {
                    return(new Null());
                }

                // Try converting to the definition value.
                return((Encodable)amb.ConvertTo(def.Type));
            }

            if (propertyArrayIndex != null)
            {
                if (!def.IsSequence && !def.Type.IsSubclassOf(typeof(SequenceOf)))
                {
                    throw new BACnetErrorException(ErrorClass.Property, ErrorCode.PropertyIsNotAList);
                }
                if (def.Type.IsSubclassOf(typeof(SequenceOf)))
                {
                    return(readWrapped(source, def.InnerType, contextId));
                }
            }
            else
            {
                if (def.IsSequence)
                {
                    return(readSequenceOf(source, def.Type, contextId));
                }
                if (def.Type.IsSubclassOf(typeof(SequenceOf)))
                {
                    return(readSequenceType(source, def.Type, contextId));
                }
            }

            return(readWrapped(source, def.Type, contextId));
        }
Exemplo n.º 2
0
        public void removeProperty(PropertyIdentifier pid)
        {
            PropertyTypeDefinition def = ObjectProperties.getPropertyTypeDefinitionRequired(Id.ObjectType, pid);

            if (def.IsRequired)
            {
                throw new BACnetServiceException(ErrorClass.Property, ErrorCode.WriteAccessDenied);
            }
            properties.Remove(pid);
        }
Exemplo n.º 3
0
        protected static SequenceOf readSequenceOfEncodable(ByteStream source, ObjectType objectType,
                                                            PropertyIdentifier propertyIdentifier, int contextId)
        {
            PropertyTypeDefinition def = ObjectProperties.getPropertyTypeDefinition(objectType, propertyIdentifier);

            if (def == null)
            {
                return(readSequenceOf(source, typeof(AmbiguousValue), contextId));
            }
            return(readSequenceOf(source, def.Type, contextId));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectPropertyInfo"/> class.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        public ObjectPropertyInfo(PropertyInfo propertyInfo)
        {
            this.PropertyInfo = propertyInfo;

            object[] attributes = (object[])propertyInfo.GetCustomAttributes(typeof(BusinessObjectPropertyAttribute), false);
            if (attributes.Length > 0)
            {// attribute exists
                this.BusinessObjectPropertyAttribute    = ((BusinessObjectPropertyAttribute)attributes[0]);
                this.HasBusinessObjectPropertyAttribute = true;
            }

            attributes = (object[])propertyInfo.GetCustomAttributes(typeof(BusinessObjectValidationAttribute), false);
            if (attributes.Length > 0)
            {// found attribute
                this.BusinessObjectValidationAttribute    = attributes[0] as BusinessObjectValidationAttribute;
                this.HasBusinessObjectValidationAttribute = true;
            }

            if (propertyInfo.PropertyType == typeof(string))
            {
                this.PropertyType = PropertyTypeDefinition.String;
            }
            else if (propertyInfo.PropertyType == typeof(long))
            {
                this.PropertyType = PropertyTypeDefinition.Int64;
            }
            else if (propertyInfo.PropertyType == typeof(int))
            {
                this.PropertyType = PropertyTypeDefinition.Int32;
            }
            else if (propertyInfo.PropertyType == typeof(short))
            {
                this.PropertyType = PropertyTypeDefinition.Int16;
            }
            else if (propertyInfo.PropertyType == typeof(decimal))
            {
                this.PropertyType = PropertyTypeDefinition.Decimal;
            }
            else if (propertyInfo.PropertyType == typeof(double) || propertyInfo.PropertyType == typeof(Single))
            {
                this.PropertyType = PropertyTypeDefinition.Double;
            }

            if (this.PropertyType == PropertyTypeDefinition.String)
            {
                attributes = (object[])propertyInfo.GetCustomAttributes(typeof(BusinessObjectStringSecurityAttribute), false);
                if (attributes.Length > 0)
                {// found attribute
                    this.BusinessObjectStringSecurityAttribute    = attributes[0] as BusinessObjectStringSecurityAttribute;
                    this.HasBusinessObjectStringSecurityAttribute = true;
                }
            }
        }
Exemplo n.º 5
0
        public void removeProperty(PropertyIdentifier pid, UnsignedInteger propertyArrayIndex)
        {
            PropertyTypeDefinition def = ObjectProperties.getPropertyTypeDefinitionRequired(Id.ObjectType, pid);

            if (!def.IsSequence)
            {
                throw new BACnetServiceException(ErrorClass.Property, ErrorCode.InvalidArrayIndex);
            }
            SequenceOf sequence = (SequenceOf)properties[pid];

            if (sequence != null)
            {
                sequence.remove((int)propertyArrayIndex.Value);
            }
        }