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;
}
#endregion