Loading Top Level Objects
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
In AF, SDK objects which can be checked-in, are considered top-level objects. These items can be loaded individually from the server or in bulk. Typically, when these items are first returned to the client application from a search or from accessing a collection, only the header information is returned. When your program accesses information that is not in the header, then the AF SDK will retrieve the full object definition from the server. If an application does this with many objects, many RPCs may result. This example uses the AFElementSearchFindElements method to illustrate a mechanism for bulk loading a list of objects into the client. This same mechanism can be used to bulk load top-level objects using one of the searches derived from the OSIsoft.AF.SearchAFSearch class
1// Get the Database 2PISystems myPISystems = new PISystems(); 3PISystem myPISystem = myPISystems.DefaultPISystem; 4if (myPISystem == null) 5 throw new InvalidOperationException("Default PISystem was not found."); 6AFDatabase myDB = myPISystem.Databases[dbName]; 7if (myDB == null) 8 throw new InvalidOperationException("Database was not found."); 9 10// Create a search to find all the elements in a specific area 11// of a plant (e.g. 'WestPlant\Area32') that have a 'Valve' category. 12int count; 13using (var search = new AFElementSearch(myDB, "FindValves", @"Root:'WestPlant\Area32' Category:'Valve'")) 14{ 15 search.CacheTimeout = TimeSpan.FromMinutes(10); 16 17 // When the elements are returned from a find operation, they are only 18 // partially loaded into memory, typically enough to display their 19 // inherent properties, such as Name, Description, Template, Type, etc. 20 // When a piece of information is accessed in the element that requires more 21 // information, an RPC to the server is made to fully load the element. 22 // By having the search do a full load, all information is loaded in bulk and 23 // we can reduce the number of RPCs made to retrieve this information. 24 count = search.GetTotalCount(); 25 Console.WriteLine("Found {0} Elements.", count); 26 foreach (AFElement item in search.FindObjects(fullLoad: true)) 27 { 28 // Now we can use the elements without having to make any additional RPCs 29 // In the example below, accessing the Attributes collection would have 30 // caused an additional RPC per element found. 31 // Now we can use the elements without having to make any additional RPCs 32 // In the example below, accessing the Attributes collection would have 33 // caused an additional RPC per element found. 34 Console.WriteLine(" Element {0} has {1} Attributes", item.Name, item.Attributes.Count); 35 } 36}
1' Get the Database 2Dim myPISystems As New PISystems() 3Dim myPISystem As PISystem = myPISystems.DefaultPISystem 4If myPISystem Is Nothing Then 5 Throw New InvalidOperationException("Default PISystem was not found.") 6End If 7Dim myDB As AFDatabase = myPISystem.Databases(dbName) 8If myDB Is Nothing Then 9 Throw New InvalidOperationException("Database was not found.") 10End If 11 12' Create a search to find all the elements in a specific area 13' of a plant (e.g. 'WestPlant\Area32') that have a 'Valve' category. 14Dim count As Integer 15Using search As New AFElementSearch(myDB, "FindValves", "Root:'WestPlant\Area32' Category:'Valve'") 16 17 search.CacheTimeout = TimeSpan.FromMinutes(10) 18 19 ' When the elements are returned from a find operation, they are only 20 ' partially loaded into memory, typically enough to display their 21 ' inherent properties, such as Name, Description, Template, Type, etc. 22 ' When a piece of information is accessed in the element that requires more 23 ' information, an RPC to the server is made to fully load the element. 24 ' By having the search do a full load, all information is loaded in bulk and 25 ' we can reduce the number of RPCs made to retrieve this information. 26 count = search.GetTotalCount() 27 Console.WriteLine("Found {0} Elements.", count) 28 For Each item As AFElement In search.FindObjects(fullLoad:=True) 29 30 ' Now we can use the elements without having to make any additional RPCs 31 ' In the example below, accessing the Attributes collection would have 32 ' caused an additional RPC per element found. 33 ' Now we can use the elements without having to make any additional RPCs 34 ' In the example below, accessing the Attributes collection would have 35 ' caused an additional RPC per element found. 36 Console.WriteLine(" Element {0} has {1} Attributes", item.Name, item.Attributes.Count) 37 Next 38End Using
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.