-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCreateEventFrameExample.cs
More file actions
65 lines (53 loc) · 2.56 KB
/
CreateEventFrameExample.cs
File metadata and controls
65 lines (53 loc) · 2.56 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
using OSIsoft.AF;
using OSIsoft.AF.Asset;
using OSIsoft.AF.EventFrame;
using OSIsoft.AF.Time;
namespace ExamplesLibrary
{
/// <summary>
/// This example creates 5 event frames of 1 day periods spanning the last 5 days.
/// The primary referenced element for the event frames are set to the Region_0\BoilerA element.
/// </summary>
/// <prerequisite-examples>
/// BuildSimpleDatabaseExample
/// </prerequisite-examples>
public class CreateEventFrameExample : IExample
{
public void Run()
{
PISystems piSystems = new PISystems();
PISystem piSystem = piSystems["<AFSERVER>"];
AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"];
CreateEventFrameTemplate(afDatabase);
CreateEventFrames(afDatabase);
}
private void CreateEventFrameTemplate(AFDatabase afDatabase)
{
AFElementTemplate efTemplate = afDatabase.ElementTemplates.Add("BasicEventFrameTemplate");
// Specify that this is an Event Frame Template.
efTemplate.InstanceType = typeof(AFEventFrame);
AFAttributeTemplate tempAttr = efTemplate.AttributeTemplates.Add("Maximum temperature");
tempAttr.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem);
AFAttributeTemplate pressAttr = efTemplate.AttributeTemplates.Add("Maximum pressure");
pressAttr.DataReferencePlugIn = AFDataReference.GetPIPointDataReference(afDatabase.PISystem);
tempAttr.ConfigString = @".\Elements[.]|Temperature;TimeMethod=NotSupported;TimeRangeMethod=Maximum";
pressAttr.ConfigString = @".\Elements[.]|Pressure;TimeMethod=NotSupported;TimeRangeMethod=Maximum";
// Do a bulk check in of all changes made so far.
afDatabase.CheckIn();
}
private void CreateEventFrames(AFDatabase afDatabase)
{
AFElementTemplate efTemplate = afDatabase.ElementTemplates["BasicEventFrameTemplate"];
for (int i = 0; i < 5; i++)
{
AFEventFrame ef = new AFEventFrame(afDatabase, "EF_" + i, efTemplate);
ef.SetStartTime(new AFTime(string.Format("t-{0}d", i + 1)));
ef.SetEndTime(new AFTime(string.Format("t-{0}d", i)));
AFElement element = afDatabase.Elements["Region_0"].Elements["BoilerA"];
ef.PrimaryReferencedElement = element;
}
// Do a bulk check in of all changes made so far.
afDatabase.CheckIn();
}
}
}