11 Replies Latest reply on Jul 14, 2015 4:47 PM by bshang

    Add New methods in AF Wrapper (PI ProcessBook)

    PabloMatia

      Somebody can explain how can I add new methods in the AFWrapper library?

      That, can I invoke from PI ProcessBook

       

      Thank you very much

       

      regards

       

      Pablo

        • Re: Add New methods in AF Wrapper (PI ProcessBook)
          bshang

          Hi Pablo,

           

          This thread provides an example of a method that was added to the AFWrapper class.

          VBA AF Wrapper Extension GetValueByTime for Processbook

           

          You'll need to re-compile, deploy, and run regasm on the new DLL after the new methods are added, similar to the steps described in the AFWrapper readme. Let me us know if you have any issues.

            • Re: Add New methods in AF Wrapper (PI ProcessBook)
              PabloMatia

              Barry

              Thank you very much.

               

              I was very useful, but i can’t compile the new version.

              I have VS 2010.

              When I build the project, it finds these errors:

               

              Error    1          The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)  C:\Users\Y\AppData\Local\Temporary Projects\ClassLibrary1\AFWrapper1.cs    26        14            AFWrapper1

              Error    2          The type or namespace name 'OSIsoft' could not be found (are you missing a using directive or an assembly reference?)  C:\Users\Y\AppData\Local\Temporary Projects\ClassLibrary1\AFWrapper1.cs    28        7            AFWrapper1

              Error    3          The type or namespace name 'OSIsoft' could not be found (are you missing a using directive or an assembly reference?)  C:\Users\Y\AppData\Local\Temporary Projects\ClassLibrary1\AFWrapper1.cs    29        7            AFWrapper1

              Error    4          The type or namespace name 'AFElement' could not be found (are you missing a using directive or an assembly reference?)  C:\Users\Y\AppData\Local\Temporary Projects\ClassLibrary1\AFWrapper1.cs    47        17            AFWrapper1

               

               

              The first file is my solution explorer:

               

              The other one is the application properties

               

              Do you know which one is the problem?

               

              Thanks in advance.

               

              Pablo

                • Re: Add New methods in AF Wrapper (PI ProcessBook)
                  bshang

                  Hi Pablo, are you using any LINQ methods? If so, target framework should be 3.5+. Do you have the appropriate "using" directives in the AFWrapper class? Can you paste the beginning of the code here to share and/or the VS project file contents?

                    • Re: Add New methods in AF Wrapper (PI ProcessBook)
                      PabloMatia

                      Barry

                       

                      I’m not using LINQ methods.

                       

                      The beginning of the class is:

                       

                      using System;

                      using System.Collections.Generic;

                      using System.Linq;

                      using System.Text;

                      using OSIsoft.AF;

                      using OSIsoft.AF.Asset;

                      using System.Runtime.InteropServices;

                       

                       

                      And I added these two methods

                       

                      1

                      // Gets the attributes that has the category "CategoryName"

                              [ComVisible(true)]

                              public string[] GetAttributesByCategory(string fullElementPath, string categoryName)

                              {

                                  AFElement element = GetElement(fullElementPath);

                                  int i = 0;

                                  string[] result = new string[element.Attributes.Count];

                                  foreach (AFAttribute attributo in element.Attributes)

                       

                                  {

                                      foreach (AFCategory categoria in attributo.Categories)

                                      {

                                          if (categoria.Name == categoryName)

                                              result[i++] = attributo.Name;

                                      }

                                  }

                                  return result;

                              }

                       

                      2

                       

                        //gets child Elements from element by category

                              [ComVisible(true)]

                              public string[] GetChildElementsByCategory(string fullElementPath, string categoryName)

                              {

                                  AFElement element = GetElement(fullElementPath);

                                  int i = 0;

                                  string[] result = new string[element.Elements.Count];

                                  foreach (AFElement elemento in element.Elements)

                                  {

                                      foreach (AFCategory categoria in elemento.Categories)

                                      {

                                          if (categoria.Name == categoryName)

                                              result[i++] = elemento.Name;

                                      }

                                  }

                                  return result;

                              }

                       

                      I believe that these functions may be useful to complete the "ProcessBook" screen, taking into account the person who opens it

                       

                      The attached file is the .cs file.

                       

                      Regards

                       

                      Pablo