コード例 #1
0
        private void MonitorAFAttributes()
        {
            DataPipeHandler afDataPipeHandler = null;

            try
            {
                //connect to AF Server
                if (string.IsNullOrEmpty(AFServerName))
                {
                    throw new AFServerNotFoundException();
                }

                else
                {
                    AFDatabase database;
                    var        _afConnectionManager = AfConnectionHelper.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();
            }
        }
コード例 #2
0
        public void GetPIData(string[] paths, string startTime, string endTime, string interval)
        {
            string[] correctPaths = paths.Select(m => m.Substring(3)).ToArray();
            AFKeyedResults <string, AFAttribute> results = AFAttribute.FindAttributesByPath(correctPaths, null);
            AFAttributeList attributeList = new AFAttributeList();

            foreach (AFAttribute attribute in results)
            {
                attributeList.Add(attribute);
            }

            AFTime                 start        = new AFTime(startTime);
            AFTime                 end          = new AFTime(endTime);
            AFTimeRange            timeRange    = new AFTimeRange(start, end);
            AFTimeSpan             timeSpan     = AFTimeSpan.Parse(interval);
            IEnumerable <AFValues> valueResults = attributeList.Data.InterpolatedValues(timeRange, timeSpan, string.Empty, false, new PIPagingConfiguration(PIPageType.TagCount, 100));

            piValuesList = new PIValuesList(valueResults);
        }
コード例 #3
0
        public void Run()
        {
            string processFeedRate = @"\\<AFSERVER>\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Process Feedrate";
            string waterFlow       = @"\\<AFSERVER>\NuGreen\NuGreen\Houston\Cracking Process\Equipment\B-210|Water Flow";

            // Directly locate the AFAttribute of interest by passing in the AF path.
            // A similar method FindElementsByPath can be used to directly locate elements.
            AFKeyedResults <string, AFAttribute> results = AFAttribute.FindAttributesByPath(new[] { processFeedRate, waterFlow }, null);

            AFAttribute processFeedRateAttribute = results[processFeedRate];
            AFAttribute waterFlowAttribute       = results[waterFlow];

            AFAttributeList attrList = new AFAttributeList(new[] { processFeedRateAttribute, waterFlowAttribute });
            // Make a bulk call to get values.
            AFValues values = attrList.GetValue();

            foreach (AFValue val in values)
            {
                Console.WriteLine("Attribute: {0}", val.Attribute);
                Console.WriteLine("Timestamp: {0}, Value: {1}", val.Timestamp, val.Value.ToString());
                Console.WriteLine();
            }
        }