private bool UpdateSessionDiagnostics(
SessionDiagnosticsData diagnostics,
SessionDiagnosticsDataType[] sessionArray,
int index)
{
// get the latest snapshot.
object value = null;
ServiceResult result = diagnostics.UpdateCallback(
SystemContext,
diagnostics.Value.Variable,
ref value);
SessionDiagnosticsDataType newValue = value as SessionDiagnosticsDataType;
sessionArray[index] = newValue;
// check for changes.
if (Utils.IsEqual(newValue, diagnostics.Value.Value))
{
return false;
}
diagnostics.Value.Error = null;
// check for bad value.
if (ServiceResult.IsNotBad(result) && newValue == null)
{
result = StatusCodes.BadOutOfService;
}
// check for bad result.
if (ServiceResult.IsBad(result))
{
diagnostics.Value.Error = result;
newValue = null;
}
// update the value.
diagnostics.Value.Value = newValue;
diagnostics.Value.Timestamp = DateTime.UtcNow;
// notify any monitored items.
diagnostics.Value.ChangesComplete(SystemContext);
return true;
}