Author Topic: Copy context references  (Read 12986 times)

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #15 on: June 13, 2014, 11:43:28 pm »
the code was missing the following instruction

Code: [Select]
conCopy.ClientID = con.ClientID;
now the error is gone, but still no context references in the new scenario

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #16 on: June 14, 2014, 12:40:09 am »
This is because you do not create the source and client id correctly. When you're done you will see that the connectors for the new UC are not the same as that of the original one. It needs some additional if-then-else to create the connectors correctly. Try using your brain.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #17 on: June 14, 2014, 12:42:43 am »
Code: [Select]
my $e = $rep->GetTreeSelectedObject();
my $pk = $rep->GetPackageByID ($e->PackageID);
my $uc2 = $pk->Elements->AddNew ($e->Name . "2" , $e->Type);
$uc2->Update();
for my $con (in $e->Connectors) {
  my $con2 = $uc2->Connectors->AddNew ($con->Name, $con->Type);
  $con2->{SupplierID} = $con->SupplierID;
  $con2->Update();
}
works for connectors drawn from UC to other elements, but not vice versa.

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #18 on: June 14, 2014, 01:00:03 am »
i basically have the same code, at least i think

Code: [Select]
EA.Diagram diagram = Repository.GetDiagramByID(droppedID);
EA.Package element2 = Repository.GetPackageByID(diagram.PackageID);

EA.Element a = element2.Elements.AddNew(element.Name, element.Type);


a.Name=a.Name.Replace(a.Name, a.Name + "_tmp");
element2.Elements.Refresh();
a.Update();
                                

EA.Collection targets = a.Scenarios;
 foreach (Scenario source in element.Scenarios)
                                {
                                    EA.Scenario target = targets.AddNew(source.Name, source.Type); //on cree un nouveau scenario du meme nom
                                    
                                    var form = new Form1();
                                    var checkedListBox1 = new CheckedListBox();
                                    form.Text = target.Name;

                                    targets.Refresh();
                                    EA.Collection targetsteps = target.Steps;
                                    EA.Collection cts = element.Connectors;
                                    EA.Collection ctstarget = element2.Connectors;
                                    int i = 0;
                                    foreach (ScenarioStep aaa in source.Steps)
                                    {
                                        form.checkedListBox1.Items.Add(aaa.Name);
                                        form.checkedListBox1.SetItemChecked(i, true);
                                        foreach (EA.Connector ct in cts)
                                        {
                                            EA.Connector con = (EA.Connector)ctstarget.AddNew("", ct.Type);
                                            con.SupplierID = ct.SupplierID;
                                            con.ClientID = ct.ClientID;
                                            if(!con.Update())
                                            {
                                                MessageBox.Show(con.GetLastError());
                                            }
                                        }
                                        ctstarget.Refresh();
                                        i++;
                                        element2.Update();
                                    }

anyway thanks for all your help i guess i'll find a workaround
« Last Edit: June 14, 2014, 01:05:53 am by Jeremie0 »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #19 on: June 14, 2014, 07:14:49 am »
You have a similar code but as I pointed out that is not sufficient. Use a debugger to find out why you are not copying the connectors correctly.

q.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #20 on: June 14, 2014, 07:19:14 am »
Furthermore: you are copying the connectors more than once if you have multiple scenarios. Move the connector copy loop outside on the same level as that for the scenarios.

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #21 on: June 26, 2014, 05:39:56 pm »
ok i figured where the problem was.
The supplierID is the elementID of the new element i created, not a copy of the old one

thanks qwerty for your help

Code: [Select]
foreach (EA.Connector ct in element.Connectors)
                                            {// ON CHERCHE A COPIER LES CONTEXT ITEMS, PAS LES CONNECTEURS
                                                EA.Connector con = (EA.Connector) element2.Connectors.AddNew("", ct.Type);
                                                con.ClientID = ct.ClientID; // <-- element2 est un package pas un element, trouver l'acteur id
                                                //string prov = Repository.GetConnectorByID(ct.ClientID).Name;

                                                con.SupplierID = a.ElementID;
                                                //prov = Repository.GetConnectorByID(ct.SupplierID).Name;

                                                try
                                                {
                                                    con.Update();
                                                }
                                                catch(Exception e)
                                                {
                                                    MessageBox.Show(e.Message);
                                                }
                                                    
                                            }

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #22 on: June 26, 2014, 06:06:57 pm »
although it seems like there's a small problem
not all the actors in the context references are copied in the new use case
and i can't figure out why

any idea ?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #23 on: June 26, 2014, 07:41:45 pm »
Compare the Element/Relationships window for the original and the copied use case.

q.

Jeremie0

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Copy context references
« Reply #24 on: June 26, 2014, 11:03:15 pm »
yeah i get it, the assocations in the newly created usecase are those linked to the source usecase in the diagram

so do you have an idea
- to create an association in the new usecase ?
- or just to add the missing ones in the context references ?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Copy context references
« Reply #25 on: June 27, 2014, 04:53:01 am »
What I said formerly: some of the connectors are probably drawn vice versa. So you need to create them on the actor side, not on the use case.

q.