Book a Demo

Author Topic: problem after updating value of an attribute  (Read 5378 times)

Simon Hackfort

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
problem after updating value of an attribute
« on: March 12, 2008, 08:31:08 pm »
Sorry for this new thread, but I did not find any explanation by using the search. So I coded an Addin in C# which accesses to the EA repository, there I go though the packages and change all value of the Version attribute and invoke the update method. I will get a true return value and if I call my method twice I see in debug mode the correct changed version value in each package. Now I close my Addin and return into the resource view of EA and select a package and look at the property view. There the old value of the version attribute will be display. Here my code which sets the value:

Quote
public static void SetVersionInPackage( EA.Repository myRepository, int pid, string version)
        {
            EA.Package p = myRepository.GetPackageByID(pid);
            p.Version = version;

            if (p.Update() == false)
                Console.WriteLine(p.GetLastError());
        }

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: problem after updating value of an attribute
« Reply #1 on: March 12, 2008, 10:29:32 pm »
Hi Simon,

It sounds like you've got both your automation project and the EA desktop running concurrently. If so, you've got to refresh the copy on the desktop.

If your automation project is an external program then you need to (at least) reload the diagram on the EA desktop. Try right-clicking the diagram tab and choosing to reload. Or you can reload the project from the main menu with File | Reload Current Project. [Or use the control-shift-F11 shortcut.]

If you have an add-in running 'inside' your EA session, look at the various Reloadxxx and Refreshxxx methods of the Repository class.

HTH, David
No, you can't have it!

Simon Hackfort

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: problem after updating value of an attribute
« Reply #2 on: March 12, 2008, 10:49:31 pm »
well, my Addin is an interal one, I open my example eap file with some standard models and packages and invoke my addon by choosing it in the menu. In a custom dialog of my addin you can enter a versionnumber in a textbox, on a button I added a click event which go through all packages from the repository of the current EA session and set the value of version attribute and finish it with update. In my EA I don't have any open views or element, after I close my addin, I look at the resource tree property window. What kind of invoke do I have to use to sync the changed contents in the repository object and the application EA?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: problem after updating value of an attribute
« Reply #3 on: March 12, 2008, 11:07:36 pm »
Simon,

Probably - but I'm not sure since I cannot see your code or model from here - you would call Repository.RefreshModelView with the root package ID.

You could also - when the add-in has finished its work - use the main menu as I mentioned earlier.

Of course if you have any diagrams open you might have to refresh them - see the other methods I pointed you at.

Here's an interesting experiment that I have not tried. If you had an open diagram with a selected element, and if the tagged values (for example) window were open, would the tagged values be refreshed when you refreshed the diagram? You could test this by adding a new tagged value (or modifying the value of one that's already there) and then doing the refresh.

David
No, you can't have it!

Simon Hackfort

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: problem after updating value of an attribute
« Reply #4 on: March 12, 2008, 11:33:30 pm »
Hi David,

I cannot publish the whole source but I will try to explain the parts. First I implement this one to tranfer the repository reference to my form.
Quote
if (myVersionForm == null)
                    myVersionForm = new VersionForm();
                    myVersionForm.SetRepository(Repository);
                    myVersionForm.ShowDialog();
To separate my utility methods to get all packages etc. from the repository I put them all into a own class file. The invoke in the form will be GetaAllEAPackages(myRepository, ref myEAPackages); for example, the parameter myEAPackages is a kind of List<> were I put all packages object which will be found by my GetaAllEAPackages method.
Quote
public static void GetaAllEAPackages(EA.Repository myRepository, ref List<EA.Package> myEAPackages)
        {
            foreach (EA.Package eamodel in myRepository.Models)
            {
                foreach (EA.Package eapackage in eamodel.Packages)
                {
                    myEAPackages.Add(eapackage);

                    EALibrary.GetEAPackages(eapackage, ref myEAPackages);
                }
            }
In this method I make a recursive invoke to get all packages which are in a package. After this I will get finally a filled list with all packages. After that I invoke my SetVersionInPackage method see post one. I tried to do this at the end, but the value won't change in the EA itself :(
Quote
 foreach (EA.Package p in myRepository.Models)
            {
                myRepository.RefreshModelView(p.PackageID);
            }

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: problem after updating value of an attribute
« Reply #5 on: March 13, 2008, 12:28:37 am »
It really sounds like you are somehow saving the 'old' version of the model over the changed one. This could happen if your UI thread (on the desktop) wrote to the underlying schema after your add-in.

As I said before, it is impossible for me to diagnose this from afar.

Please reread both my earlier posts, and see if you need to use the other repository methods.

As a quick test, see if you can exit EA entirely from your add-in. Then reopen the model and see if the values were written to the database. If not, then try running a concurrent process that reads the database after you change the version numbers and call Update, but before you go back to the UI. [You could write a separate program - that does not reference EA, but opens the database with OLEDB through the Jet (or your DBMS) provider - or use MS Access in read-only mode (remember to open the database in shared mode).]

The above should give you the clues you need.

David
No, you can't have it!

Simon Hackfort

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: problem after updating value of an attribute
« Reply #6 on: March 14, 2008, 12:05:20 am »
Hi David,

today I did some tests with a friend an his example in VB. There we set the value of version property live in the debugger and made a print out of the value to check for successfully invoked update method. All was fine, but we look in the EA application and there was the old value like with my Addin. After that we try to set another value in another attribute like notes. And the result was that it work perfectly with my code and the code of the VB script. So it seems that there is a little issue with the synchronization of version attribute. I think I will contact the EA support for help.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: problem after updating value of an attribute
« Reply #7 on: March 14, 2008, 01:52:08 am »
Quote
...
So it seems that there is a little issue with the synchronization of version attribute. I think I will contact the EA support for help.
That sounds like the right course of action to me. From what you write it sounds like this is an isolated fault.

You seem to have been doing everything else correctly.

Please post back to tell us what Sparx has to say on the issue.

David
No, you can't have it!