AF SDK Online Course - GetInputs Method
AF SDK Online Course - GetInputs Method
If we eliminated the validation checks, this could be shorter to understand but more fragile for bad
data. There are a few scenarios where we should throw an exception.
1. The Attribute is on the element root and therefore doesn't have a Parent attribute.
2. The specified name/path is wrong.
3. The measurement attribute is not a numeric data type.
// https://techsupport.osisoft.com/Documentation/PI-AF-
SDK/html/M_OSIsoft_AF_Asset_AFDataReference_GetInputs.htm
public override AFAttributeList GetInputs(object context)
{
var brandNewList = new AFAttributeList();
// First and foremost we need a measurement attribute, which is the centerpoint to compare against
limits.
if (string.IsNullOrWhiteSpace(_measAttrName) || _measAttrName == DefaultMeasPath)
{
// https://techsupport.osisoft.com/Documentation/PI-AF-
SDK/html/P_OSIsoft_AF_Asset_AFDataReference_Attribute.htm
// https://techsupport.osisoft.com/Documentation/PI-AF-
SDK/html/P_OSIsoft_AF_Asset_AFAttribute_Parent.htm
measurement = Attribute.Parent;
if (measurement == null)
{
throw new Exception("Root-level attribute does not have a parent. You must define
'MeasAttr=something' in the ConfigString.");
}
}
else
{
// Let's offer some bit of name substitution.
// However, the GetInputs method lacks any timeContext, which restricts @value substitution
// to current values only. This restriction is fine for static attributes.
// https://techsupport.osisoft.com/Documentation/PI-AF-
SDK/html/T_OSIsoft_AF_AFNameSubstitutionType.htm
var path = SubstituteParameters(_measAttrName, this, context, timeContext: null);
// Note that the final fetch of the measurement attribute is *relative* to the current Attribute.
// https://techsupport.osisoft.com/Documentation/PI-AF-
SDK/html/P_OSIsoft_AF_Asset_AFAttribute_Attributes.htm
measurement = Attribute.Attributes[path];
if (measurement == null)
{
throw new Exception($"MeasAttr '{_measAttrName}' not found. Check your ConfigString.");
}
}
if (!IsNumericType(Type.GetTypeCode(measurement.Type)))
{
throw new Exception($"MeasAttr does not have a numeric Type.");
}
// If the list will have any items, the measurement will always be at Index 0.
brandNewList.Add(measurement);
return brandNewList;
}
Code comments for the ConfigString Setter mentions Separation of Concerns. The ConfigString Setter
receives a string and its concern should be limited to parsing that string into pieces parts. The GetInputs
method has the concern to make sure what was specified in ConfigString refers to a valid AFAttribute,
and if so, also gathers any associated Limit Trait attributes. There is no concern about the data values, or
if there are any missing Limit Traits. Such concerns are more appropriately deferred to the GetValue
method.