Author Topic: Copy context references  (Read 12967 times)

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Copy context references
« on: June 11, 2014, 11:22:56 pm »
Hello everyone,

I've looked everywhere but I can't find any info on how to copy context references from one usecase to another in C#

Any idea ?
« Last Edit: June 11, 2014, 11:23:12 pm by Jeremie0 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #1 on: June 12, 2014, 01:01:29 am »
What do you mean by "context references"?

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #2 on: June 12, 2014, 06:16:18 pm »
the actors and systems related to the steps of a scenario

like in the screenshot

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #3 on: June 12, 2014, 06:35:28 pm »
Those are just a summary of elements you find when scanning the connectors collection. So if you create connectors for the copied use case you will automatically find the references.

q.
« Last Edit: June 12, 2014, 06:36:21 pm by qwerty »

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #4 on: June 12, 2014, 06:51:32 pm »
i'm sorry i don't get it...

i've created an element and copied the scenario from the source element to the new one

how do you get "actor" and "CS" for example ?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #5 on: June 12, 2014, 07:31:06 pm »
Have a look at the connectors of the source use case. Just copy these connectors and you will see the Context References as well in the copy.

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #6 on: June 12, 2014, 07:59:23 pm »
i get an error everytime i try to add a connector

Code: [Select]
foreach (EA.Connector ct in cts)
                                        {
                                            EA.Element tmp = Repository.GetElementByID(ct.ClientID);
                                                ctstarget = ctstarget.AddNew(tmp.Name, ct.Type);
                                        }

and when i do the following, it works but no context references appear in the scenario
Code: [Select]
foreach (EA.Connector ct in cts)
                                        {
                                            EA.Element tmp = Repository.GetElementByID(ct.ClientID);
                                            EA.Connector con = ctstarget.AddNew(tmp.Name, ct.Type);
                                            //con.Update();
                                        }
« Last Edit: June 12, 2014, 08:19:00 pm by Jeremie0 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #7 on: June 12, 2014, 09:10:51 pm »
As long as you comment the Update you will not create a connector.

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #8 on: June 13, 2014, 06:00:46 pm »
that's precisely where the problem is.

With the update uncommented, everytime i run the addin i get the message
"An extern component encountered an exception"

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #9 on: June 13, 2014, 08:13:19 pm »
Looking at it a bit more precisely you lack to supply the SupplierID. Maybe you should have a look in my Scripting book.

N.B. The awful indentation makes reading your code not an easy task.

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #10 on: June 13, 2014, 08:49:19 pm »
it still creates an exception :(

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #11 on: June 13, 2014, 08:49:58 pm »
Code: [Select]
foreach (EA.Connector ct in cts)
                                        {
                                            EA.Element tmp = Repository.GetElementByID(ct.ClientID);
                                            EA.Connector con = ctstarget.AddNew(tmp.Name, ct.Type);
                                             con.SupplierID = ct.SupplierID;
                                                           if (!con.Update())
                                            {
                                                MessageBox.Show(con.GetLastError());
                                            }
                                        }

sorry for the double post
« Last Edit: June 13, 2014, 08:51:22 pm by Jeremie0 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #12 on: June 13, 2014, 09:07:50 pm »
Your code lacks quite some essentials.

Code: [Select]
useCaseOrg = Repository.GetElementByID(orgID);
useCaseCopy = package.Elements.AddNew(useCaseOrg.Name, "UseCase");
useCaseCopy.Update();
for (EA.Connector con in useCaseOrg.connectors) {
  EA.Connector conCopy = useCaseCopy.Connectors.AddNew (con.name, con.type);
  conCopy.supplierID = con.SupplierID;
  conCopy.Update();
}

I wrote this out of my head with no testing. But it should point you in the right direction.

q.
« Last Edit: June 13, 2014, 09:09:10 pm by qwerty »

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #13 on: June 13, 2014, 10:02:28 pm »
thanks but that's what i wrote already...

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #14 on: June 13, 2014, 10:18:27 pm »
Too bad I'm not given clairvoyance. So I'm out.

q.