private void MonitorAFAttributes() { DataPipeHandler afDataPipeHandler = null; try { //connect to AF Server if (string.IsNullOrEmpty(AFServerName)) { throw new AFServerNotFoundException(); } else { AFDatabase database; var _afConnectionManager = AfConnectionMgr.ConnectAndGetDatabase(AFServerName, AFDatabaseName, out database); // get the attributes that will be monitored IDictionary<string, string> findAttributesErrors; var attributes = AFAttribute.FindAttributesByPath(AttributesList, database, out findAttributesErrors); // in case there was errors in the search we display them if (findAttributesErrors != null && findAttributesErrors.Count > 0) findAttributesErrors.ToList().ForEach(e => Logger.ErrorFormat("{0},{1}", e.Key, e.Value)); afDataPipeHandler = new DataPipeHandler(new AFConsoleDataObserver()); afDataPipeHandler.AddSignupsWithInitEvents(attributes); afDataPipeHandler.StartListening(TimeSpan.FromSeconds(Interval)); Logger.InfoFormat("Listening for data changes started. Checking every {0}s", Interval); } } catch (Exception ex) { Logger.Error(ex); } finally { _terminateRequest.WaitOne(); // null propagation operator, this is same as x!=null x.Dispose() afDataPipeHandler?.Dispose(); } }
private void MonitorAFAttributes() { //connect to AF Server if (string.IsNullOrEmpty(AFServerName)) { _terminateRequest.WaitOne(); } else { AFDatabase database; var _afConnectionManager = AfConnectionMgr.ConnectAndGetDatabase(AFServerName, AFDatabaseName, out database); // get the attributes that will be monitored IDictionary<string, string> findAttributesErrors; var attributes = AFAttribute.FindAttributesByPath(AttributesList, database, out findAttributesErrors); // in case there was errors in the search we display them if (findAttributesErrors != null && findAttributesErrors.Count > 0) findAttributesErrors.ToList().ForEach(e => Logger.ErrorFormat("{0},{1}", e.Key, e.Value)); var afDataPipeHandler = new DataPipeHandler(new AFConsoleDataObserver()); afDataPipeHandler.AddSignupsWithInitEvents(attributes); afDataPipeHandler.StartListening(TimeSpan.FromSeconds(5)); // here the method will wait until a key is pressed _terminateRequest.WaitOne(); afDataPipeHandler.Dispose(); } }
private void MonitorPITags() { DataPipeHandler archiveDataPipeHandler = null; DataPipeHandler snapshotDataPipeHandler = null; if (string.IsNullOrEmpty(PIServerName)) { _terminateRequest.WaitOne(); } else { try { PIServer piserver; var piConnectionManager = PiConnectionMgr.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); archiveDataPipeHandler.StartListening(TimeSpan.FromSeconds(5)); snapshotDataPipeHandler.StartListening(TimeSpan.FromSeconds(2)); } catch (Exception ex) { Logger.Error(ex); } finally { // here the method will wait until a key is pressed _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(); } } }
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(); } }