Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How do custom controls work with graph persistence (Read 3231 times)
benjamin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 30th, 2006
How do custom controls work with graph persistence
Nov 30th, 2006 at 5:38pm
Print Post  
I would like to use a custom Windows Form UserControl within a graph, and then save the graph. However the control contains information that should be saved and reloaded when the entire graph file is loaded.

What do I have to implement in my UserControl to supporr this? Is there a set of interfaces that have to be implemented?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3349
Joined: Oct 19th, 2005
Re: How do custom controls work with graph persist
Reply #1 - Nov 30th, 2006 at 6:23pm
Print Post  
The control saves automatically all public properties of the hosted control that are from value types (number, structs, enums), strings, or objects that implement ISerializable. You can either expose each piece of data as a separate property, or create one property of a struct or ISerializable type to contain all the data.

HTH
  
Back to top
 
IP Logged
 
benjamin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 30th, 2006
Re: How do custom controls work with graph persist
Reply #2 - Nov 30th, 2006 at 6:31pm
Print Post  
Slavcho wrote on Nov 30th, 2006 at 6:23pm:
The control saves automatically all public properties of the hosted control that are from value types (number, structs, enums), strings, or objects that implement ISerializable. You can either expose each piece of data as a separate property, or create one property of a struct or ISerializable type to contain all the data.

HTH


Ah beautiful, so all I have to do is on my control expose .NET properties, and as long as those properties are typed as string or intrinsic value types, I don't have to do anything special? And when reloaded, these properties will be re-set?

I am guessing then that FlowChart .NET is using reflection to inspect all this stuff during persistence and load time?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3349
Joined: Oct 19th, 2005
Re: How do custom controls work with graph persist
Reply #3 - Nov 30th, 2006 at 6:45pm
Print Post  
Quote:
Ah beautiful, so all I have to do is on my control expose .NET properties, and as long as those properties are typed as string or intrinsic value types, I don't have to do anything special? And when reloaded, these properties will be re-set?


It's supposed to work that way, but one cannot be ever sure Grin

Quote:
I am guessing then that FlowChart .NET is using reflection to inspect all this stuff during persistence and load time?


Yes, there's a lot of reflection used there.

g.
  
Back to top
 
IP Logged
 
benjamin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 30th, 2006
Re: How do custom controls work with graph persist
Reply #4 - Nov 30th, 2006 at 6:48pm
Print Post  
Slavcho wrote on Nov 30th, 2006 at 6:45pm:
It's supposed to work that way, but one cannot be ever sure Grin


Uhm, Ok.. but aren't you one of the developers? I guess I'll find out soon enough Smiley
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3349
Joined: Oct 19th, 2005
Re: How do custom controls work with graph persist
Reply #5 - Nov 30th, 2006 at 7:03pm
Print Post  
Yeah, but take for example the RichTextBox control. We had the following problem recently - RichTextBox defines Text, Lines and Rtf properties. Rtf contains the formatting tags, and Text and Lines contain just the plain text without any formatting.

So FlowChart.NET saves Rtf with formatting, then it saves the other 2 plain-text properties. When loading, Rtf is set first, and then Text. However assigning to Text has a side effect of losing all formatting, so what you load from the file is not the same as what you save Smiley

So we have added to the 4.2.2 version some special code to filter out the Text and Lines properties of RichText object. That's just an example that one never knows what will happen when using reflection.

g.
  
Back to top
 
IP Logged
 
benjamin
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 30th, 2006
Re: How do custom controls work with graph persist
Reply #6 - Nov 30th, 2006 at 7:06pm
Print Post  
Slavcho wrote on Nov 30th, 2006 at 7:03pm:
Yeah, but take for example the RichTextBox control. We had the following problem recently - RichTextBox defines Text, Lines and Rtf properties. Rtf contains the formatting tags, and Text and Lines contain just the plain text without any formatting.

So FlowChart.NET saves Rtf with formatting, then it saves the other 2 plain-text properties. When loading, Rtf is set first, and then Text. However assigning to Text has a side effect of losing all formatting, so what you load from the file is not the same as what you save Smiley

So we have added to the 4.2.2 version some special code to filter out the Text and Lines properties of RichText object. That's just an example that one never knows what will happen when using reflection.

g.


I see, however that is not really an issue with reflection, it's a behavior in the RTF control that was poorly defined and documented (not a big surprise given it's owner).

All I want to know is if the properties themselves are restricted to those types, they will always be properly set. How my UserControl handles these properties being set (and in what order) is completely up to me and something totaly in my control.

But I get your point. If you use a 3rd party control, this might be completely out of your hands.

Perhaps you'd be good to provide a persistencepolicy class, which defines in which order properties should be set? Could probably be very easy to implement. That would free you from having to write special cases in your code, since you can never account for all the 3rd party controls out there, nor should that code really be in your library to begin with.

Just my 2 cents.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3349
Joined: Oct 19th, 2005
Re: How do custom controls work with graph persist
Reply #7 - Nov 30th, 2006 at 7:20pm
Print Post  
That's a nice idea, thanks.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint