public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem piSystem = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            AFElementTemplate boilerTemplate = afDatabase.ElementTemplates["Boiler"];

            const int pageSize = 1000;
            int startIndex = 0;
            int totalCount;
            do
            {
                // Find a collection of elements instantiated from the Boiler tempplate.
                // Only the Elements' header information (Name, Description, Template, Type, etc.)
                // are loaded from the AF Server by this call.
                AFNamedCollection<AFElement> elements = AFElement.FindElements(
                    database: afDatabase,
                    searchRoot: null,
                    query: "Boiler",
                    field: AFSearchField.Template,
                    searchFullHierarchy: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);
                if (elements == null) break;

                // Partially load the element by retrieving information only for the Water Flow attribute.
                AFElement.LoadAttributes(elements, new[] { boilerTemplate.AttributeTemplates["Water Flow"] });

                Console.WriteLine("Found {0} Elements.", elements.Count);

                AFAttributeList attrList = new AFAttributeList();

                // Because we are retrieving the Water Flow attribute which was previously loaded,
                // no additional server calls are made.
                // If LoadAttributes had not been called previously, then a server call would have been made for each element
                // in the loop below.
                foreach (AFElement item in elements)
                {
                    attrList.Add(item.Attributes["Water Flow"]);
                }

                AFValues values = attrList.GetValue();

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

                startIndex += pageSize;

            } while (startIndex < totalCount);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            NetworkCredential credential = new NetworkCredential(connectionInfo.user, connectionInfo.password);
            var piSystem = (new PISystems())[connectionInfo.AFServerName];

            Console.WriteLine($"connecting to : {connectionInfo.AFServerName} - {connectionInfo.AFDatabaseName}");
            piSystem.Connect(credential);
            var afdb = piSystem.Databases[connectionInfo.AFDatabaseName];

            Console.WriteLine("connected");

            //element search
            var query  = "Template:'Antimatter Relay'";
            var search = new AFElementSearch(afdb, "Relay Search", query);

            var results  = search.FindElements(0, true, 1000);
            var attrList = new AFAttributeList();

            foreach (var element in results)
            {
                Console.WriteLine($"{element.Name}");
                foreach (var attribute in element.Attributes)
                {
                    //not optimized
                    //var snapShot = attribute.GetValue();
                    //Console.WriteLine($"{attribute.Name}: {snapShot.Value.ToString()} {snapShot.UOM}");

                    //optimized
                    attrList.Add(attribute);
                }
            }

            //one call to get values
            var snapShots = attrList.GetValue();

            foreach (var snapShot in snapShots)
            {
                Console.WriteLine($"Element: {snapShot.Attribute.Element.Name} - {snapShot.Attribute.Name}: {snapShot.Value.ToString()} {snapShot.UOM}");
            }

            Console.WriteLine("completed execution");
            //Console.ReadKey();
        }
Ejemplo n.º 3
0
        public override void Run()
        {
            try
            {
                var connection = new AfConnectionHelper(Server, Database);
                connection.Connect();

                AFDatabase database = connection.GetDatabase();

                var afObject = AFObject.FindObject(AttributePath, database);

                var separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;

                if (afObject is AFAttribute)
                {
                    var     attribute = (AFAttribute)afObject;
                    AFValue value     = attribute.GetValue();
                    Console.WriteLine("{0}{1}{2}{3}{4}", GetStringValue(value), separator, value.Timestamp, separator, attribute.Name);
                }

                if (afObject is AFElement)
                {
                    var element = (AFElement)afObject;

                    // the attibute list object allows a single GetValue() call for all attributes at same time.
                    // We call this a "Bulk Call"
                    var attributes = new AFAttributeList(element.Attributes);
                    var values     = attributes.GetValue();

                    // prints the results
                    values.ForEach((afvalue) => Console.WriteLine("{0}{1}{2}{3}{4}", GetStringValue(afvalue), separator, afvalue.Timestamp, separator, afvalue.Attribute.Name));
                }
            }

            catch (Exception ex)
            {
                this.Logger.Error(ex);
            }
        }
        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();
            }
        }
Ejemplo n.º 5
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();
            }
        }
        public void Run()
        {
            PISystems piSystems = new PISystems();
            PISystem  piSystem  = piSystems["<AFSERVER>"];

            AFDatabase afDatabase = piSystem.Databases["NuGreen"];

            AFElementTemplate boilerTemplate = afDatabase.ElementTemplates["Boiler"];

            const int pageSize   = 1000;
            int       startIndex = 0;
            int       totalCount;

            do
            {
                // Find a collection of elements instantiated from the Boiler tempplate.
                // Only the Elements' header information (Name, Description, Template, Type, etc.)
                // are loaded from the AF Server by this call.
                AFNamedCollection <AFElement> elements = AFElement.FindElements(
                    database: afDatabase,
                    searchRoot: null,
                    query: "Boiler",
                    field: AFSearchField.Template,
                    searchFullHierarchy: true,
                    sortField: AFSortField.Name,
                    sortOrder: AFSortOrder.Ascending,
                    startIndex: startIndex,
                    maxCount: pageSize,
                    totalCount: out totalCount);
                if (elements == null)
                {
                    break;
                }

                // Partially load the element by retrieving information only for the Water Flow attribute.
                AFElement.LoadAttributes(elements, new[] { boilerTemplate.AttributeTemplates["Water Flow"] });

                Console.WriteLine("Found {0} Elements.", elements.Count);

                AFAttributeList attrList = new AFAttributeList();

                // Because we are retrieving the Water Flow attribute which was previously loaded,
                // no additional server calls are made.
                // If LoadAttributes had not been called previously, then a server call would have been made for each element
                // in the loop below.
                foreach (AFElement item in elements)
                {
                    attrList.Add(item.Attributes["Water Flow"]);
                }

                AFValues values = attrList.GetValue();

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

                startIndex += pageSize;
            } while (startIndex < totalCount);
        }
Ejemplo n.º 7
0
        public override void Run()
        {
            try
            {

                var connection = new AfConnectionMgr(Server, Database);
                connection.Connect();

                AFDatabase database = connection.GetDatabase();

                var afObject = AFObject.FindObject(AttributePath, database);

                var separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;

                if (afObject is AFAttribute)
                {
                    var attribute = (AFAttribute)afObject;
                    AFValue value = attribute.GetValue();
                    Console.WriteLine("{0}{1}{2}{3}{4}", GetStringValue(value), separator, value.Timestamp,separator, attribute.Name);
                }

                if (afObject is AFElement)
                {

                    var element = (AFElement)afObject;

                    // the attibute list object allows a single GetValue() call for all attributes at same time.
                    // We call this a "Bulk Call"
                    var attributes = new AFAttributeList(element.Attributes);
                    var values=attributes.GetValue();

                    // prints the results
                    values.ForEach((afvalue)=> Console.WriteLine("{0}{1}{2}{3}{4}", GetStringValue(afvalue),separator, afvalue.Timestamp,separator,afvalue.Attribute.Name));
                }

            }

            catch (Exception ex)
            {
                this.Logger.Error(ex);
            }
        }