|
|
Save and load MDI state
Last post 09-15-2008 11:59 by mike2008. 27 replies.
-
-
mike2008


- Joined on 05-15-2008
- Points 635
|
Re: Save and load MDI state
[Infragistics] Mike Dour:However, if you want to know how to combine the layout files into one layout file, the code posted originally will do that. Yes, the code does that, and individual layout settings were saved as binary blocks in the main xml file. My question is to save individual layout settings as xml as well, instead of binary blocks. In otherwords, embedding xml files into the main one. I was trying to write the individual layout settings as CData elements in the main xml file. If i write those layout settings as normal xml elements, some characters will be handled specially, e.g., "<", ">". Any better suggestions or sample code? Thanks!
|
|
-
-
-
vrn


- Joined on 03-21-2008
- Points 3,750
|
Re: Save and load MDI state
Mike2008, I am going to take advantage of your thread to ask Mike Dour a related question. hope that is okay.
Mike Dour, what is the relative benefit of the Base 64 approach over XML? I am very new to this and hopefully not asking something very basic. It seems like using the XML would be advantageous for application support purposes.
Thanks!
|
|
-
-
-
vrn


- Joined on 03-21-2008
- Points 3,750
|
Re: Save and load MDI state
So Base64 is necessary to implement as binary?
|
|
-
-
-
vrn


- Joined on 03-21-2008
- Points 3,750
|
Re: Save and load MDI state
[Infragistics] Mike Dour:
private void Form1_Load( object sender, EventArgs e ) { if ( File.Exists( "config.xml" ) == false ) return;
using ( XmlTextReader reader = new XmlTextReader( "config.xml" ) ) { reader.ReadStartElement( "Config" );
using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) ) this.ultraToolbarsManager1.LoadFromBinary( stream );
using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) ) this.ultraToolbarsManager1.LoadFromBinary( stream ); } }
Mike, In the above code snippet I think you meant to do something with ToolbarConfig and DockConfig since write it out at Form closure.
[Infragistics] Mike Dour:
writer.WriteStartElement( "DockConfig" );
If you do not mind, can you add that code to snippet to help me understand how you use the stream to read individual settings
Second questoin, I want to let users to save as many settings as they like. That way they can have multiple looks and layouts pre-defined and they can change it to any of them very quickly. When they load such a setting file, I would like each control to process its own settings by firing an event. What should I be sending as part of the event to the individual control so that the control can pick it up from there? Should I make the control get the XML stream, the complete binary or something else?
Thanks!
|
|
-
-
[Infragistics] Mike Dour


- Joined on 10-25-2007
- Melville, NY
- Points 17,104

|
Re: Save and load MDI state
vrn:Mike, In the above code snippet I think you meant to do something with ToolbarConfig and DockConfig since write it out at Form closure.
My code snippet used an XmlTextReader, which just reads the nodes in order, so it did not need to specify the config file it was looking for. I could have put asserts before loading each stream to make sure the current node had the expected names before loading them.
vrn:Second questoin, I want to let users to save as many settings as they like. That way they can have multiple looks and layouts pre-defined and they can change it to any of them very quickly. When they load such a setting file, I would like each control to process its own settings by firing an event. What should I be sending as part of the event to the individual control so that the control can pick it up from there? Should I make the control get the XML stream, the complete binary or something else?
I would send the stream loaded from the file in the event args. Then the control can just pass that to its appropriate LoadFrom... method.
|
|
-
-
vrn


- Joined on 03-21-2008
- Points 3,750
|
Re: Save and load MDI state
[Infragistics] Mike Dour:
My code snippet used an XmlTextReader, which just reads the nodes in order, so it did not need to specify the config file it was looking for. I could have put asserts before loading each stream to make sure the current node had the expected names before loading them.
Mike your code worked like a charm!
- I am guessing because ReadBase64 is reading the next node and decoding it, the order of loading the controls is important? So it should be read in the same sequence that I saved it?
- Do you have suggestion on how I can make the loading sequence independent of the saving sequence? This can prove useful for my design where I am trying to make each component completely independent of the other. So each component should be able to figure out its own setting from the larger XML file.
|
|
-
-
[Infragistics] Mike Dour


- Joined on 10-25-2007
- Melville, NY
- Points 17,104

|
Re: Save and load MDI state
vrn:I am guessing because ReadBase64 is reading the next node and decoding it, the order of loading the controls is important? So it should be read in the same sequence that I saved it?
Yes, that is correct.
vrn:Do you have suggestion on how I can make the loading sequence independent of the saving sequence? This can prove useful for my design where I am trying to make each component completely independent of the other. So each component should be able to figure out its own setting from the larger XML file.
Instead of using an XmlTextReader, you can try to implement something using an XmlDocument. Then each control can iterate the child nodes of the document and find the node with their stream name and just read in that node. Alternatively, you could keep the same approach and read in all streams and populate them into a Dictionary<string,Stream>, where the key is the stream name. Then when each control goes to load, they just access the dictionary with the name they are looking for.
|
|
-
-
mike2008


- Joined on 05-15-2008
- Points 635
|
Re: Save and load MDI state
[Infragistics] Mike Dour:In the handler, you can get the PersistedInfo for the tab and create a Form (or use an existing Form) to use for the tab. Set the Form on the Form property of the event arguments.
I successfully save the xml and load when opening. Now I need to add more information to the PersistedInfo object, e.g., some state information of the child form. I have a Serializable class called MdiChildFormState to save to PersistedInfo, and I added the new members with [OptionalField()] attribute. Then I tried to load the old version of the MDI layout file (without new memebers), and I got the following exception: [System.ArgumentNullException] {"Member at position 1 was null.\r\nParameter name: members"} System.ArgumentNullException and ex.StackTraceis like the follows: at System.Runtime.Serialization.FormatterServices.PopulateObjectMembers(Object obj, MemberInfo[ members, Object[ data) at System.Runtime.Serialization.Formatters.Soap.ReadObjectInfo.PopulateObjectMembers() at System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObjectEnd(ParseRecord pr) at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord pr) at System.Runtime.Serialization.Formatters.Soap.SoapHandler.EndElement(String prefix, String name, String urn) at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXml() at System.Runtime.Serialization.Formatters.Soap.SoapParser.Run() at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser) at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler) at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream) at Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager.Load(Stream stream, Boolean xml) at Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager.LoadFromXml(Stream stream) Any idea how I can solve this issue?
Thanks. Mike2008
|
|
-
-
-
mike2008


- Joined on 05-15-2008
- Points 635
|
Re: Save and load MDI state
It looks like OptionField in Serializable class does not work when using SOAP formatter. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=140592 I implemented ISerializable interface for the class, and added my own serialization and deserialization method to handle optional fields.
It works fine now.
Thanks.
|
|
|
|