Book a Demo

Author Topic: How to duplicate a package using Repository object  (Read 5499 times)

Fabio Riera

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
How to duplicate a package using Repository object
« on: July 10, 2013, 11:06:17 pm »
Hi there,

I'm creating an add-in for EA. One of my tasks is to duplicate a package (ctrl-C & ctrl-V) in project browser. How I do this task using the Repository object? The package to be duplicated is the object in context. Thanks in advance.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to duplicate a package using Repository ob
« Reply #1 on: July 10, 2013, 11:11:41 pm »
Check the package.clone method.

q,

Fabio Riera

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: How to duplicate a package using Repository ob
« Reply #2 on: July 10, 2013, 11:16:57 pm »
Thanks! And how I move the cloned package to another package? By changing its ParentID?

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: How to duplicate a package using Repository ob
« Reply #3 on: July 10, 2013, 11:26:37 pm »
Hi Fabio,

be aware: It may be no problem to clone a package. But I think this clone don't create new elements as it's content (shallow copy).

So you probably have to recursively dip into the package structure and clone all the elements and packages.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to duplicate a package using Repository ob
« Reply #4 on: July 10, 2013, 11:52:49 pm »
I'm pretty sure it does, package.Clone has often been suggested as the solution to copying elements, but it would be nice to get a confirmation.

Geert
« Last Edit: July 10, 2013, 11:54:23 pm by Geert.Bellekens »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to duplicate a package using Repository ob
« Reply #5 on: July 11, 2013, 12:18:10 am »
I just tried it. clone works recursively.

q.

Fabio Riera

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: How to duplicate a package using Repository ob
« Reply #6 on: July 11, 2013, 03:12:10 am »
Hello,

I'm trying with this code:

            const int SOURCE_PACKAGE_ID = 227375;
            Package pckSource = MyRepository.GetPackageByID(SOURCE_PACKAGE_ID);
            Package pckClon = pckSource.Clone();

But pckClon is always null.

What I'm doing wrong?
« Last Edit: July 11, 2013, 03:14:39 am by fabioriera »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to duplicate a package using Repository ob
« Reply #7 on: July 11, 2013, 05:19:57 am »
I tried it with VB and it works. You're missing an update at the end.

Maybe it's a security issue? Have you turned on security?

q.