Book a Demo

Author Topic: Read connector tagged values trough C#  (Read 4655 times)

casper

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Read connector tagged values trough C#
« on: November 04, 2005, 05:48:51 am »
When I'm trying to read all the tagged values of a connector ( source->destination Aggregation) I get the following error while looping through the tagged values.

Code: [Select]

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'EA.TaggedValue'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{EF08950B-949E-435F-84A3-A59E3106C3BF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
  at nHibernateTemplateHelper.Main.GetConnectorTaggedValues(Repository repository, Object param) in D:\nHibernateTemplateHelper\Main.cs:line 107


Code: [Select]

public object GetConnectorTaggedValues(Repository repository, object param)
{
           try
           {

               string[] parameters = (string[])param;
               Connector c = repository.GetConnectorByGuid(parameters[0]);
               if (c.TaggedValues.Count > 0)
               {
                   string result = "";
                   foreach (TaggedValue tv in c.TaggedValues)
                   {
                                result = tv.Name + "=\"" + tv.Value + "\" ";
                   }
                   return result;
               }                
           }
           catch (Exception exc)
           {
               System.Diagnostics.Debug.WriteLine("Somthing went wrong while retrieving the tagged files." + exc);
           }
           return string.Empty;
}


Maybe I'm casting it wrong? or should I try a different approach?

TomO

  • EA Administrator
  • EA User
  • *****
  • Posts: 80
  • Karma: +7/-0
  • EA - Bridging the gap between Business and IT
    • View Profile
    • Sparx Systems
Re: Read connector tagged values trough C#
« Reply #1 on: November 07, 2005, 03:27:49 pm »
Hello Casper

I have only taken a quick look at your code, but the one thing that stands out (as I cant see what you are "using") is the way you have declared your tagged value in the foreach loop.


You have this:

foreach (TaggedValue tv in c.TaggedValues)
    {
       result = tv.Name + "=\"" + tv.Value + "\" ";
    }

Try it with specifying it as an EA type:

foreach (EA.TaggedValue tv in c.TaggedValues)
    {
       result = tv.Name + "=\"" + tv.Value + "\" ";
    }

This may be of no consequence if its included above, but if its not then it may be your answer.


Best Regards.

casper

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Read connector tagged values trough C#
« Reply #2 on: November 07, 2005, 11:55:06 pm »
Hi Tom,

Thanks for the reply, I appreciate the input. Nevertheless, I did use the EA namespace and that’s why the code compiled (If I didn't included the namespace I couldn't compile the code).

Some research in the EA namespace showed that there are several TaggedValue types like TaggedValue, TaggedValueClass and ITaggedValue (not counting IDualTaggedValue). I have tried all of them but all created the cast error.

----------
Update
----------
A colleague of mine has discovered the right class to use. Instead of casting it to a TaggedValue it must be casted to ConnectorTag.
« Last Edit: November 08, 2005, 01:37:09 am by Casper »