-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLoadElementsExample.cs
More file actions
66 lines (55 loc) · 2.42 KB
/
LoadElementsExample.cs
File metadata and controls
66 lines (55 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using OSIsoft.AF;
using OSIsoft.AF.Asset;
namespace ExamplesLibrary
{
/// <summary>
/// Find and load a collection of elements instantiated from the Boiler template.
/// Print each found element name and attribute count to the console.
/// </summary>
/// <prerequisite-examples>
/// none
/// </prerequisite-examples>
public class LoadElementsExample : IExample
{
public void Run()
{
PISystems piSystems = new PISystems();
PISystem piSystem = piSystems["<AFSERVER>"];
AFDatabase afDatabase = piSystem.Databases["NuGreen"];
const int pageSize = 1000;
int startIndex = 0;
int totalCount;
do
{
// Find a collection of elements instantiated from the Boiler tempplate.
// Only the Elements' header information (Name, Description, Template, Type, etc.)
// are loaded from the AF Server by this call.
AFNamedCollection<AFElement> elements = AFElement.FindElements(
database: afDatabase,
searchRoot: null,
query: "Boiler",
field: AFSearchField.Template,
searchFullHierarchy: true,
sortField: AFSortField.Name,
sortOrder: AFSortOrder.Ascending,
startIndex: startIndex,
maxCount: pageSize,
totalCount: out totalCount);
if (elements == null) break;
// This call goes to the AF Server to fully load the found elements in one call,
// so further AF Server calls can be avoided.
AFElement.LoadElements(elements);
// Now we can use the elements without having to make any additional server calls.
// In the example below, accessing the Attributes collection would have
// caused an additional call per element if we had not called LoadElements previously.
Console.WriteLine("Found {0} Elements.", elements.Count);
foreach (AFElement item in elements)
{
Console.WriteLine(" Element {0} has {1} Attributes", item.Name, item.Attributes.Count);
}
startIndex += pageSize;
} while (startIndex < totalCount);
}
}
}