2 Replies Latest reply on Sep 7, 2016 7:54 PM by Rick Davin

    Evaluating AF Databases Programatically


      Hey guys,


      I'm working on an AFSDK app that gather information about specific AF Servers / Databases.  I've got a couple things I want to measure, and I'm just wondering the best way to approach these. 


      1) The overall depth of the database: particularly I'm interested if the hierarchy goes just a few branches deep.  I don't need to count every individual branch.  My initial thought was that I could programatically generate the XML output and then parse this using something like XMLReader


      2) Count the number of PI Point data references:  I don't have a great idea on how to approach this one.  Is this information available through "Database Properties"?  I see a stat for "Reference Types" -- is there anything beneath / behind this? 


      3) The number of elements which are based on templates: Manually, I can go to Library > Element Templates > The template in question > General > Find > Elements.  This then returns a list of all the elements.  I could theoretically get a count of this return and loop through this for every template in my AF DB / Server. 


      Any guidance on getting these metrics is appreciated it.  Still pretty new with AFSDK so documentation would be great as well. 



        • Re: Evaluating AF Databases Programatically

          Hi Matt,


          Probably the easiest way to approach this would be to do a recursive search through your database.  I use the skeleton of this function for a bunch of different things so I just slightly modified it to fit the parameters you are asking for.

          Starting from the root you can implement a function like this:


          private void RecursiveSearch(AFElement root, int depth, ref int pipointdrs, ref int templatedElements){
               foreach (AFAttribute a in root.Attributes)    {
                    if (a.DataReferencePlugIn != null && a.DataReferencePlugIn.Name.ToLower().Contains("pi point")){
               foreach (AFElement e in root.Elements){
                    RecursiveSearch(e, depth+1, ref pipointdrs, ref templatedElements);
               if(depth > maxdepth) {
                    maxdepth = depth;
               if(root.Template != null) {


          If you have any questions or need clarification, let me know.

          1 of 1 people found this helpful
          • Re: Evaluating AF Databases Programatically
            Rick Davin

            Hi Matt,


            Some initial thoughts, besides I think its a great idea...


            1.  Generating the XML Output can take a long time on a complex database.  Likewise, walking down the hierarchy could also take a long time, but perhaps not as long as the XML Output.  Plus something doesn't sit well with me to use an external device like XmlReader to read my database hierarchy.  But keep in mind, I always try to use AFSDK to solve my problems first.  You could try loading the entire database into memory, and I have example code I could send you, but again if its a huge or complex database it could take some time.  However, loading everything would make the app faster on items 1, 2, and 3.


            2. Checking the PIPoint data references is also easy enough once you know the magic keys, but you want to count per element template as well as per element for non-templated attributes.  At a shameful plugging of my own blog, see Sometimes its the small things that matter.  Of course that assumes you already loaded your attributes.


            3. The AFSDK has a command for AFElementTemplate.FindInstatiatedElements.


            Other: to also measure in complexity, if the database uses derived templates, has attributes decorated with Traits, or has several references defined, I would bump up the complexity level.

            2 of 2 people found this helpful