Following scenario:
Put "this.Close()" in comment of the class RolesEdit.cs of the ProjectTracker application.
So the form will stay on the screen when you click Save.
Problem:
The event Roles_Saved doesn't get executed anymore when you click a second time on Save:
private void Roles_Saved(object sender, Csla.Core.SavedEventArgs e){
// this runs on the client and invalidates // the RoleList cache RoleList.InvalidateCache();}
What can be the reason that the Roles_Saved doesn't get called anymore?
The Saved event is raised by an object instance.
When you call Save() you get back a new object instance.
Any handler for the Saved event must hook the new Saved event from the new object instance.
Interesting. I think this is due to serialization, and it is a
bug in the Roles class.
Now that I think about it, when the new object comes back from
the server, it is deserialized onto the client. The deserialization process
doesn’t run any constructors (not normal ones anyway), and so that code
doesn’t execute.
So what’s needed is this code:
protected override void OnDeserialized()
{
base.OnDeserialized();
this.Saved += Roles_Saved;
}
That should re-establish the event handler in the new instance.
I’m glad you discovered this!
Rocky
Great. This is the missing code.
I was wondering because I'm using a 2-tier architecture (physical), so my first
thought was that I don't need to worry about serializing. But after some
investigation I discovered that your save method is automatically cloning the
object in CSLA 3.5.2. The code for your cloning is using Serialize and Deserialize and that
is the reason we have to implement OnDeserialized method. Correct me if I'm
wrong.
The code I added is the following:
protected override void
OnDeserialized(System.Runtime.Serialization.StreamingContext context)
{
base.OnDeserialized(context);
this.Saved += new
EventHandler<Csla.Core.SavedEventArgs>(Roles_Saved);
}
Alef
You are correct, and that should be the right answer. I’ve
added that code into ProjectTracker too, so the next person won’t have to
figure this out :)
Rocky
From: alef
[mailto:cslanet@lhotka.net]
Sent: Tuesday, November 18, 2008 7:57 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: Saved event is not being called the second
time
Great.
This is the missing code.
I was wondering because I'm using a 2-tier architecture (physical), so my first
thought was that I don't need to worry about serializing. But after some
investigation I discovered that your save method is automatically cloning the
object in CSLA 3.5.2. The code for your cloning is using Serialize and
Deserialize and that is the reason we have to implement OnDeserialized method.
Correct me if I'm wrong.
The code I added is the following:
protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext
context)
{
base.OnDeserialized(context);
this.Saved += new
EventHandler<Csla.Core.SavedEventArgs>(Roles_Saved);
}
Alef
Copyright (c) Marimer LLC