public void ReadValues(
IList<NodeId> variableIds,
IList<Type> expectedTypes,
out List<object> values,
out List<ServiceResult> errors)
{
values = new List<object>();
errors = new List<ServiceResult>();
// build list of values to read.
ReadValueIdCollection valuesToRead = new ReadValueIdCollection();
for (int ii = 0; ii < variableIds.Count; ii++)
{
ReadValueId valueToRead = new ReadValueId();
valueToRead.NodeId = variableIds[ii];
valueToRead.AttributeId = Attributes.Value;
valueToRead.IndexRange = null;
valueToRead.DataEncoding = null;
valuesToRead.Add(valueToRead);
}
// read the values.
DataValueCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
ResponseHeader responseHeader = Read(
null,
Int32.MaxValue,
TimestampsToReturn.Both,
valuesToRead,
out results,
out diagnosticInfos);
// verify that the server returned the correct number of results.
ClientBase.ValidateResponse(results, valuesToRead);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, valuesToRead);
for (int ii = 0; ii < variableIds.Count; ii++)
{
values.Add(null);
errors.Add(ServiceResult.Good);
// process any diagnostics associated with bad or uncertain data.
if (StatusCode.IsNotGood(results[ii].StatusCode))
{
errors[ii] = new ServiceResult(results[ii].StatusCode, ii, diagnosticInfos, responseHeader.StringTable);
continue;
}
object value = results[ii].Value;
// extract the body from extension objects.
ExtensionObject extension = value as ExtensionObject;
if (extension != null && extension.Body is IEncodeable)
{
value = extension.Body;
}
// check expected type.
if (expectedTypes[ii] != null && !expectedTypes[ii].IsInstanceOfType(value))
{
errors[ii] = ServiceResult.Create(
StatusCodes.BadTypeMismatch,
"Value {0} does not have expected type: {1}.",
value,
expectedTypes[ii].Name);
continue;
}
// suitable value found.
values[ii] = value;
}
}