public async Task AsyncTask_updateinfo() { IList <PIPointChangeInfo> clist = new List <PIPointChangeInfo>(); Action asyncJobupdateinfo = () => { PIPointChangesCookie cookie = null; while (updateval2 == 0) { if (myPIServer != null) { if (monitval == 0) { monitval = 1; cookie = null; UpdMonitorLabel("Monitoring ON (" + myPIServer.Name + ")"); } if (ReferenceEquals(cookie, null)) { clist = myPIServer.FindChangedPIPoints(int.MaxValue, null, out cookie); } else { clist = myPIServer.FindChangedPIPoints(int.MaxValue, cookie, out cookie); } if (clist != null) { foreach (PIPointChangeInfo change in clist) { //MessageBox.Show(change.ID + " : " + change.Action); string[] displayvalues = new string[3]; if (change.Action.ToString() == "Removed") { displayvalues[0] = change.ID.ToString(); } else { PIPoint mypt = PIPoint.FindPIPoint(myPIServer, change.ID); displayvalues[0] = mypt.Name; } displayvalues[1] = change.Action.ToString(); displayvalues[2] = DateTime.Now.ToString(); ListViewItem lvi = new ListViewItem(displayvalues); UpdListView2(lvi); } } } } }; await Task.Run(asyncJobupdateinfo); }
public void PointUpdatesTest() { // Construct a unique PI Point name string pointNameFormat = $"PointUpdateTestPoint{AFTime.Now}"; // Expected number of changes const int ExpectedChangeCount = 3; var nameOfPointToDelete = pointNameFormat; Utils.CheckTimeDrift(Fixture, Output); PIPointChangesCookie cookie = null; try { // Initialize to start monitoring changes Output.WriteLine($"Prepare to receive PI Point change notifications."); Fixture.PIServer.FindChangedPIPoints(int.MaxValue, null, out cookie); // Perform the operation 10 times... Output.WriteLine($"Create PI Points and process change notifications."); for (int loopIndex = 0; loopIndex < 10; loopIndex++) { // Create a new PI Point which should cause a change (#1) PIPoint testPoint = Fixture.PIServer.CreatePIPoint(pointNameFormat); nameOfPointToDelete = pointNameFormat; // Edit the PI Point's name to cause a change (#2) testPoint.Name = string.Concat(testPoint.Name, "_Renamed"); nameOfPointToDelete = testPoint.Name; // Delete the PI Point which should cause a change (#3) Fixture.PIServer.DeletePIPoint(testPoint.Name); // Sleep a bit to make sure all processing has completed Thread.Sleep(TimeSpan.FromSeconds(3)); // Log changes that have occurred since the last call var changes = Fixture.PIServer.FindChangedPIPoints( int.MaxValue, cookie, out cookie, new PIPointList() { testPoint }); if (changes != null) { foreach (var info in changes) { Output.WriteLine($"Change [{info.Action}] made on point with ID [{info.ID}]."); Assert.True(testPoint.ID == info.ID, $"Expected change on point with ID: [{testPoint.ID}], Actual change point ID: [{info.ID}]."); } Assert.True(changes.Count == ExpectedChangeCount, $"Expected the number of change to be {ExpectedChangeCount}, but there were actually {changes.Count} on iteration {loopIndex + 1}."); } } Output.WriteLine("Retrieved PI Point change notifications successfully."); } finally { Fixture.DeletePIPoints($"{pointNameFormat}*", Output); Fixture.DeletePIPoints($"{nameOfPointToDelete}*", Output); cookie?.Dispose(); } }