forked from nickgermyn/PI-Web-API-Client-DotNet-Standard
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
188 lines (155 loc) · 8.71 KB
/
Program.cs
File metadata and controls
188 lines (155 loc) · 8.71 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// ************************************************************************
//
// * Copyright 2018 OSIsoft, LLC
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * <http://www.apache.org/licenses/LICENSE-2.0>
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// ************************************************************************
using OSIsoft.PIDevClub.PIWebApiClient;
using OSIsoft.PIDevClub.PIWebApiClient.Client;
using OSIsoft.PIDevClub.PIWebApiClient.Model;
using OSIsoft.PIDevClub.PIWebApiClient.WebID;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace LibraryTest
{
class Program
{
static void Main(string[] args)
{
//Create an instance of the PI Web API top level object.
string username = Environment.GetEnvironmentVariable("pi_u");
string password = Environment.GetEnvironmentVariable("pi_p");
string piWebApiUrl = args[0];
string piServerName = args[1];
string tagName = args[2];
//Do not verify Ssl certificate
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
PIWebApiClient client = new PIWebApiClient(piWebApiUrl, useKerberos: true, username, password);
string pointPath = $@"{piServerName}\{tagName}";
PIPoint point1a = client.Point.GetByPath(pointPath);
PITimedValue value = client.Stream.GetEnd(point1a.WebId);
Console.WriteLine($"{tagName}: {value.Value}");
string startTime = "8-Jan-2020";
string endTime = "10-Jan-2020";
PITimedValues values = client.Stream.GetInterpolated(point1a.WebId, startTime: startTime, endTime: endTime);
foreach( PITimedValue item in values.Items )
{
Console.WriteLine($@"{item.Timestamp} {item.Value}");
}
//PIDataServer dataServer = client.DataServer.GetByPath("\\\\PIPreProd");
//string expression = "'sinusoid'*2 + 'cdt158'";
//PITimedValues values = client.Calculation.GetAtTimes(webId: dataServer.WebId, expression: expression, time: new List<string>() { "*-1d" });
//string expression2 = "'cdt158'+tagval('sinusoid','*-1d')";
//PITimedValues values2 = client.Calculation.GetAtTimes(webId: dataServer.WebId, expression: expression2, time: new List<string>() { "*-1d" });
//PIItemsSummaryValue itemsSummaryValue = client.Calculation.GetSummary(expression: expression2, startTime: "*-1d", endTime: "*", webId: dataServer.WebId,
// summaryType: new List<string>() { "Average", "Maximum" });
////Get PI Point
//PIPoint createdPoint = client.Point.GetByPath("\\\\MARC-PI2016\\SINUSOIDR1259", null);
////Change the description of the PI Point
//string webId = createdPoint.WebId;
//createdPoint.DigitalSetName = null;
//createdPoint.EngineeringUnits = null;
//createdPoint.Descriptor = "New description";
//createdPoint.Future = null;
//createdPoint.Id = null;
//createdPoint.Links = null;
//createdPoint.Name = null;
//createdPoint.Path = null;
//createdPoint.PointClass = null;
//createdPoint.PointType = null;
//createdPoint.WebId = null;
////Update PI Point
//ApiResponse<Object> response = client.Point.UpdateWithHttpInfo(webId, createdPoint);
////Check if the request was successful
//Console.WriteLine(response.StatusCode);
////Get PI Points WebIds
//PIPoint point1 = client.Point.GetByPath("\\\\marc-pi2016\\sinusoid");
//PIPoint point2 = client.Point.GetByPath("\\\\marc-pi2016\\sinusoidu", selectedFields: "webId;name");
//PIPoint point3 = client.Point.GetByPath("\\\\marc-pi2016\\cdt158");
//List<string> webIds = new List<string>() { point1.WebId, point2.WebId, point3.WebId };
////Get recorded values in bulk
//PIItemsStreamValues piItemsStreamValues = client.StreamSet.GetRecordedAdHoc(webId: webIds, startTime: "*-3d", endTime: "*");
////Send values in bulk
//var streamValuesItems = new PIItemsStreamValues();
//var streamValue1 = new PIStreamValues();
//var streamValue2 = new PIStreamValues();
//var streamValue3 = new PIStreamValues();
//var value1 = new PITimedValue();
//var value2 = new PITimedValue();
//var value3 = new PITimedValue();
//var value4 = new PITimedValue();
//var value5 = new PITimedValue();
//var value6 = new PITimedValue();
//value1.Value = 2;
//value1.Timestamp = "*-1d";
//value2.Value = 3;
//value2.Timestamp = "*-2d";
//value3.Value = 4;
//value3.Timestamp = "*-1d";
//value4.Value = 5;
//value4.Timestamp = "*-2d";
//value5.Value = 6;
//value5.Timestamp = "*-1d";
//value6.Value = 7;
//value6.Timestamp = "*-2d";
//streamValue1.WebId = point1.WebId;
//streamValue1.Items = new List<PITimedValue>();
//streamValue1.Items.Add(value1);
//streamValue1.Items.Add(value2);
//streamValue2.WebId = point2.WebId;
//streamValue2.Items = new List<PITimedValue>();
//streamValue2.Items.Add(value3);
//streamValue2.Items.Add(value4);
//streamValue3.WebId = point2.WebId;
//streamValue3.Items = new List<PITimedValue>();
//streamValue3.Items.Add(value5);
//streamValue3.Items.Add(value6);
//ApiResponse<PIItemsItemsSubstatus> response2 = client.StreamSet.UpdateValuesAdHocWithHttpInfo(new List<PIStreamValues>() { streamValue1, streamValue2, streamValue3 });
////Get an element given a path
//PIElement myElement = client.Element.GetByPath("\\\\MARC-PI2016\\CrossPlatformLab\\marc.adm");
////Get element's attributes
//PIItemsAttribute attributes = client.Element.GetAttributes(myElement.WebId, null, 1000, null, false);
////Get an attribute given a path
//PIAttribute attribute = client.Attribute.GetByPath(string.Format("{0}|{1}", "\\\\MARC-PI2016\\CrossPlatformLab\\marc.adm", attributes.Items[0].Name));
//WebIdInfo webIdInfo = client.WebIdHelper.GetWebIdInfo(myElement.WebId);
//WebIdInfo webIdInfo2 = client.WebIdHelper.GetWebIdInfo(attribute.WebId);
//WebIdInfo webIdInfo4 = client.WebIdHelper.GetWebIdInfo(point1.WebId);
//WebIdInfo webIdInfo3 = client.WebIdHelper.GetWebIdInfo(dataServer.WebId);
////Get the attribute's end of the stream value
//PITimedValue value = client.Stream.GetEnd(attribute.WebId);
////Cancelling the HTTP request with the CancellationToken
//Stopwatch watch = Stopwatch.StartNew();
//CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
//PIItemsStreamValues bulkValues = null;
//try
//{
// Task t = Task.Run(async () =>
// {
// bulkValues = await client.StreamSet.GetRecordedAdHocAsync(webId: webIds, startTime: "*-1800d", endTime: "*", maxCount: 50000, cancellationToken: cancellationTokenSource.Token);
// });
// //Cancel the request after 4s
// System.Threading.Thread.Sleep(4000);
// cancellationTokenSource.Cancel();
// t.Wait();
// Console.WriteLine("Completed task: Time elapsed: {0}s", 0.001 * watch.ElapsedMilliseconds);
//}
//catch (Exception)
//{
// Console.WriteLine("Cancelled task: Time elapsed: {0}s", 0.001 * watch.ElapsedMilliseconds);
//};
}
}
}