Exemple #1
0
        /// <summary>
        /// Validates a read value id parameter.
        /// </summary>
        public static ServiceResult Validate(ReadValueId valueId)
        {
            // check for null structure.
            if (valueId == null)
            {
                return(StatusCodes.BadStructureMissing);
            }

            // null node ids are always invalid.
            if (valueId.NodeId == null)
            {
                return(StatusCodes.BadNodeIdInvalid);
            }

            // must be a legimate attribute value.
            if (!Attributes.IsValid(valueId.AttributeId))
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }

            // data encoding and index range is only valid for value attributes.
            if (valueId.AttributeId != Attributes.Value)
            {
                if (!String.IsNullOrEmpty(valueId.IndexRange))
                {
                    return(StatusCodes.BadIndexRangeNoData);
                }

                if (!QualifiedName.IsNull(valueId.DataEncoding))
                {
                    return(StatusCodes.BadDataEncodingInvalid);
                }
            }

            // initialize as empty.
            valueId.ParsedIndexRange = NumericRange.Empty;

            // parse the index range if specified.
            if (!String.IsNullOrEmpty(valueId.IndexRange))
            {
                try
                {
                    valueId.ParsedIndexRange = NumericRange.Parse(valueId.IndexRange);
                }
                catch (Exception e)
                {
                    return(ServiceResult.Create(e, StatusCodes.BadIndexRangeInvalid, String.Empty));
                }
            }
            else
            {
                valueId.ParsedIndexRange = NumericRange.Empty;
            }

            // passed basic validation.
            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Validates the operand (sets the ParsedBrowsePath and ParsedIndexRange properties).
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="index">The index.</param>
        /// <returns>The result of the validation.</returns>
        public override ServiceResult Validate(FilterContext context, int index)
        {
            m_validated = false;

            // verify that the operand refers to a node in the type model.
            if (!context.TypeTree.IsKnown(m_nodeId))
            {
                return(ServiceResult.Create(
                           StatusCodes.BadTypeDefinitionInvalid,
                           "AttributeOperand does not have a known TypeDefinitionId ({0}).",
                           m_nodeId));
            }

            // verify attribute id.
            if (!Attributes.IsValid(m_attributeId))
            {
                return(ServiceResult.Create(
                           StatusCodes.BadAttributeIdInvalid,
                           "AttributeOperand does not specify a valid AttributeId ({0}).",
                           m_attributeId));
            }

            // initialize as empty.
            m_parsedIndexRange = NumericRange.Empty;

            // parse the index range.
            if (!String.IsNullOrEmpty(m_indexRange))
            {
                try
                {
                    m_parsedIndexRange = NumericRange.Parse(m_indexRange);
                }
                catch (Exception e)
                {
                    return(ServiceResult.Create(
                               e,
                               StatusCodes.BadIndexRangeInvalid,
                               "AttributeOperand does not specify a valid BrowsePath ({0}).",
                               m_indexRange));
                }

                if (m_attributeId != Attributes.Value)
                {
                    return(ServiceResult.Create(
                               StatusCodes.BadIndexRangeInvalid,
                               "AttributeOperand specifies an IndexRange for an Attribute other than Value ({0}).",
                               m_attributeId));
                }
            }

            m_validated = true;

            return(ServiceResult.Good);
        }
Exemple #3
0
        /// <summary>
        /// Validates a write value parameter.
        /// </summary>
        public static ServiceResult Validate(WriteValue value)
        {
            // check for null structure.
            if (value == null)
            {
                return(StatusCodes.BadStructureMissing);
            }

            // null node ids are always invalid.
            if (value.NodeId == null)
            {
                return(StatusCodes.BadNodeIdInvalid);
            }

            // must be a legimate attribute value.
            if (!Attributes.IsValid(value.AttributeId))
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }

            // initialize as empty.
            value.ParsedIndexRange = NumericRange.Empty;

            // parse the index range if specified.
            if (!String.IsNullOrEmpty(value.IndexRange))
            {
                try
                {
                    value.ParsedIndexRange = NumericRange.Parse(value.IndexRange);
                }
                catch (Exception e)
                {
                    return(ServiceResult.Create(e, StatusCodes.BadIndexRangeInvalid, String.Empty));
                }

                // check that value provided is actually an array.
                Array array = value.Value.Value as Array;

                if (array == null)
                {
                    return(StatusCodes.BadTypeMismatch);
                }

                NumericRange range = value.ParsedIndexRange;

                // check that the number of elements to write matches the index range.
                if (range.End >= 0 && (range.End - range.Begin != array.Length - 1))
                {
                    return(StatusCodes.BadIndexRangeNoData);
                }

                // check for single element.
                if (range.End < 0 && array.Length != 1)
                {
                    return(StatusCodes.BadIndexRangeInvalid);
                }
            }
            else
            {
                value.ParsedIndexRange = NumericRange.Empty;
            }

            // passed basic validation.
            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Validates a write value parameter.
        /// </summary>
        public static ServiceResult Validate(WriteValue value)
        {
            // check for null structure.
            if (value == null)
            {
                return(StatusCodes.BadStructureMissing);
            }

            // null node ids are always invalid.
            if (value.NodeId == null)
            {
                return(StatusCodes.BadNodeIdInvalid);
            }

            // must be a legimate attribute value.
            if (!Attributes.IsValid(value.AttributeId))
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }

            // initialize as empty.
            value.ParsedIndexRange = NumericRange.Empty;

            // parse the index range if specified.
            if (!String.IsNullOrEmpty(value.IndexRange))
            {
                try
                {
                    value.ParsedIndexRange = NumericRange.Parse(value.IndexRange);
                }
                catch (Exception e)
                {
                    return(ServiceResult.Create(e, StatusCodes.BadIndexRangeInvalid, String.Empty));
                }

                if (value.ParsedIndexRange.SubRanges != null)
                {
                    Matrix matrix = value.Value.Value as Matrix;

                    if (matrix == null)
                    {
                        // Check for String or ByteString arrays. Those DataTypes have special handling
                        // when using sub ranges.
                        bool isArrayWithValidDataType = value.Value.Value is Array &&
                                                        value.Value.WrappedValue.TypeInfo.BuiltInType == BuiltInType.String ||
                                                        value.Value.WrappedValue.TypeInfo.BuiltInType == BuiltInType.ByteString;

                        if (!isArrayWithValidDataType)
                        {
                            return(StatusCodes.BadTypeMismatch);
                        }
                    }
                }
                else
                {
                    // check that value provided is actually an array.
                    Array  array = value.Value.Value as Array;
                    string str   = value.Value.Value as string;

                    if (array != null)
                    {
                        NumericRange range = value.ParsedIndexRange;

                        // check that the number of elements to write matches the index range.
                        if (range.End >= 0 && (range.End - range.Begin != array.Length - 1))
                        {
                            return(StatusCodes.BadIndexRangeNoData);
                        }

                        // check for single element.
                        if (range.End < 0 && array.Length != 1)
                        {
                            return(StatusCodes.BadIndexRangeInvalid);
                        }
                    }
                    else if (str != null)
                    {
                        NumericRange range = value.ParsedIndexRange;

                        // check that the number of elements to write matches the index range.
                        if (range.End >= 0 && (range.End - range.Begin != str.Length - 1))
                        {
                            return(StatusCodes.BadIndexRangeNoData);
                        }

                        // check for single element.
                        if (range.End < 0 && str.Length != 1)
                        {
                            return(StatusCodes.BadIndexRangeInvalid);
                        }
                    }
                    else
                    {
                        return(StatusCodes.BadTypeMismatch);
                    }
                }
            }
            else
            {
                value.ParsedIndexRange = NumericRange.Empty;
            }

            // passed basic validation.
            return(null);
        }