protected bool VerifyGoodAttribute(
Node node,
uint attributeId,
DataValue value)
{
// check if attribute is not valid for node.
if (!Attributes.IsValid(node.NodeClass, attributeId))
{
Log(
"Unexpected Attribute returned during read for Node '{0}'. NodeId = {1}, Attribute = {2}, Value = {3}",
node,
node.NodeId,
Attributes.GetBrowseName(attributeId),
value.WrappedValue);
return false;
}
// replace null values with the default.
object attributeValue = value.Value;
// check data type.
TypeInfo typeInfo = TypeInfo.IsInstanceOfDataType(
attributeValue,
Attributes.GetDataTypeId(attributeId),
Attributes.GetValueRank(attributeId),
Session.NamespaceUris,
Session.TypeTree);
if (typeInfo == null)
{
Log(
"Invalid data type for attribute value for Node '{0}'. NodeId = {1}, Attribute = {2}, ExpectedType = {3}, ActualType = {4}",
node,
node.NodeId,
Attributes.GetBrowseName(attributeId),
Attributes.GetBuiltInType(attributeId),
value.WrappedValue.TypeInfo);
return false;
}
// save the attribute value.
try
{
if (!SetAttributeValue(node, attributeId, attributeValue))
{
return false;
}
}
catch (Exception e)
{
Log(
e,
"Unexpected error saving attribute value for Node '{0}'. NodeId = {1}, Attribute = {2}, Value = {3}",
node,
node.NodeId,
Attributes.GetBrowseName(attributeId),
new Variant(attributeValue));
return false;
}
return true;
}