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);
            }
        }
Beispiel #2
0
        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();
            }
        }