public void GeneratePathsTest() { PIAnalysis piAnalysis = client.Analysis.GetByPath(Constants.AF_ANALYSIS_PATH); PIAnalysis piAnalysis2 = client.Analysis.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ANALYSIS_PATH, typeof(PIAnalysis))); Assert.AreEqual(piAnalysis.Id, piAnalysis2.Id); PIAnalysisCategory piAnalysisCategory = client.AnalysisCategory.GetByPath(Constants.AF_ANALYSIS_CATEGORY_PATH); PIAnalysisCategory piAnalysisCategory2 = client.AnalysisCategory.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ANALYSIS_CATEGORY_PATH, typeof(PIAnalysisCategory))); Assert.AreEqual(piAnalysisCategory.Id, piAnalysisCategory2.Id); PIAnalysisRule piAnalysisRule = client.AnalysisRule.GetByPath(Constants.AF_ANALYSIS_RULE_PATH); WebIdInfo piAnalysisRuleWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAnalysisRule.WebId); PIAnalysisRule piAnalysisRule2 = client.AnalysisRule.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ANALYSIS_RULE_PATH, typeof(PIAnalysisRule), piAnalysisRuleWebIdInfo.OwnerType)); Assert.AreEqual(piAnalysisRule.Id, piAnalysisRule2.Id); PIAnalysisRulePlugIn piAnalysisRulePlugIn = client.AnalysisRulePlugIn.GetByPath(Constants.AF_ANALYSIS_RULE_PLUGIN_PATH); PIAnalysisRulePlugIn piAnalysisRulePlugIn2 = client.AnalysisRulePlugIn.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ANALYSIS_RULE_PLUGIN_PATH, typeof(PIAnalysisRulePlugIn))); Assert.AreEqual(piAnalysisRulePlugIn.Id, piAnalysisRulePlugIn2.Id); PIAnalysisTemplate piAnalysisTemplate = client.AnalysisTemplate.GetByPath(Constants.AF_ANALYSIS_TEMPLATE_PATH); PIAnalysisTemplate piAnalysisTemplate2 = client.AnalysisTemplate.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ANALYSIS_TEMPLATE_PATH, typeof(PIAnalysisTemplate))); Assert.AreEqual(piAnalysisTemplate.Id, piAnalysisTemplate2.Id); PIAssetDatabase piAssetDatabase = client.AssetDatabase.GetByPath(Constants.AF_DATABASE_PATH); PIAssetDatabase piAssetDatabase2 = client.AssetDatabase.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_DATABASE_PATH, typeof(PIAssetDatabase))); Assert.AreEqual(piAssetDatabase.Id, piAssetDatabase2.Id); PIAssetServer piAssetServer = client.AssetServer.GetByPath(Constants.AF_SERVER_PATH); PIAssetServer piAssetServer2 = client.AssetServer.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_SERVER_PATH, typeof(PIAssetServer))); Assert.AreEqual(piAnalysisCategory.Id, piAnalysisCategory2.Id); PIAttribute piAttribute = client.Attribute.GetByPath(Constants.AF_ATTRIBUTE_PATH); WebIdInfo piAttributeWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAttribute.WebId); PIAttribute piAttribute2 = client.Attribute.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ATTRIBUTE_PATH, typeof(PIAttribute), piAttributeWebIdInfo.OwnerType)); Assert.AreEqual(piAttribute.Id, piAttribute2.Id); PIAttributeCategory piAttributeCategory = client.AttributeCategory.GetByPath(Constants.AF_ATTRIBUTE_CATEGORY_PATH); PIAttributeCategory piAttributeCategory2 = client.AttributeCategory.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ATTRIBUTE_CATEGORY_PATH, typeof(PIAttributeCategory))); Assert.AreEqual(piAnalysisCategory.Id, piAnalysisCategory2.Id); PIAttributeTemplate piAttributeTemplate = client.AttributeTemplate.GetByPath(Constants.AF_ATTRIBUTE_TEMPLATE_PATH); WebIdInfo piAttributeTemplateWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAttributeTemplate.WebId); PIAttributeTemplate piAttributeTemplate2 = client.AttributeTemplate.Get(client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ATTRIBUTE_TEMPLATE_PATH, typeof(PIAttributeTemplate), piAttributeTemplateWebIdInfo.OwnerType)); Assert.AreEqual(piAttributeTemplate.Id, piAttributeTemplate2.Id); PIDataServer piDataServer = client.DataServer.GetByPath(Constants.PI_DATA_SERVER_PATH); PIDataServer piDataServer2 = client.DataServer.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.PI_DATA_SERVER_PATH, typeof(PIDataServer))); Assert.AreEqual(piDataServer.Id, piDataServer2.Id); PIElement piElement = client.Element.GetByPath(Constants.AF_ELEMENT_PATH); PIElement piElement2 = client.Element.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ELEMENT_PATH, typeof(PIElement))); Assert.AreEqual(piElement.Id, piElement2.Id); PIElementCategory piElementCategory = client.ElementCategory.GetByPath(Constants.AF_ELEMENT_CATEGORY_PATH); PIElementCategory piElementCategory2 = client.ElementCategory.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ELEMENT_CATEGORY_PATH, typeof(PIElementCategory))); Assert.AreEqual(piAnalysisCategory.Id, piAnalysisCategory2.Id); PIElementTemplate piElementTemplate = client.ElementTemplate.GetByPath(Constants.AF_ELEMENT_TEMPLATE_PATH); PIElementTemplate piElementTemplate2 = client.ElementTemplate.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ELEMENT_TEMPLATE_PATH, typeof(PIElementTemplate))); Assert.AreEqual(piAnalysisCategory.Id, piAnalysisCategory2.Id); PIEnumerationSet piEnumerationSet = client.EnumerationSet.GetByPath(Constants.AF_ENUMERATION_SET_PATH); WebIdInfo piEnumerationSetWebIdInfo = client.WebIdHelper.GetWebIdInfo(piEnumerationSet.WebId); PIEnumerationSet piEnumerationSet2 = client.EnumerationSet.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ENUMERATION_SET_PATH, typeof(PIEnumerationSet), piEnumerationSetWebIdInfo.OwnerType)); Assert.AreEqual(piEnumerationSet.Id, piEnumerationSet2.Id); PIEnumerationValue piEnumerationValue = client.EnumerationValue.GetByPath(Constants.AF_ENUMERATION_VALUE_PATH); WebIdInfo piEnumerationValueWebIdInfo = client.WebIdHelper.GetWebIdInfo(piEnumerationValue.WebId); PIEnumerationValue piEnumerationValue2 = client.EnumerationValue.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_ENUMERATION_VALUE_PATH, typeof(PIEnumerationValue), piEnumerationValueWebIdInfo.OwnerType)); Assert.AreEqual(piEnumerationValue.Id, piEnumerationValue2.Id); //AFEventFrame ev = AFObject.FindObject(Constants.AF_EVENT_FRAME_PATH) as AFEventFrame; //string webId33 = ev.GetWebID(WebIDType.PathOnly); //PIEventFrame piEventFrame = client.EventFrame.GetByPath(Constants.AF_EVENT_FRAME_PATH); //WebIdInfo piEventFrameWebIdInfo = client.WebIdHelper.GetWebIdInfo(piEventFrame.WebId); //PIEventFrame piEventFrame2 = client.EventFrame.Get( // client.WebIdHelper.GenerateWebIdByPath(Constants.AF_EVENT_FRAME_PATH, typeof(PIEventFrame))); //Assert.AreEqual(piEventFrame.Id, piEventFrame2.Id); PIPoint piPoint = client.Point.GetByPath(Constants.PI_POINT_PATH); PIPoint piPoint2 = client.Point.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.PI_POINT_PATH, typeof(PIPoint))); Assert.AreEqual(piPoint.Id, piPoint2.Id); PISecurityIdentity piSecurityIdentity = client.SecurityIdentity.GetByPath(Constants.AF_SECURITY_IDENTITY_PATH); PISecurityIdentity piSecurityIdentity2 = client.SecurityIdentity.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_SECURITY_IDENTITY_PATH, typeof(PISecurityIdentity))); Assert.AreEqual(piSecurityIdentity.Id, piSecurityIdentity2.Id); PISecurityMapping piSecurityMapping = client.SecurityMapping.GetByPath(Constants.AF_SECURITY_MAPPING_PATH); PISecurityMapping piSecurityMapping2 = client.SecurityMapping.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_SECURITY_MAPPING_PATH, typeof(PISecurityMapping))); Assert.AreEqual(piSecurityMapping.Id, piSecurityMapping2.Id); PITable piTable = client.Table.GetByPath(Constants.AF_TABLE_PATH); PITable piTable2 = client.Table.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_TABLE_PATH, typeof(PITable))); Assert.AreEqual(piTable.Id, piTable2.Id); PITableCategory piTableCategory = client.TableCategory.GetByPath(Constants.AF_TABLE_CATEGORY_PATH); PITableCategory piTableCategory2 = client.TableCategory.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_TABLE_CATEGORY_PATH, typeof(PITableCategory))); Assert.AreEqual(piTableCategory.Id, piTableCategory2.Id); PIUnit piUnit = client.Unit.GetByPath(Constants.AF_UOM_PATH); PIUnit piUnit2 = client.Unit.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_UOM_PATH, typeof(PIUnit))); Assert.AreEqual(piUnit.Id, piUnit2.Id); PIUnitClass piUnitClass = client.UnitClass.GetByPath(Constants.AF_UOM_CLASS_PATH); PIUnitClass piUnitClass2 = client.UnitClass.Get( client.WebIdHelper.GenerateWebIdByPath(Constants.AF_UOM_CLASS_PATH, typeof(PIUnitClass))); Assert.AreEqual(piUnitClass.Id, piUnitClass2.Id); }
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); }; }
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--; } }
public void GetWebIDOnlyTest() { string webIdType = "IDOnly"; PIAnalysis piAnalysis = client.Analysis.GetByPath(Constants.AF_ANALYSIS_PATH, null, webIdType); WebIdInfo piAnalysisWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAnalysis.WebId); Assert.AreNotEqual(Constants.AF_ANALYSIS_PATH.ToUpper().Substring(2), piAnalysisWebIdInfo.Path); Assert.AreEqual(piAnalysis.Id, piAnalysisWebIdInfo.ObjectID.ToString()); PIAnalysisCategory piAnalysisCategory = client.AnalysisCategory.GetByPath(Constants.AF_ANALYSIS_CATEGORY_PATH, null, webIdType); WebIdInfo piAnalysisCategoryWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAnalysisCategory.WebId); Assert.AreNotEqual(Constants.AF_ANALYSIS_CATEGORY_PATH.ToUpper().Substring(2), piAnalysisCategoryWebIdInfo.Path); Assert.AreEqual(piAnalysisCategory.Id, piAnalysisCategoryWebIdInfo.ObjectID.ToString()); PIAnalysisRule piAnalysisRule = client.AnalysisRule.GetByPath(Constants.AF_ANALYSIS_RULE_PATH, null, webIdType); WebIdInfo piAnalysisRuleWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAnalysisRule.WebId); Assert.AreNotEqual(Constants.AF_ANALYSIS_RULE_PATH.ToUpper().Substring(2), piAnalysisRuleWebIdInfo.Path); Assert.AreEqual(piAnalysisRule.Id, piAnalysisRuleWebIdInfo.ObjectID.ToString()); PIAnalysisRulePlugIn piAnalysisRulePlugIn = client.AnalysisRulePlugIn.GetByPath(Constants.AF_ANALYSIS_RULE_PLUGIN_PATH, null, webIdType); WebIdInfo piAnalysisRulePlugInWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAnalysisRulePlugIn.WebId); Assert.AreNotEqual(Constants.AF_ANALYSIS_RULE_PLUGIN_PATH.ToUpper().Substring(2), piAnalysisRulePlugInWebIdInfo.Path); Assert.AreEqual(piAnalysisRulePlugIn.Id, piAnalysisRulePlugInWebIdInfo.ObjectID.ToString()); PIAnalysisTemplate piAnalysisTemplate = client.AnalysisTemplate.GetByPath(Constants.AF_ANALYSIS_TEMPLATE_PATH, null, webIdType); WebIdInfo piAnalysisTemplateWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAnalysisTemplate.WebId); Assert.AreNotEqual(Constants.AF_ANALYSIS_TEMPLATE_PATH.ToUpper().Substring(2), piAnalysisTemplateWebIdInfo.Path); Assert.AreEqual(piAnalysisTemplate.Id, piAnalysisTemplateWebIdInfo.ObjectID.ToString()); PIAssetDatabase piAssetDatabase = client.AssetDatabase.GetByPath(Constants.AF_DATABASE_PATH, null, webIdType); WebIdInfo piAssetDatabaseWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAssetDatabase.WebId); Assert.AreNotEqual(Constants.AF_DATABASE_PATH.ToUpper().Substring(2), piAssetDatabaseWebIdInfo.Path); Assert.AreEqual(piAssetDatabase.Id, piAssetDatabaseWebIdInfo.ObjectID.ToString()); PIAssetServer piAssetServer = client.AssetServer.GetByPath(Constants.AF_SERVER_PATH, null, webIdType); WebIdInfo piAssetServerWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAssetServer.WebId); Assert.AreNotEqual(Constants.AF_SERVER_PATH.ToUpper().Substring(2), piAssetServerWebIdInfo.Path); Assert.AreEqual(piAssetServer.Id, piAssetServerWebIdInfo.ServerID.ToString()); PIAttribute piAttribute = client.Attribute.GetByPath(Constants.AF_ATTRIBUTE_PATH, null, webIdType); WebIdInfo piAttributeWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAttribute.WebId); Assert.AreNotEqual(Constants.AF_ATTRIBUTE_PATH.ToUpper().Substring(2), piAttributeWebIdInfo.Path); Assert.AreEqual(piAttribute.Id, piAttributeWebIdInfo.ObjectID.ToString()); PIAttributeCategory piAttributeCategory = client.AttributeCategory.GetByPath(Constants.AF_ATTRIBUTE_CATEGORY_PATH, null, webIdType); WebIdInfo piAttributeCategoryWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAttributeCategory.WebId); Assert.AreNotEqual(Constants.AF_ATTRIBUTE_CATEGORY_PATH.ToUpper().Substring(2), piAttributeCategoryWebIdInfo.Path); Assert.AreEqual(piAttributeCategory.Id, piAttributeCategoryWebIdInfo.ObjectID.ToString()); PIAttributeTemplate piAttributeTemplate = client.AttributeTemplate.GetByPath(Constants.AF_ATTRIBUTE_TEMPLATE_PATH, null, webIdType); WebIdInfo piAttributeTemplateWebIdInfo = client.WebIdHelper.GetWebIdInfo(piAttributeTemplate.WebId); Assert.AreNotEqual(Constants.AF_ATTRIBUTE_TEMPLATE_PATH.ToUpper().Substring(2), piAttributeTemplateWebIdInfo.Path); Assert.AreEqual(piAttributeTemplate.Id, piAttributeTemplateWebIdInfo.ObjectID.ToString()); PIDataServer piDataServer = client.DataServer.GetByPath(Constants.PI_DATA_SERVER_PATH, null, webIdType); WebIdInfo piDataServerWebIdInfo = client.WebIdHelper.GetWebIdInfo(piDataServer.WebId); Assert.AreNotEqual(Constants.PI_DATA_SERVER_PATH.ToUpper().Substring(2), piDataServerWebIdInfo.Path); Assert.AreEqual(piDataServer.Id, piDataServerWebIdInfo.ServerID.ToString()); PIElement piElement = client.Element.GetByPath(Constants.AF_ELEMENT_PATH, null, webIdType); WebIdInfo piElementWebIdInfo = client.WebIdHelper.GetWebIdInfo(piElement.WebId); Assert.AreNotEqual(Constants.AF_ELEMENT_PATH.ToUpper().Substring(2), piElementWebIdInfo.Path); Assert.AreEqual(piElement.Id, piElementWebIdInfo.ObjectID.ToString()); PIElementCategory piElementCategory = client.ElementCategory.GetByPath(Constants.AF_ELEMENT_CATEGORY_PATH, null, webIdType); WebIdInfo piElementCategoryWebIdInfo = client.WebIdHelper.GetWebIdInfo(piElementCategory.WebId); Assert.AreNotEqual(Constants.AF_ELEMENT_CATEGORY_PATH.ToUpper().Substring(2), piElementCategoryWebIdInfo.Path); Assert.AreEqual(piElementCategory.Id, piElementCategoryWebIdInfo.ObjectID.ToString()); PIElementTemplate piElementTemplate = client.ElementTemplate.GetByPath(Constants.AF_ELEMENT_TEMPLATE_PATH, null, webIdType); WebIdInfo piElementTemplateWebIdInfo = client.WebIdHelper.GetWebIdInfo(piElementTemplate.WebId); Assert.AreNotEqual(Constants.AF_ELEMENT_TEMPLATE_PATH.ToUpper().Substring(2), piElementTemplateWebIdInfo.Path); Assert.AreEqual(piElementTemplate.Id, piElementTemplateWebIdInfo.ObjectID.ToString()); PIEnumerationSet piEnumerationSet = client.EnumerationSet.GetByPath(Constants.AF_ENUMERATION_SET_PATH, null, webIdType); WebIdInfo piEnumerationSetWebIdInfo = client.WebIdHelper.GetWebIdInfo(piEnumerationSet.WebId); Assert.AreNotEqual(Constants.AF_ENUMERATION_SET_PATH.ToUpper().Substring(2), piEnumerationSetWebIdInfo.Path); Assert.AreEqual(piEnumerationSet.Id, piEnumerationSetWebIdInfo.ObjectID.ToString()); PIEnumerationValue piEnumerationValue = client.EnumerationValue.GetByPath(Constants.AF_ENUMERATION_VALUE_PATH, null, webIdType); WebIdInfo piEnumerationValueWebIdInfo = client.WebIdHelper.GetWebIdInfo(piEnumerationValue.WebId); Assert.AreNotEqual(Constants.AF_ENUMERATION_VALUE_PATH.ToUpper().Substring(2), piEnumerationValueWebIdInfo.Path); Assert.AreEqual(piEnumerationValue.Id, piEnumerationValueWebIdInfo.ObjectID.ToString()); PIEventFrame piEventFrame = client.EventFrame.GetByPath(Constants.AF_EVENT_FRAME_PATH, null, webIdType); WebIdInfo piEventFrameWebIdInfo = client.WebIdHelper.GetWebIdInfo(piEventFrame.WebId); Assert.AreNotEqual(Constants.AF_EVENT_FRAME_PATH.ToUpper().Substring(2), piEventFrameWebIdInfo.Path); Assert.AreEqual(piEventFrame.Id, piEventFrameWebIdInfo.ObjectID.ToString()); PIPoint piPoint = client.Point.GetByPath(Constants.PI_POINT_PATH, null, webIdType); WebIdInfo piPointWebIdInfo = client.WebIdHelper.GetWebIdInfo(piPoint.WebId); Assert.AreNotEqual(Constants.PI_POINT_PATH.ToUpper().Substring(2), piPointWebIdInfo.Path); Assert.AreEqual(piPoint.Id.ToString(), piPointWebIdInfo.PointID.ToString()); PISecurityIdentity piSecurityIdentity = client.SecurityIdentity.GetByPath(Constants.AF_SECURITY_IDENTITY_PATH, null, webIdType); WebIdInfo piSecurityIdentityWebIdInfo = client.WebIdHelper.GetWebIdInfo(piSecurityIdentity.WebId); Assert.AreNotEqual(Constants.AF_SECURITY_IDENTITY_PATH.ToUpper().Substring(2), piSecurityIdentityWebIdInfo.Path); Assert.AreEqual(piSecurityIdentity.Id, piSecurityIdentityWebIdInfo.ObjectID.ToString()); PISecurityMapping piSecurityMapping = client.SecurityMapping.GetByPath(Constants.AF_SECURITY_MAPPING_PATH, null, webIdType); WebIdInfo piSecurityMappingWebIdInfo = client.WebIdHelper.GetWebIdInfo(piSecurityMapping.WebId); Assert.AreNotEqual(Constants.AF_SECURITY_MAPPING_PATH.ToUpper().Substring(2), piSecurityMappingWebIdInfo.Path); Assert.AreEqual(piSecurityMapping.Id, piSecurityMappingWebIdInfo.ObjectID.ToString()); PITable piTable = client.Table.GetByPath(Constants.AF_TABLE_PATH, null, webIdType); WebIdInfo piTableWebIdInfo = client.WebIdHelper.GetWebIdInfo(piTable.WebId); Assert.AreNotEqual(Constants.AF_TABLE_PATH.ToUpper().Substring(2), piTableWebIdInfo.Path); Assert.AreEqual(piTable.Id, piTableWebIdInfo.ObjectID.ToString()); PITableCategory piTableCategory = client.TableCategory.GetByPath(Constants.AF_TABLE_CATEGORY_PATH, null, webIdType); WebIdInfo piTableCategoryWebIdInfo = client.WebIdHelper.GetWebIdInfo(piTableCategory.WebId); Assert.AreNotEqual(Constants.AF_TABLE_CATEGORY_PATH.ToUpper().Substring(2), piTableCategoryWebIdInfo.Path); Assert.AreEqual(piTableCategory.Id, piTableCategoryWebIdInfo.ObjectID.ToString()); PIUnit piUnit = client.Unit.GetByPath(Constants.AF_UOM_PATH, null, webIdType); WebIdInfo piUnitWebIdInfo = client.WebIdHelper.GetWebIdInfo(piUnit.WebId); Assert.AreNotEqual(Constants.AF_UOM_PATH.ToUpper().Substring(2), piUnitWebIdInfo.Path); Assert.AreEqual(piUnit.Id, piUnitWebIdInfo.ObjectID.ToString()); PIUnitClass piUnitClass = client.UnitClass.GetByPath(Constants.AF_UOM_CLASS_PATH, null, webIdType); WebIdInfo piUnitClassWebIdInfo = client.WebIdHelper.GetWebIdInfo(piUnitClass.WebId); Assert.AreNotEqual(Constants.AF_UOM_CLASS_PATH.ToUpper().Substring(2), piUnitClassWebIdInfo.Path); Assert.AreEqual(piUnitClass.Id, piUnitClassWebIdInfo.ObjectID.ToString()); }
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(); }
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); }
public ApiResponsePIDataServer(int statusCode, IDictionary <string, string> headers, PIDataServer data) : base(statusCode, headers) { this.Data = data; }
private static async Task RunAsync() { PIWebApiClient client = new PIWebApiClient("https://localhost/piwebapi", true); //Example 1 - Connecting to PI Web API PILanding landing = await client.Home.GetAsync(); Console.WriteLine("The System Link is {0}", landing.Links.System); //Example 2 - Getting the PI Objects Web ID PIDataServer dataServer = client.DataServer.GetByName("SATURN-MARCOS"); PIPoint sinusoidPoint = client.Point.GetByPath("\\\\SATURN-MARCOS\\sinusoid"); PIElement element = client.Element.GetByPath("\\\\SATURN-MARCOS\\Talk\\Element1"); PIAttribute attribute = client.Attribute.GetByPath("\\\\SATURN-MARCOS\\Talk\\Element1|Attribute1"); //Example 3 - Handling exceptions try { PIWebApiClient client2 = new PIWebApiClient("https://devdata.osisoft.com/piwebapi", true); //Example 1 - Connecting to PI Web API await client2.Home.GetAsync(); } catch (ApiException e) { Console.WriteLine("Expected exception: {0}", e.Message); } try { PIPoint sinusoidPoint2 = client.Point.GetByPath("\\\\SATURN-MARCOS\\sin453534usoid"); } catch (ApiException e) { Console.WriteLine("Expected exception: {0}", e.Message); } //Example 4 - Change the description of the PI Point PIPoint updatedPIPoint = new PIPoint(); updatedPIPoint.Descriptor = "New descriptor!!"; var res = client.Point.UpdateWithHttpInfo(sinusoidPoint.WebId, updatedPIPoint); if (res.StatusCode < 300) { Console.WriteLine("Success!"); } //Example 5 - Retrieving data in bulk PIPoint point1 = client.Point.GetByPath("\\\\SATURN-MARCOS\\sinusoid"); PIPoint point2 = client.Point.GetByPath("\\\\SATURN-MARCOS\\sinusoidu"); PIPoint point3 = client.Point.GetByPath("\\\\SATURN-MARCOS\\cdt158"); List <string> webIds = new List <string>() { point1.WebId, point2.WebId, point3.WebId }; PIItemsStreamValues itemsStreamValues = client.StreamSet.GetRecordedAdHoc(webIds, startTime: "*-1d", endTime: "*"); foreach (PIStreamValues streamValues in itemsStreamValues.Items) { foreach (PITimedValue value in streamValues.Items) { Console.WriteLine("{0} {1} {2}", streamValues.Name, value.Value, value.Timestamp); } } ////Example 6 - Sending data in bulk var piStreamValuesList = new List <PIStreamValues>() { new PIStreamValues() { WebId = point1.WebId, Items = new List <PITimedValue>() { new PITimedValue() { Value = 2, Timestamp = "*-1d" }, new PITimedValue() { Value = 3, Timestamp = "*-2d" } }, }, new PIStreamValues() { WebId = point2.WebId, Items = new List <PITimedValue>() { new PITimedValue() { Value = 4, Timestamp = "*-1d" }, new PITimedValue() { Value = 5, Timestamp = "*-2d" } }, }, new PIStreamValues() { WebId = point3.WebId, Items = new List <PITimedValue>() { new PITimedValue() { Value = 6, Timestamp = "*-1d" }, new PITimedValue() { Value = 7, Timestamp = "*-2d" } }, }, }; ApiResponse <PIItemsItemsSubstatus> response2 = client.StreamSet.UpdateValuesAdHocWithHttpInfo(piStreamValuesList); if (response2.StatusCode < 300) { Console.WriteLine("The values were updated successfully."); } //Example 7 - PI Web API Batch Dictionary <string, PIRequest> batch = new Dictionary <string, PIRequest>() { { "1", new PIRequest("GET", "https://localhost/piwebapi/points?path=\\\\SATURN-MARCOS\\sinusoid") }, { "2", new PIRequest("GET", "https://localhost/piwebapi/points?path=\\\\SATURN-MARCOS\\cdt158") }, { "3", new PIRequest() { Method = "GET", Resource = "https://localhost/piwebapi/streamsets/value?webid={0}&webid={1}", Parameters = new List <string>() { "$.1.Content.WebId", "$.2.Content.WebId" }, ParentIds = new List <string>() { "1", "2" } } } }; Dictionary <string, PIResponse> batchResponse = await client.BatchApi.ExecuteAsync(batch); if (batchResponse.All(r => r.Value.Status == 200)) { PIPoint pointBatch1 = JsonConvert.DeserializeObject <PIPoint>(batchResponse["1"].Content.ToString()); PIPoint pointBatch2 = JsonConvert.DeserializeObject <PIPoint>(batchResponse["2"].Content.ToString()); PIItemsStreamValue batchStreamValues = JsonConvert.DeserializeObject <PIItemsStreamValue>(batchResponse["3"].Content.ToString()); foreach (PIStreamValue piStreamValue in batchStreamValues.Items) { Console.WriteLine("PI Point: {0}, Value: {1}, Timestamp: {2}", piStreamValue.Name, piStreamValue.Value.Value, piStreamValue.Value.Timestamp); } } //Example 8 - Getting Web ID 2.0 information WebIdInfo webIdInfo = client.WebIdHelper.GetWebIdInfo(element.WebId); Console.WriteLine("Element Path is: {0}", webIdInfo.Path); WebIdInfo webIdInfo2 = client.WebIdHelper.GetWebIdInfo(attribute.WebId); Console.WriteLine("Attribute Path is: {0}", webIdInfo.Path); WebIdInfo webIdInfo4 = client.WebIdHelper.GetWebIdInfo(point1.WebId); Console.WriteLine("PI Point Path is: {0}", webIdInfo.Path); WebIdInfo webIdInfo3 = client.WebIdHelper.GetWebIdInfo(dataServer.WebId); Console.WriteLine("PI Data Server Path is: {0}", webIdInfo.Path); //Example 9 - Generating Web ID 2.0 using path string webId1PathOnly = client.WebIdHelper.GenerateWebIdByPath("\\\\SATURN-MARCOS", typeof(PIDataServer)); PIDataServer dataServer2 = client.DataServer.Get(webId1PathOnly); string webId2PathOnly = client.WebIdHelper.GenerateWebIdByPath("\\\\SATURN-MARCOS\\Talk\\Element1|Attribute1", typeof(PIAttribute), typeof(PIElement)); PIAttribute attribute2 = client.Attribute.Get(webId2PathOnly); }
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); }