4 Replies Latest reply on Mar 20, 2012 7:15 PM by mhamel

    Exception when using AFAttribute.DataReference

    muwpa

      Hello v-campers ;)

       

      I'm actually working on a PB-Addin that shows in a docking window a AFTreeView. The User can navigate through the TreeNodes to an AFAttribute. To visualize (Trend, Value, SQC,..) a chosen AFAttribute the user has to drag and drop it into the PB display.

       

      In the ItemDrag-Event of the AFTree I build a string containing a visualisazion (e.g. Trend), and the Tag (which is represented by an AFAttribute). To get the Tag name of the AFAttribute I used the following function:

       

       

       
      private string getSelectedAFAttribute(AFTreeNode aftn)
      {
           string tag = string.Empty;
           try
           {
                 AFAttribute afa = (AFAttribute)aftn.AFObject;
                 tag = afa.DataReference.ToString();
           }
           catch (System.Runtime.InteropServices.COMException ex)
           {
                 System.Diagnostics.Debug.WriteLine(ex.Message + " " + ex.StackTrace);
           }
           catch (System.Exception ex)
           {
                 System.Diagnostics.Debug.WriteLine(ex.Message + " " + ex.StackTrace);
           }
                  StringBuilder builder = new StringBuilder();
                  // using StringBuilder to create my "visualization string"
                  return builder;
      }
      

       In the Connect class there is the other part of the drop-handling.The problem occurs in the line

       

       

       
      tag = afa.DataReference.ToString();
      

      In the VS2010 debug output window I get the following error:

       

      "A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in OSIsoft.AF.Asset.DataReference.PIPoint.dll"

       

      That's the reason for the second catch in the code I posted, but this exception is not catched by my catch-statement. Maybe anyone else has/had this problem too. Are there any suggestions to avoid this error?

       

       

       

      Thanks in advance,

       

      Chris

       

       

        • Re: Exception when using AFAttribute.DataReference
          mhamel

          @Christian: This behavior is strange. I tried to reproduce your problem but without success. Could you tell which .NET Framework you are using? Would you share more of your code snippets on how you pass the AFTreeNode object?

           

          Can you validate that when using the PI System Explorer you get obtain values for attributes configured with the PI Point Data Reference on this machine?

            • Re: Exception when using AFAttribute.DataReference
              muwpa

              Hi Mathieu,

               

              I use VS2010 with .NET Framework 3.5 Client Profile, PI SDK 1.4.0, AF SDK 2.0.0

               

              Here are some more snippets..

               

              This is the "ItemDrag" Event which is fired when a user drags an AFAttribute in the AFTreeView and drops into an PB display.

               

               

               
              private void afTreeView_ItemDrag(object sender, ItemDragEventArgs e)
              {
                   try
                   {
                        if (e.Item.GetType().ToString() == "OSIsoft.AF.UI.AFTreeNodeAttribute")
                        {
                            // the function from my last posting
              
                             string tag = getSelectedAFAttribute((AFTreeNode)e.Item);
                             DataObject myDo = new DataObject(DataFormats.Text, tag);
                             DoDragDrop(myDo, DragDropEffects.Copy);
                        }
                        else
                        {
                              MessageBox.Show("Drag and Drop only supported for Attributes.");
                        }
                   }
                   catch (System.Exception ex)
                   {
                       //some output and ex-handling
                    }
              }
              

               And this is the "OnOleDropEventHandler" Drop in the connect class.

               

               

               
              private void Drop(PBDataObject pData, int effect, int x, int y, ref bool canceDefault)
              {
                   try
                   {
                        if (pData.GetData(1) != null && pData.GetData(1).ToString().Contains(LAGPORTAL))
                        {
                            bool isMatch = false;
                            int i = this.app.ActiveDisplay.Symbols.Count;
                            for (i = this.app.ActiveDisplay.Symbols.Count; i > 0; i--)
                            {
                                 Symbol s = (Symbol)this.app.ActiveDisplay.Symbols.Item(i);
                                 // dropped over existing symbol - add content
                                 if (isMatchOnSymbol(s, x, y))
                                 {
                                      handleExistingSymbol(s, pData);
                                      isMatch = true;
                                      break;
                                  }
                            }
                            //create new Symbol - not dropped over existing Symbol
                            if (!isMatch)
                            {
                                 handleNonExistingSymbol(this.app.ActiveDisplay, pData, x, y);
                            }
                         }
                   }
                   catch (System.Exception ex)
                   {
                        // some output and ex-handling
                   }
              }
              

               Hope this helps. Thanks for having a look to this.

               

              Chris

               

               

               

               

                • Re: Exception when using AFAttribute.DataReference
                  MvanderVeeken

                  Maybe it's a long shot, but it's easy to try out: try not using the client profile, but the 'full' .NET 3.5 application.

                   

                  I've seen some weird behavior with the client profile.

                    • Re: Exception when using AFAttribute.DataReference
                      mhamel
                      @Christian: I tried a second time to reproduce your problem but without success. My PB add-in with an embedded AF Treeview responds well to the query of the DataReference.ToString() method. I have tried several combinations of problems or misconfigurations for trying to obtain your type of exception but without success. Conceptually, I don't see any problems in the code snippets you shared. A possible reason that the PI Point Data Reference is not handling properly the ToString method is a corruption of the .dll imported from the PI AF Server. What happen when you try to utilize a PI Point related attribute in PI ProcessBook directly to trend the events over a period of time? What version of PI ProcessBook are you using? Is it a localized version of PI ProcessBook? Can you validate that when using the PI System Explorer you get obtain values for attributes configured with the PI Point Data Reference on this machine? You can also do this former test on another machine.