Author Topic: Acces to Tagged Value "ImplementsGuid" failed  (Read 6454 times)

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Acces to Tagged Value "ImplementsGuid" failed
« on: November 28, 2008, 01:32:06 am »
When I try to get acces to the Tagged Value "ImplementsGuid" of an operation which implements another one of an interface which is connected through a realization, the acces via Automation Interface with C# fails.

It fails with exception:
S Y S T E M   E X C E P T I O N   # 1:   "Action is not supported"   C A U S E D   B Y :   System.Object GetByName(System.String)      

This is my
Code: [Select]
     
EA.Element localElement = element;
EA.Collection localOperations = localElement.Methods;
   /* Loops through all operations of the local element... */
   for (short i = 0; i < localOperations.Count; i++)
   {
      EA.Method tempLocalOperation = (EA.Method)ocalOperations.GetAt(i);
     EA.TaggedValue taggedValueLocalOperation;
      object objectLocalOperation;

      try /* Get value of ImplementsGuid of Tagged Values */
      {
         objectLocalOperation = tempLocalOperation.TaggedValues.GetByName("ImplementsGuid");
        taggedValueLocalOperation = (EA.TaggedValue)  bjectLocalOperation;
     }
      catch(Exception e)
      {
         output.writeSystemException(e);
         break;
      }
      string guidLocalOperation = taggedValueLocalOperation.Value;
}

In another application I got acess to Tagged Values in the same way, the only difference is that I got acces to an EA.Element and now I try it with an EA.Method.

Could somebody tell me why this fails and could maybe post a solution for my problem?

Thanks for your help!  :)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #1 on: November 28, 2008, 04:54:14 am »
Methods work a bit differently than other EA entities. [I am trying to avoid confusion with the terms "element" or "object" since whether the context is UML or EA could be confusing here.]

Try casting to MethodTag instead of TaggedValues, even though you are using the TaggedValues collection of a Method. I think you'll be OK then.

Note that similar situations apply to: attributes and the AttributeTag type; and connectors and the ConnectorTag type.

HTH, David

Your code should work just fine for most other EA entities, at least for elements and packages.
No, you can't have it!

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #2 on: November 28, 2008, 05:03:50 pm »
Thank you for your information, I have changed the cast but the exception occurs although  :o. When I debug until the exception occurs it occurs at the following line:

Code: [Select]
objectLocalOperation = tempLocalOperation.TaggedValues.GetByName("ImplementsGuid");

It is very strange because in the debugging I can see that there are three Tagged Values available, but I have no chance to get access to them, wether by name neither by number!  :-/

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Acces to Tagged Value
« Reply #3 on: November 28, 2008, 11:43:48 pm »
Did you explicitly type the variable you are setting?

You should have something like:

EA.MethodTag taggedValueLocalOperation;

Then the line you've posted immediately above should work.

[edit]Or not...
Remember to cast the result to EA.MethodTag as well. I think GetByName has a return type of object.[/edit]
« Last Edit: November 28, 2008, 11:45:32 pm by Midnight »
No, you can't have it!

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #4 on: November 29, 2008, 12:01:07 am »
Yes, I have all this done but it didn't work.... :-/ To be shure that I didn't misunderstood you here is my whole function:

Code: [Select]

        public void adjustOperations(EA.Element localElement)
        {
            EA.Collection localOperations = localElement.Methods;
            /* Loops through all operations of the local element... */
            for (short i = 0; i < localOperations.Count; i++)
            {
                EA.Method tempLocalOperation = (EA.Method)localOperations.GetAt(i);
                EA.MethodTag taggedValueLocalOperation = null;
                object objectLocalOperation = null;
                string guidLocalOperation = null;

                try /* Try to get Value of ImplementsGuid of Tagged Values */
                {
                    objectLocalOperation = tempLocalOperation.TaggedValues.GetByName("ImplementsGuid");
                    taggedValueLocalOperation = (EA.MethodTag)objectLocalOperation;
                }
                catch(Exception e)
                {
                    /* Display exception */
                    output.writeSystemException(e);
                    break;
                }

                /* ImplementsGuid in Tagged Values available */
                if (null != taggedValueLocalOperation)
                {
                    guidLocalOperation = taggedValueLocalOperation.Value;
                }
                /* No ImplementsGuid in Tagged Values available */
                else
                {
                    output.writeHeading("E R R O R :   No \"ImplementsGuid\" in Tagged Values available!");
                    break;
                }

                /* ...and through all of the parent element... */
                for (short j = 0; j < parentOperations.Count; j++)
                {
                    EA.Method tempParentOperation = (EA.Method)parentOperations.GetAt(j);
                    /* ...compares both operations... */
                    if (guidLocalOperation == tempParentOperation.MethodGUID)
                    {
                        /* ... and adjust the child operation if necessary */
                        if (tempLocalOperation.Name != tempParentOperation.Name)
                        {
                            tempLocalOperation.Name = tempParentOperation.Name;
                            tempLocalOperation.Update();
                            operationsCount++;
                        }
                    }
                }
            }
        }

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #5 on: November 30, 2008, 04:06:16 am »
What is the exception now, and which line causes it?
No, you can't have it!

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #6 on: December 01, 2008, 06:16:06 pm »
That is the following exception:
"Action is not supported"   caused by   "System.Object GetByName(System.String)"

This exception is caused by the following line:
Code: [Select]
objectLocalOperation = tempLocalOperation.TaggedValues.GetByName("ImplementsGuid");

I´m despairing of this problem :-[, so thanks a lot for your help! :)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #7 on: December 01, 2008, 10:12:34 pm »
I am guessing here, but...

First, I wonder if there is a TaggedValues collection there at all. Yes, I know the documentation says there is, but perhaps it is actually a MethodTags (or something) collection. Use Object Browser or something to check this.

Second, at the same time, whatever the collection name is, check to see if there is a GetByName method on this collection.

Last (of the three things I can think of), check that the value you are passing is what EA really wants to see. I don't usually retrieve Tagged Values by name, so I don't remember if there are any quirks in how the name should be formatted. [I really don't think there are any, but something is causing the error.] Throw together a 'normal' model fragment where a class (or some other entity) has a tagged value (not a MethodTag) and see if you can call it by name. Remember that tagged value names are case sensitive. Do you get an error?

If none of these work, send an email to Sparx Support pronto. Perhaps it is a bug, or the documentation is missing something. Remember that Sparx is in the Land of AUS, so give them time to read and answer. If you send the note today (your time) you might even have a reply by start of business tomorrow.

If any of these work, or Sparx comes back with something please post back and let us know.

David
No, you can't have it!

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #8 on: December 01, 2008, 11:33:57 pm »
1. -> There is a tagged value collection, when I debug I can see the correct amount of tagged values.

2. -> According to the documentation a method has a Collection of type MethodTag named TaggedValues. And because it is a collection I should have access via GetByName().

3. -> I have got access through GetByName() to TaggedValues of a Requirement without any troubles.

So I will contact Sparx Support and tell you what the results are.  ;)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8064
  • Karma: +118/-20
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #9 on: December 02, 2008, 09:20:02 am »
If you read the documentation for Collection.GetByName you'll see
Quote
Only supported for the following collections: Models, Packages, Elements, Diagrams, TaggedValues.

Although I admit that TaggedValues could do with some clarification, as it is only talking about the Element.TaggedValues collection which is typed as TaggedValue.


dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #10 on: December 02, 2008, 06:38:45 pm »
Thanks for all your help :), the next time I will open my eyes when I am reading the documentation!  ::)

I resolved this issue with replacing the GetByName() through GetAt():

Code: [Select]
/* Loops through all MethodTags of the actual operation */
for (short j = 0; j < tempLocalOperation.TaggedValues.Count; j++)
{
    /* Try to get MethodTag */
    try
    {
        objectLocalOperation = tempLocalOperation.TaggedValues.GetAt(j);
        taggedValueLocalOperation = (EA.MethodTag)objectLocalOperation;
    }
    catch (Exception e)
    {
        /* Display exception e.g. an "Out of Bounds" one */
        output.writeSystemException(e);
        return;
    }

    /* Reference to realizing operation available? */
    if ("ImplementsGuid" == taggedValueLocalOperation.Name)
    {
        break;
    }
    /* Keep in mind that actual no reference is available */
    else
    {
        taggedValueLocalOperation = null;
    }
}

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #11 on: December 02, 2008, 08:14:22 pm »
But why does the MethodTag collection not support GetByName()?

It seems completely arbitrary and inconsistent. Why can't they offer a decent API? All these inconsistencies cost us a lot of time.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #12 on: December 03, 2008, 05:37:29 am »
Quote
But why does the MethodTag collection not support GetByName()?

It seems completely arbitrary and inconsistent. Why can't they offer a decent API? All these inconsistencies cost us a lot of time.
BTW, I think I remember seeing something about this a while ago. Either it was when I ran into this, in which case I reported it as a bug, or it was someone else. In the latter case I would have suggested the user who had the problem be the one reporting the bug, since I would not have the details at hand.

Perhaps either Frank or dagraf (or both) would be kind enough to send in a report.

David
No, you can't have it!

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #13 on: December 03, 2008, 05:39:34 am »
While we're on the topic...

Be sure to use a short (i.e. 16 bit) integer when calling GetAt. Some configurations are fairly tolerant of using a 32-bit integer, but things can go wrong. Missing this can leave you with symptoms that are difficult to diagnose.

David
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Acces to Tagged Value "ImplementsGuid" failed
« Reply #14 on: December 03, 2008, 09:06:59 am »
Quote
Perhaps either Frank or dagraf (or both) would be kind enough to send in a report.

OK, maybe I'll send in a report. But I'm tired of beating my head on a brick wall.

I think the last issue in this context was the total absence of tagged values for operation parameters in the automation interface. This was discussed here, and reports were sent, but nothing came of it. And then the fact that you can define tagged values in profiles, include them into MDG technologies, but have no way to synchronize them afterwards. This is not just a bug, but an outrage, and it has been discussed here and reports have been sent, but Sparx has not reacted to this for more than half a year.

I'm using MDG technologies and the automation interface when it cannot be avoided, but not any further. As far as I'm concerned all these little patches coming with every release won't do in the long run. Either they redesign all this in a consistent way or they can stick it up their ... ears.