public void UpdateValueAdHocTest()
        {
            var          currentTime = "*-1d";
            PITimedValue attr1tv     = new PITimedValue()
            {
                Timestamp = currentTime,
                Value     = 20
            };
            PITimedValue attr2tv = new PITimedValue()
            {
                Timestamp = currentTime,
                Value     = 21
            };
            PITimedValue attr3tv = new PITimedValue()
            {
                Timestamp = currentTime,
                Value     = 22
            };



            List <PIStreamValue> values = new List <PIStreamValue>();

            values.Add(new PIStreamValue(attr1webId, null, null, attr1tv));
            values.Add(new PIStreamValue(attr2webId, null, null, attr2tv));
            values.Add(new PIStreamValue(attr3webId, null, null, attr3tv));

            string updateOption = "Replace";
            string bufferOption = "BufferIfPossible";

            instance.UpdateValueAdHoc(values: values, updateOption: updateOption, bufferOption: bufferOption);
        }
        public void UpdateValueTest()
        {
            // TODO uncomment below to test the method and replace null with proper value
            var          currentTime = "t";
            PITimedValue value       = new PITimedValue()
            {
                Timestamp = currentTime,
                Value     = 30
            };
            string updateOption = "Replace";
            string bufferOption = "BufferIfPossible";
            var    res          = instance.UpdateValueWithHttpInfo(webId: webId, value: value, updateOption: updateOption, bufferOption: bufferOption);
            var    afValue      = point.RecordedValue(new AFTime(currentTime));

            Assert.IsTrue(afValue.ValueAsSingle() == Convert.ToSingle(value.Value));
        }
        public void SetValueTest()
        {
            DateTime     time  = DateTime.Today;
            PITimedValue value = new PITimedValue("t", null, true, false, false, 153);

            value.Substituted = null;
            instance.SetValue(webId, value);

            string     path = Constants.AF_ATTRIBUTE_PATH;
            AFDatabase db   = StandardPISystem.Databases[Constants.AF_DATABASE_NAME];

            db.Refresh();
            AFAttribute myAttribute = AFObject.FindObject(path) as AFAttribute;
            float       v1          = myAttribute.GetValue().ValueAsSingle();
            float       v2          = Convert.ToSingle(value.Value);

            Assert.IsTrue(v1 == v2);
        }
        public void UpdateValuesTest()
        {
            // TODO uncomment below to test the method and replace null with proper value

            var          currentTime1 = "*-1d";
            var          currentTime2 = "*-2d";
            PITimedValue value1       = new PITimedValue()
            {
                Timestamp = currentTime1,
                Value     = 40
            };
            PITimedValue value2 = new PITimedValue()
            {
                Timestamp = currentTime2,
                Value     = 50
            };
            string updateOption = "Replace";
            string bufferOption = "BufferIfPossible";



            List <PITimedValue> values = new List <PITimedValue>();

            values.Add(value1);
            values.Add(value2);

            instance.UpdateValues(webId: webId, values: values, updateOption: updateOption, bufferOption: bufferOption);

            //AFCache.Clear();

            //var afValue1 = point.RecordedValue(new AFTime(currentTime1));
            //int v1a = afValue1.ValueAsInt32();
            //int v1b = Convert.ToInt32(value1.Value);
            //Assert.IsTrue(v1a == v1b);


            //var afValue2 = point.RecordedValue(new AFTime(currentTime2));
            //int v2a = afValue2.ValueAsInt32();
            //int v2b = Convert.ToInt32(value2.Value);
            //Assert.IsTrue(v2a == v2b);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //Do not verify Ssl certificate
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            //Create an instance of the PI Web API top level object.
            PIWebApiClient client = new PIWebApiClient("https://marc-rras.osisoft.int/piwebapi", false, "marc.adm", "kk");

            //PIWebApiClient client = new PIWebApiClient("https://devdata.osisoft.com/piwebapi", false, "webapiuser", "!try3.14webapi!");
            var homeLanding = client.Home.Get();
            ////Get the PI Data Archive object
            PIDataServer  dataServer = client.DataServer.GetByPath("\\\\MARC-PI2016");
            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);
            };
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            PIWebApiClient client = new PIWebApiClient();

            bool connectionTest = client.Connect("https://marc-web-sql.marc.net/piwebapi", true);

            if (connectionTest == false)
            {
                return;
            }
            PIDataServer dataServer   = client.DataServer.GetByPath("\\\\MARC-PI2016");
            PIPoint      createdPoint = client.Point.GetByPath("\\\\MARC-PI2016\\SINUSOIDR1259", null);
            string       webId        = createdPoint.WebId;

            createdPoint.DigitalSetName   = null;
            createdPoint.EngineeringUnits = null;
            createdPoint.Descriptor       = "14 Hour Sine Waveeeeee";
            createdPoint.Future           = false;
            createdPoint.Id         = 0;
            createdPoint.Links      = null;
            createdPoint.Name       = null;
            createdPoint.Path       = null;
            createdPoint.PointClass = null;
            createdPoint.PointType  = null;
            createdPoint.WebId      = null;
            createdPoint.Span       = 0;
            createdPoint.Zero       = 0;
            ApiResponseObject response = client.Point.UpdateWithHttpInfo(webId, createdPoint);

            Console.WriteLine(response.StatusCode);

            PIPoint             point1 = client.Point.GetByPath("\\\\marc-pi2016\\sinusoid");
            PIPoint             point2 = client.Point.GetByPath("\\\\marc-pi2016\\sinusoidu");
            PIPoint             point3 = client.Point.GetByPath("\\\\marc-pi2016\\cdt158");
            string              webIds = point1.WebId + "," + point2.WebId + "," + point3.WebId;
            PIItemsStreamValues piItemsStreamValues = client.StreamSet.GetRecordedAdHoc(webIds, true, 10000);

            for (int i = 0; i < piItemsStreamValues.GetItemsLength(); i++)
            {
                Console.WriteLine(piItemsStreamValues.GetItem(i).Path);
                for (int j = 0; j < piItemsStreamValues.GetItem(i).GetItemsLength(); j++)
                {
                    Console.WriteLine(piItemsStreamValues.GetItem(i).GetItem(j).Value);
                }
            }

            PIItemsStreamValues streamValuesItems = new PIItemsStreamValues();

            streamValuesItems.CreateItemsArray(3);

            PITimedValue value1 = new PITimedValue();

            value1.Value     = 2;
            value1.Timestamp = "*-1d";
            PITimedValue value2 = new PITimedValue();

            value2.Value     = 3;
            value2.Timestamp = "*-2d";
            PITimedValue value3 = new PITimedValue();

            value3.Value     = 4;
            value3.Timestamp = "*-1d";
            PITimedValue value4 = new PITimedValue();

            value4.Value     = 5;
            value4.Timestamp = "*-2d";
            PITimedValue value5 = new PITimedValue();

            value5.Value     = 6;
            value5.Timestamp = "*-1d";
            PITimedValue value6 = new PITimedValue();

            value6.Value     = 7;
            value6.Timestamp = "*-2d";



            PIStreamValues streamValue1 = new PIStreamValues();

            streamValue1.WebId = point1.WebId;
            streamValue1.CreateItemsArray(2);
            streamValue1.SetItem(0, value1);
            streamValue1.SetItem(1, value2);
            streamValuesItems.SetItem(0, streamValue1);

            PIStreamValues streamValue2 = new PIStreamValues();

            streamValue2.WebId = point2.WebId;
            streamValue2.CreateItemsArray(2);
            streamValue2.SetItem(0, value3);
            streamValue2.SetItem(1, value4);
            streamValuesItems.SetItem(1, streamValue2);

            PIStreamValues streamValue3 = new PIStreamValues();

            streamValue3.WebId = point2.WebId;
            streamValue3.CreateItemsArray(2);
            streamValue3.SetItem(0, value5);
            streamValue3.SetItem(1, value6);
            streamValuesItems.SetItem(2, streamValue3);

            ApiResponsePIItemsItemsSubstatus responsee = client.StreamSet.UpdateValuesAdHocWithHttpInfo(streamValuesItems);

            PIElement myElement = client.Element.GetByPath("\\\\MARC-PI2016\\CrossPlatformLab\\marc.adm");

            Console.WriteLine(myElement.Description);
            PIItemsAttribute attributes = client.Element.GetAttributes(myElement.WebId, 1000, false, false, false, 0);

            Console.WriteLine(attributes);
            PIAttribute  attribute = client.Attribute.GetByPath(string.Format("{0}|{1}", "\\\\MARC-PI2016\\CrossPlatformLab\\marc.adm", attributes.Items[0].Name));
            PITimedValue value     = client.Stream.GetEnd(attribute.WebId);

            Console.WriteLine(value);



            string        expression = "'sinusoid'*2 + 'cdt158'";
            PITimedValues values1    = client.Calculation.GetAtTimes(webId: dataServer.WebId, expression: expression, times: "*-1d, *-2d");

            string        expression2 = "'cdt158'+tagval('sinusoid','*-1d')";
            PITimedValues values2     = client.Calculation.GetAtTimes(webId: dataServer.WebId, expression: expression2, times: "*-1d, *-2d");

            PIItemsSummaryValue itemsSummaryValue = client.Calculation.GetSummary(expression: expression2, startTime: "*-1d", endTime: "*", webId: dataServer.WebId,
                                                                                  summaryTypes: "Average, Maximum");



            //Get the attribute's end of the stream value
            PITimedValue newValue = client.Stream.GetEnd(attribute.WebId);


            //Stream Updates
            PIItemsStreamUpdatesRegister piItemsStreamUpdatesRegister = client.StreamSet.RegisterStreamSetUpdates(webIds);
            List <string> markersList = piItemsStreamUpdatesRegister.Items.Select(i => i.LatestMarker).ToList();
            string        markers     = String.Join(",", markersList.ToArray());
            int           k           = 3;

            while (k > 0)
            {
                PIItemsStreamUpdatesRetrieve piItemsStreamUpdatesRetrieve = client.StreamSet.RetrieveStreamSetUpdates(markers);
                markersList = piItemsStreamUpdatesRetrieve.Items.Select(i => i.LatestMarker).ToList();
                markers     = String.Join(",", markersList.ToArray());
                foreach (PIStreamUpdatesRetrieve item in piItemsStreamUpdatesRetrieve.Items)
                {
                    foreach (PIDataPipeEvent piEvent in item.Events)
                    {
                        Console.WriteLine("Action={0}, Value={1}, SourcePath={2}", piEvent.Action, piEvent.Value, item.SourcePath);
                    }
                }
                System.Threading.Thread.Sleep(30000);
                k--;
            }
        }
        /// <summary>Set the value of a configuration item attribute. For attributes with a data reference or non-configuration item attributes, consult the documentation for streams.</summary>
        public Object SetValue(string webId, PITimedValue value)
        {
            ApiResponseObject localVarResponse = SetValueWithHttpInfo(webId, value);

            return(localVarResponse.Data);
        }
        /// <summary>Set the value of a configuration item attribute. For attributes with a data reference or non-configuration item attributes, consult the documentation for streams.</summary>
        public ApiResponseObject SetValueWithHttpInfo(string webId, PITimedValue value)
        {
            if (string.IsNullOrEmpty(webId) == true)
            {
                webId = null;
            }
            if (webId == null)
            {
                throw new ApiException(400, "Missing required parameter 'webId'");
            }
            if (value == null)
            {
                throw new ApiException(400, "Missing required parameter 'value'");
            }

            var    localVarPath         = "/attributes/{webId}/value";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new CustomDictionaryForQueryString();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            String[] localVarHttpContentTypes = new String[] { };
            String   localVarHttpContentType  = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "text/xml" };
            String   localVarHttpHeaderAccept  = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            localVarPathParams.Add("format", "json");

            if (webId != null)
            {
                localVarPathParams.Add("webId", Configuration.ApiClient.ParameterToString(webId));
            }
            if (value != null && value.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(value);
            }
            else
            {
                localVarPostBody = value;
            }

            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.PUT, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("SetValue", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponseObject(localVarStatusCode,
                                         localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                         (Object)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Object))));
        }
        static void Main(string[] args)
        {
            //Create an instance of the PI Web API top level object.

            PIWebApiClient client = new PIWebApiClient("https://marc-web-sql.marc.net/piwebapi", true);
            // TODO: The PI Web API client must provide a user name and password when using “basic” authentication
            // Store passwords outside of the code in a hardware TPM, trusted service (credential manager) or in a protected file.
            // Code to return the user name and password is not shown here.



            var homeLanding = client.Home.Get();
            ////Get the PI Data Archive object
            PIDataServer  dataServer = client.DataServer.GetByPath("\\\\MARC-PI2016");
            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.Span       = null;
            createdPoint.Zero       = 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);
            };


            //Stream Updates
            PIItemsStreamUpdatesRegister piItemsStreamUpdatesRegister = client.StreamSet.RegisterStreamSetUpdates(webIds);
            List <string> markers = piItemsStreamUpdatesRegister.Items.Select(i => i.LatestMarker).ToList();
            int           k       = 3;

            while (k > 0)
            {
                PIItemsStreamUpdatesRetrieve piItemsStreamUpdatesRetrieve = client.StreamSet.RetrieveStreamSetUpdates(markers);
                markers = piItemsStreamUpdatesRetrieve.Items.Select(i => i.LatestMarker).ToList();
                foreach (PIStreamUpdatesRetrieve item in piItemsStreamUpdatesRetrieve.Items)
                {
                    foreach (PIDataPipeEvent piEvent in item.Events)
                    {
                        Console.WriteLine("Action={0}, Value={1}, SourcePath={2}", piEvent.Action, piEvent.Value, item.SourcePath);
                    }
                }
                System.Threading.Thread.Sleep(30000);
                k--;
            }

            ChannelsExamples(client, webIds);
            Console.WriteLine("Finished");
            Console.ReadKey();
        }
Beispiel #10
0
 public ApiResponsePITimedValue(int statusCode, IDictionary <string, string> headers, PITimedValue data)
     : base(statusCode, headers)
 {
     this.Data = data;
 }
        static void Main(string[] args)
        {
            //Create an instance of the PI Web API top level object.
            PIWebApiClient client = new PIWebApiClient("https://marc-web-sql.marc.net/piwebapi", true);

            //Get the PI Data Archive object
            PIDataServer dataServer = client.DataServer.GetByPath("\\\\MARC-PI2016");

            //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");
            PIPoint       point3 = client.Point.GetByPath("\\\\marc-pi2016\\cdt158");
            List <string> webIds = new List <string>()
            {
                point1.WebId, point1.WebId, point1.WebId
            };

            //Get recorded values in bulk
            PIItemsStreamValues piItemsStreamValues = client.StreamSet.GetRecordedAdHoc(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));

            //Get the attribute's end of the stream value
            PITimedValue value = client.Stream.GetEnd(attribute.WebId);
        }
        static void Main(string[] args)
        {
            PIWebApiClient client         = new PIWebApiClient();
            bool           connectionTest = client.Connect("https://marc-web-sql.marc.net/piwebapi", true);

            if (connectionTest == false)
            {
                return;
            }
            PIDataServer dataServer   = client.DataServer.GetByPath("\\\\MARC-PI2016");
            PIPoint      createdPoint = client.Point.GetByPath("\\\\MARC-PI2016\\SINUSOIDR1259", null);
            string       webId        = createdPoint.WebId;

            createdPoint.DigitalSetName   = null;
            createdPoint.EngineeringUnits = null;
            createdPoint.Descriptor       = "14 Hour Sine Waveeeeee";
            createdPoint.Future           = false;
            createdPoint.Id         = 0;
            createdPoint.Links      = null;
            createdPoint.Name       = null;
            createdPoint.Path       = null;
            createdPoint.PointClass = null;
            createdPoint.PointType  = null;
            createdPoint.WebId      = null;
            ApiResponseObject response = client.Point.UpdateWithHttpInfo(webId, createdPoint);

            Console.WriteLine(response.StatusCode);

            PIPoint             point1 = client.Point.GetByPath("\\\\marc-pi2016\\sinusoid");
            PIPoint             point2 = client.Point.GetByPath("\\\\marc-pi2016\\sinusoidu");
            PIPoint             point3 = client.Point.GetByPath("\\\\marc-pi2016\\cdt158");
            string              webIds = point1.WebId + "," + point1.WebId + "," + point1.WebId;
            PIItemsStreamValues piItemsStreamValues = client.StreamSet.GetRecordedAdHoc(webIds, true, 10000);

            for (int i = 0; i < piItemsStreamValues.GetItemsLength(); i++)
            {
                Console.WriteLine(piItemsStreamValues.GetItem(i).Path);
                for (int j = 0; j < piItemsStreamValues.GetItem(i).GetItemsLength(); j++)
                {
                    Console.WriteLine(piItemsStreamValues.GetItem(i).GetItem(j).Value);
                }
            }

            PIItemsStreamValues streamValuesItems = new PIItemsStreamValues();

            streamValuesItems.CreateItemsArray(3);

            PITimedValue value1 = new PITimedValue();

            value1.Value     = 2;
            value1.Timestamp = "*-1d";
            PITimedValue value2 = new PITimedValue();

            value2.Value     = 3;
            value2.Timestamp = "*-2d";
            PITimedValue value3 = new PITimedValue();

            value3.Value     = 4;
            value3.Timestamp = "*-1d";
            PITimedValue value4 = new PITimedValue();

            value4.Value     = 5;
            value4.Timestamp = "*-2d";
            PITimedValue value5 = new PITimedValue();

            value5.Value     = 6;
            value5.Timestamp = "*-1d";
            PITimedValue value6 = new PITimedValue();

            value6.Value     = 7;
            value6.Timestamp = "*-2d";



            PIStreamValues streamValue1 = new PIStreamValues();

            streamValue1.WebId = point1.WebId;
            streamValue1.CreateItemsArray(2);
            streamValue1.SetItem(0, value1);
            streamValue1.SetItem(1, value2);
            streamValuesItems.SetItem(0, streamValue1);

            PIStreamValues streamValue2 = new PIStreamValues();

            streamValue2.WebId = point2.WebId;
            streamValue2.CreateItemsArray(2);
            streamValue2.SetItem(0, value3);
            streamValue2.SetItem(1, value4);
            streamValuesItems.SetItem(1, streamValue2);

            PIStreamValues streamValue3 = new PIStreamValues();

            streamValue3.WebId = point2.WebId;
            streamValue3.CreateItemsArray(2);
            streamValue3.SetItem(0, value5);
            streamValue3.SetItem(1, value6);
            streamValuesItems.SetItem(2, streamValue3);

            ApiResponsePIItemsItemsSubstatus responsee = client.StreamSet.UpdateValuesAdHocWithHttpInfo(streamValuesItems);

            PIElement myElement = client.Element.GetByPath("\\\\MARC-PI2016\\CrossPlatformLab\\marc.adm");

            Console.WriteLine(myElement.Description);
            PIItemsAttribute attributes = client.Element.GetAttributes(myElement.WebId, 1000, false, false, false, 0);

            Console.WriteLine(attributes);
            PIAttribute  attribute = client.Attribute.GetByPath(string.Format("{0}|{1}", "\\\\MARC-PI2016\\CrossPlatformLab\\marc.adm", attributes.Items[0].Name));
            PITimedValue value     = client.Stream.GetEnd(attribute.WebId);

            Console.WriteLine(value);
        }
        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);
            //};
        }