0% found this document useful (0 votes)
37 views

AF SDK Online Course - GetInputs Method

This method retrieves input attributes for a data reference. It first validates that a required measurement attribute is present and numeric. It then retrieves any associated limit attributes. Validation checks are included to make the method more robust despite potentially fragile bad data. Exceptions may be thrown if the measurement attribute is invalid. The method concerns are to validate configuration and retrieve associated attributes, leaving data value and missing limit trait concerns to other methods.

Uploaded by

Cleber Pereira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

AF SDK Online Course - GetInputs Method

This method retrieves input attributes for a data reference. It first validates that a required measurement attribute is present and numeric. It then retrieves any associated limit attributes. Validation checks are included to make the method more robust despite potentially fragile bad data. Exceptions may be thrown if the measurement attribute is invalid. The method concerns are to validate configuration and retrieve associated attributes, leaving data value and missing limit trait concerns to other methods.

Uploaded by

Cleber Pereira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

We let the GetInputs automatically fetch the Limit Traits, if any.

// 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();

AFAttribute measurement = null;

// 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);

// Let the CDR automatically fetch the associated limits.


// These could come back in any order, plus some or all may be missing!
// Geez, doesn't that make it fun and challenging!
// https://techsupport.osisoft.com/Documentation/PI-AF-
SDK/html/M_OSIsoft_AF_Asset_AFAttribute_GetAttributesByTrait.htm
brandNewList.AddRange(measurement.GetAttributesByTrait(new AFAttributeTrait[]
{ AFAttributeTrait.LimitLo
,
AFAttributeTrait.LimitHi
,
AFAttributeTrait.LimitLoLo
,
AFAttributeTrait.LimitHiHi }));

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.

You might also like