Lesson 4 hints and tips
- Last UpdatedMay 16, 2023
- 1 minute read
- PI System
- AF SDK 2.10
- PI Server
-
Create an AFEnumerationSet
AFEnumerationSet bTypeEnum = database.EnumerationSets.Add("Building Type");
bTypeEnum.Add("Residential", 0);
bTypeEnum.Add("Business", 1); -
Set AFAttributeTemplate properties
AFAttributeTemplate energyUsageAttrTemp =
meterBasicTemplate.AttributeTemplates.Add("Energy Usage");
energyUsageAttrTemp.Type = typeof(Single);
energyUsageAttrTemp.Categories.Add(tsDataA);
energyUsageAttrTemp.DefaultUOM = uom;
energyUsageAttrTemp.DataReferencePlugIn =
database.PISystem.DataReferencePlugIns["PI Point"];
energyUsageAttrTemp.ConfigString =
@"\\%@\Configuration|PIDataArchiveName%\%Element%.%Attribute%;UOM=kWh"; -
Set AFAttributeTemplate type to be an enumeration set
AFAttributeTemplate attrTemp = elemTemp.AttributeTemplates["Building Type"];
AFEnumerationSet enumSet = database.EnumerationSets["Building Type"];
attrTemp.TypeQualifier = enumSet; -
Check in the changes
if (database.IsDirty)
database.CheckIn(); -
Commit changes using bulk CheckIn
In the exercise solution code, you perform CheckIn operations in bulk to improve performance. This is accomplished by calling CheckIn less frequently. For most situations, avoid calling CheckIn on every object change because each causes a call to the SQL server. When making multiple modifications, a general rule of thumb is to check In 200 objects at a time. If more control is required over the list of objects to be checked in, use the CheckIn() method on a PISystem instance. For more information, see PISystem.Checkin Method.
-
Add Overloads
When adding AFElement objects to an AFElements collection, several Add methods are available. The methods can be roughly divided into two groups:
-
Methods that accept a string denoting the new AFElement name and return a reference to the newly created AFElement.
AFElement meters = database.Elements.Add("Meters"); -
Methods that accept a reference to an existing AFElement object and return void
A common use case for the second method is when adding an existing element as a weak reference to a parent element as in the following:
AFReferenceType weakRefType = database.ReferenceTypes["Weak Reference"];
AFElement meters = database.Elements["Meters"];
AFElement buildingA = database.Elements["Meter Company"].Elements["Building A"];
buildingA.Elements.Add(meters.Elements["Meter001"], weakRefType);
-