/// <summary> /// This method deletes the data stored in specified tags of the PI Data Archive /// To delete data, it is required to first read the values that you want to delete, and then /// Call the update values method with the AFUpdateOption.Remove option /// <remarks> /// </remarks> /// </summary> private void DeleteData() { try { ValidateParameters(); piConnectionHelper = new PiConnectionHelper(Server); piConnectionHelper.Connect(); PIServer server = piConnectionHelper.GetPiServer(); var timer = Stopwatch.StartNew(); // Gets the tags and creates a point list with the tags, to prepare for bulk read call var points = PIPoint.FindPIPoints(server, TagList); var pointList = new PIPointList(points); Logger.InfoFormat("Initialized PI Points for deletion: {0}", string.Join(", ", points.Select(p => p.Name))); // converts strings to AFTime objects this will throw an error if invalid var startTime = new AFTime(StartTime); var endTime = new AFTime(EndTime); if (startTime > endTime) { throw new PIDeleteUtilInvalidParameterException("Start Time must be smaller than End Time"); } // defines the data eraser task that will work in parallel as the data querying task dataEraser = new DataProcessor(EraseData); var eraseTask = Task.Run(() => dataEraser.Run()); // splits iterates the period, over foreach (var period in Library.Helpers.EachNDay(startTime, endTime, Days)) { Logger.InfoFormat("Getting tags information for period {0} to {1} ({2} Days chunk)", startTime, endTime, Days); // makes the first data call var data = pointList.RecordedValues(period, AFBoundaryType.Inside, null, false, new PIPagingConfiguration(PIPageType.TagCount, 100)); Logger.InfoFormat("Adding the data to the queue for deletion. ({0} to {1})", startTime, endTime); // we push this data into the data processor queue so we can continue to query for the rest of the data. dataEraser.DataQueue.Add(data); } dataEraser.DataQueue.CompleteAdding(); // // this will tell the data eraser that no more data will be added and allow it to complete eraseTask.Wait(); // waiting for the data processor to complete Logger.InfoFormat( "Deletion process completed in {0} seconds. With {1} events deleted (assuming there was no errors).", Math.Round(timer.Elapsed.TotalSeconds, 0), dataEraser.TotalEventProcessed); } catch (Exception ex) { Logger.Error(ex); } }
public override void Run() { PIServer server = null; try { ValidateParameters(); PiConnectionHelper.ConnectAndGetServer(Server, out server); if (Delete) { DeleteTags(server); } else { var newPoints = CreatePoints(server); if (DataSt != null) { GenerateData(newPoints); } } } catch (Exception ex) { Logger.Error(ex); } }
private void MonitorPITags() { DataPipeHandler archiveDataPipeHandler = null; DataPipeHandler snapshotDataPipeHandler = null; try { if (string.IsNullOrEmpty(PIServerName)) { throw new PIServerNotFoundException(); } else { PIServer piserver; var piConnectionManager = PiConnectionHelper.ConnectAndGetServer(PIServerName, out piserver); // get the tag we want to monitor var pointList = PIPoint.FindPIPoints(piserver, TagList).ToList(); // event pipe for archive modifications var archive = AFDataPipeType.Archive; archiveDataPipeHandler = new DataPipeHandler(new PIConsoleDataObserver(archive), archive); archiveDataPipeHandler.AddSignupsWithInitEvents(pointList); // event pipe for snpshot modifications var snapshot = AFDataPipeType.Snapshot; snapshotDataPipeHandler = new DataPipeHandler(new PIConsoleDataObserver(snapshot), snapshot); snapshotDataPipeHandler.AddSignupsWithInitEvents(pointList); // archive data pipe is for demonstrative use // you may only need the snapshot in your application, this depends on your use case archiveDataPipeHandler.StartListening(TimeSpan.FromSeconds(Interval)); snapshotDataPipeHandler.StartListening(TimeSpan.FromSeconds(Interval)); Logger.InfoFormat("Listening for data changes started. Checking every {0}s", Interval); } } catch (Exception ex) { Logger.Error(ex); } finally { // here the method will wait until _terminateRequest.Set() before terminating _terminateRequest.WaitOne(); // in case you don't know this is called null propagation // its equivalent to if x!=null x.Dispose() archiveDataPipeHandler?.Dispose(); snapshotDataPipeHandler?.Dispose(); } }
public override void Run() { try { PiConnectionHelper piConnectionHelper = new PiConnectionHelper(Server); piConnectionHelper.Connect(); PIServer pi = piConnectionHelper.GetPiServer(); List <PIPoint> points = PIPoint.FindPIPoints(pi, NameFilter, SourceFilter).ToList(); Logger.InfoFormat("{0} Tags Found", points.Count()); Logger.Info(string.Join(",", points.Select(p => p.Name))); } catch (Exception ex) { Logger.Error(ex); } }
public override void Run() { try { PiConnectionHelper piConnectionHelper = new PiConnectionHelper(Server); piConnectionHelper.Connect(); PIServer pi = piConnectionHelper.GetPiServer(); PIPoint point = PIPoint.FindPIPoint(pi, Tag); AFValue value = point.CurrentValue(); Logger.InfoFormat("The current value for PI Point {0} is : {1} - {2}", Tag, value.Timestamp, value.Value); } catch (Exception ex) { Logger.Error(ex); } }
public override void Run() { try { PiConnectionHelper piConnectionHelper = new PiConnectionHelper(Server); piConnectionHelper.Connect(); PIServer pi = piConnectionHelper.GetPiServer(); PIPointList pointList = new PIPointList(PIPoint.FindPIPoints(pi, TagMask)); AFListResults <PIPoint, AFValue> values = pointList.CurrentValue(); foreach (AFValue val in values) { Logger.InfoFormat("The current value for PI Point {0} is : {1} - {2}", val.PIPoint, val.Timestamp, val.Value); } } catch (Exception ex) { Logger.Error(ex); } }