Book a Demo

Author Topic: RefactorEA  (Read 22058 times)

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • "There is no I in Team America"
    • View Profile
RefactorEA
« Reply #15 on: June 01, 2009, 09:23:30 am »
Hi Midnight ...

Thanks for checking it out man.
Just been a bit lazy ... yes the dll and the source are out of sync ...

I was thinking "ah! do it later! no-one's going to look at the code anyways..."
...imagine my surprise...

Thanks heaps for looking at the code...I'll be keeping them in sync now...

Best!
Neo
« Last Edit: June 01, 2009, 10:12:09 am by simon.leserve »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: RefactorEA
« Reply #16 on: June 01, 2009, 09:59:59 pm »
And a new version once again. You have been busy!
No, you can't have it!

cube1us

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: RefactorEA
« Reply #17 on: June 01, 2009, 11:41:32 pm »
> Hey Cube,

> Thanks tonnes for the feadback!

You are most welcome.  Thanks tonnes for your efforts!!

> The bug has been fixed.
> Merge Elements can now be selected from the Diagram Context Menu too...like you suggested.

Wow. Cool.  We'll give it a try today.

> Only thing is I couldn't figure out how to determine the last selected > element from a set...(I'll try and figure this out...but for now you'll just see a dialog box asking which of the two elements (haven't included functionality for more than two) will serve as the target.)

I have no ideas for you on that one, unfortunately.  But that dialog box could be a good place to put warnings (see below).

> The bug was actually really bad. The logic entirely disregarded the > possibility of a connection between the source and target (or vice-?> versa). Anyway, what I decided to do is leave connections between > the source and target unmodified altogether (What do you think?)

I think that would be unusual in any legitimate merge.  Leaving any that do exist along, is probably safest.

> Oh yeh...I was going to ask you what you thought the best creteria > for "Sufficiently Similar" should be (i.e. to allow merging between two elements)? I initially thought it should be:

> 1. Same Stereotype
> 2. Same EA.Element.Type
> 3. Source and Target IDs differ

> Then, I found I needed to really merge two elements that had separate stereotypes. Do you think it's necessary to consider stereotype at all? (it could be made optional.)

Suggest that these could just produce warnings.  In the case of differing element types, that could end up creating "syntactically" incorrect UML, I suppose.  The Stereotype probably should not matter at all (though a warning might be a good idea there, too).  If the GUIDs of the source and target are the same, I recommend throwing out an error dialog box.

> If you think of any other criteria we can put that in place.

> I'm getting good test results accross all diagrams in which the elements participate ...

> Thanks again for your anlysis, and support!

And thanks again for all you have done.

> Best,
> Neo


> The latest version (RefactorEA v1.2.3) is posted at http://neocortex.net.au/ComputerScience/Projects.aspx

> P.S. you'll have no trouble compiling and running the source from C# Express

Great!!

JRJ Cube

cube1us

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: RefactorEA
« Reply #18 on: June 02, 2009, 07:02:32 am »
I did some testing with 1.3.5.

When I went to do the merge, both elements showed up identically (as EA.ElementClass ) -- the name did not appear, so I was unable to tell which element was which.

I also had intermittent issues with the project failing the Sparx-provided integrity check after some merges.

Thanks again -- and hope this helps.

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • "There is no I in Team America"
    • View Profile
RefactorEA
« Reply #19 on: June 02, 2009, 08:58:42 am »
Thanks a lot Cube, Midnight, ...

Cube:
I'm planning to put some comprehensive unit testing in place before the next major release. It didn't occur to me before but now I'll definitely be including project-integrity-checking in that unit-testing.

There'll be a few minor releases before the next major release. And I'm working on some documentation also.

Thanks again Cube. The feedback is invaluable.

Midnight:
Thanks heaps for the encouragement!
I was wondering if you had found any bugs?
I was also wondering if you had found the source code useful?

Best,
Neo

« Last Edit: June 02, 2009, 09:08:54 am by simon.leserve »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: RefactorEA
« Reply #20 on: June 03, 2009, 09:31:29 am »
Quote
Only thing is I couldn't figure out how to determine the last selected element from a set...(I'll try and figure this out...but for now you'll just see a dialog box asking which of the two elements (haven't included functionality for more than two) will serve as the target.)
You should be able to use Repository.GetContextObject () along with Repository.GetContextItemType () to get consistent behavior with EA for this type of action.

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Re: RefactorEA
« Reply #21 on: June 03, 2009, 06:32:56 pm »
well...it seems not to be working for 7.5.845.
I'll try to debug later.
Recursion definition:
If you don’t understand the definition read "Recursion definition".

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Re: RefactorEA
« Reply #22 on: June 03, 2009, 06:50:38 pm »
It seems the problem is with the instalation...
Recursion definition:
If you don’t understand the definition read "Recursion definition".

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • "There is no I in Team America"
    • View Profile
RefactorEA
« Reply #23 on: June 03, 2009, 09:59:47 pm »
Hi Simon, Martin,

Simon:
Thanks for the pointers...it worked!
I gave it a shot and I got a real object instance from Repository.GetContextObject () but it would not cast to EA.Element (or EA.DiagramElement) even when the return value for Repository.GetContextItemType () is EA.ObjectType.otElement ...

So guess what! ... yep, Repository.GetContextItem(out obj) did the trick ... but you were just testing us right?
Thanks heaps Simon!

Martin:
Thanks tonnes for giving RefactorEA a try. And thanks also for the bug feedback.

Is it possible to try running the installation a couple of more times. Try uninstalling also before installing. If it continues to fail I'd immensely appreciate the opportunity to solve the bug with your help. I'm running EA 7.5.845 and it runs ok for me...It's possible that the problem is the failure to create a registry key if EA has been installed for the current user only. Thanks again Martin!

Best,
Neo
« Last Edit: June 04, 2009, 06:58:36 am by simon.leserve »

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Re: RefactorEA
« Reply #24 on: June 04, 2009, 02:56:34 am »
1) Thanks you, you did the service for all of us.
2) I'll check it and if I find a bug I'll solve it and give you the fix
3) In my company we are considering to use it, so if we do ans we find bugs we'll solve it and post the fixes through you.
Recursion definition:
If you don’t understand the definition read "Recursion definition".

cube1us

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: RefactorEA
« Reply #25 on: June 04, 2009, 04:02:26 am »
I saw that 1.3.6 was out there, so I tested again.

The test setup is:  
EA 7.1.831
Built in Access EAP file
Deployment Diagram
Node1  (dependency) -> Node3A
Node2  (dependency) -> Node 3b
Node Merged exists, but has no relationships to or from that node.

If I select Node3A, then Node Merged (the latter being the target) graphically, and then right click, AddIns, Refactor, Merge, I get a dialog box indicating that one cannot merge an element onto itself.

If I select node3A as the target (has the extra hashed border around it), and do the merge, it succeeds, but of course there is no visible effect, as the source had no relationships.

If I do it with a relationship, I get a "save" dialog box, and the model fails an integrity check.

Similarly, if using the project browser I do

Merge from Node3A to Merged:  OK  (merged now has one reference)
Merge from Node3B to Merged:  OK  (merged now has to references)
Merge from Merged to Node3B:  OK  (merged has no more references, as they moved to Node3B)
Create a dependency from Node3A to Merged
Merge from Merged to Node 3B:  I get a save dialog, and model fails the dependency check (these two events seem to correlate 100%)

Hope that helps, and thanks again for your efforts.


UPDATE:  I printed off the code for MergeElements.cs and *may* see the issue there.  The sequence in MergeFromDiagramContext() is something like:

...
try {
   ...
   _target - (EA.Element)obj;
}
...
EA.Element A = _repository.GetElementByID(...);
EA.Element B = _repository.GetElementByID(...);
if(_target != null) {
   if(_target ==A)
      _source = B;
   else
      _source = A;
}

I think that the trouble is that the first setting of _target sets it to a reference to an object which is *neither* A nor B -- that is, the references are different.  The object referred to by _target presumably has the same EA ElementID as one of A or B, but is not the same C# object (pointer) as either of them.  (Disclaimer:  I have never written C#:  I am applying my extensive C/C++/Java background to this, and assuming C# works basically the same way).

So, instead, you would need this:

if(_target != null) {
   if(_target.ElementID == A.ElementID) {
      _source = B;
   }
   else
      _source = A;
}

(PS:  If no elements at all are selected, there is no error message, nor does it show the select dialog.    I was unable to find a way to get the SelectTarget dialog to come up).

Hope that helps even more.    ;)

SECOND UPDATE:  In looking at MergeConnectors() I think I see something that *may* be an issue that could cause the integrity check issue I reported (disclaimer:  I have not explored the EA API reference in detail -- it may be that given how DeleteAt() works this code is perfectly good).

The code has a loop going thru all of the connectors on the source element, and as it finds one, it moves one end to the target, and then deletes it.  While it is doing that, it is changing things out from underneath itself -- which you clearly recognized (see the DeleteAT() method call) and then decrementing the loop counter so as to reproces an entry.  That feels dangerous to me.   At the least, it seems likely that it will reprocess all of the new connectors (hopefully the code that checks for a matching ElementID would cause them to be ignored).  Anyway, if there is a problem here (I'm not sure),  I see two safer alternatives.  One might be to build an array of all of the "old" connectors before changing any of them -- and then go back and delete the connectors later.  The other would be to restart the loop from the beginning after each change.

The other thing I found myself wondering about was whether or not it was enough for the new connector to have just a ClientID and a SupplierID or if there was maybe some other critical property that needed to be set.

Hope that maybe helps some more.   ;)
« Last Edit: June 04, 2009, 05:20:15 am by cube »

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • "There is no I in Team America"
    • View Profile
Re: RefactorEA
« Reply #26 on: June 04, 2009, 07:33:25 am »
Hi Martin, Cube,

Thanks a Trillion to you both!
Oh, sorry...I got the units-of-measurement for Dollars and Thanks confused. I meant to say: Thanks a Million!

Martin:
This is an open source project...and so a partnership like yours would be immensely appreciated. Perhaps we can move to Source Forge as a source repository or something...what do you think?

Cube:
Thanks again...this analysis is awesome...
I'm hoping to get a chance to go through it thoroughly tonight.
I'll be in touch soon.

Thanks again!

Best,
Neo
« Last Edit: June 04, 2009, 07:36:27 am by simon.leserve »

cube1us

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: RefactorEA
« Reply #27 on: June 06, 2009, 06:28:37 am »
In looking at the object model and the code for doing the "heavy lifting" with the connector, I wonder if a better approach might be to just change whichever end needs changing, rather than creating a new connector.  There are just soooo many attributes that would need to be copied over to the new connector.

It might be a simple matter of looping thru each connector, and for each case where the ClientID or SupplerID (but skip self-references?)  matched the merge "source" change it to the merge "target" -- no new connector at all, and no deleting.

Have a good weekend -- maybe I'll get some time to load this thing up on my machine at home and try out my theories.

Neocortex

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
  • "There is no I in Team America"
    • View Profile
Re: RefactorEA
« Reply #28 on: June 06, 2009, 11:13:32 am »
That's a great idea Cube...and I think you're right ... the way I did was pretty silly now you come to mention it ...

Anyway, I'm finally going to get stuck into some code today...
If you happen to be working on it now though let me Know ... I'll do something else.

... I'm sure I've got the bloody swine flu ... feel like I've been hit in the head with a brick ... (no I didn't drink anything last night) ...
« Last Edit: June 06, 2009, 11:14:17 am by simon.leserve »

cube1us

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: RefactorEA
« Reply #29 on: June 08, 2009, 11:32:33 pm »
I did not manage to get to it over the weekend, unfortunately.  I may take a leap of faith and throw C# on my work machine after taking a system state backup (I have old old VC++ 6.0  and VB 6.0 installed).

Sorry you haven't been feeling well.  Hopefully it isn't really influenza.