currentprincipalchanged does not update all winparts

currentprincipalchanged does not update all winparts

Old forum URL: forums.lhotka.net/forums/t/3926.aspx


Ton Smeets posted on Wednesday, November 21, 2007

Hello,

I worked on this one for a while but I can't find what causes the problem.

Like Project Tracker I am using the winparts to update on principal change. This works fine, but not always. There is a particular situation when I open several winparts, and the last one is RolesEdit. In this case the last winpart I open is a winpart that should close when the user logs out. The winpart closes, and all underlaying winparts update to readonly, except the one that is pushed to the front. this one still remains in write mode.

So, first login and create a new Project, then open in the main menu an existing resource (in a new winpart) and then open admin(roles edit, a new winpart). LogOut and roles edit goes away. You will see that the resource is not read only. Close this one and the project left is read only.

My programm has this problems, and multiple versions of ProjectTracker show the same result. This happens only when the last opened winpart is one that should close on a principal change (LogOut).

Does anyone found a solution for this one?

Thank You.

Ton Smeets replied on Thursday, November 22, 2007

Well, I think I found the problem. Inside the next lines it all happens:

//notify all documents

foreach (Control ctl in Panel1.Controls)

if (ctl is WinPart)

((WinPart)ctl).OnCurrentPrincipalChanged(this, EventArgs.Empty);

When a form (WinPart) should be closed, due to authorization restrictions, it will happen inside that foreach loop. This causes an exception, so I read. What I have done next is create a new enumerator with WinPart controls. And enumerate through this list and do the OnCurrentPrincipalChanged code.

I changed the code above in the next lines:

foreach (Control ctrl in new EnumeratorWrapper<WinPart>(Panel1.Controls))

if(ctrl is WinPart)

((WinPart)ctrl).OnCurrentPrincipalChanged(this, EventArgs.Empty);

 

And added a new Class I found on the internet. See below:

 

public class EnumeratorWrapper<T> : IEnumerable

{

protected List<T> items;

public EnumeratorWrapper(IEnumerable enumerable)

{

items = new List<T>();

foreach (T item in enumerable)

items.Add(item);

}

public IEnumerator GetEnumerator()

{

return items.GetEnumerator();

}

}

Now all winparts are changed correctly during the update in currentPrincipalChanged code.

Please feel free and comment on this one. I am not yet a professional software developer, but I will be some day.Stick out tongue [:P]

Copyright (c) Marimer LLC