Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Save and load MDI state

Last post 09-15-2008 11:59 by mike2008. 27 replies.
Page 2 of 2 (28 items) < Previous 1 2
Sort Posts: Previous Next
  • 06-12-2008 11:43 In reply to

    • mike2008
    • Top 150 Contributor
    • 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!

    • Post Points: 20
  • 06-12-2008 11:56 In reply to

    Re: Save and load MDI state

    If you use an XmlTextWriter like in the code I posted, I believe there is a WriteString method which will escape all control characters automatically. When you read back the string value with the XmlTextReader, the string will automatically be unescaped.

    • Post Points: 20
  • 07-14-2008 12:57 In reply to

    • vrn
    • Top 25 Contributor
    • 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!

    • Post Points: 20
  • 07-14-2008 13:34 In reply to

    Re: Save and load MDI state

    It all depends on whether you would like to use SaveAsBinary or SaveAsXml. The binary layout files are smaller in size but cannot be manually examined or edited. The XML layout files can be opened and edited by a developer in any xml editor.

    • Post Points: 20
  • 07-14-2008 13:58 In reply to

    • vrn
    • Top 25 Contributor
    • Joined on 03-21-2008
    • Points 3,750

    Re: Save and load MDI state

    So  Base64 is necessary to implement as binary?

    • Post Points: 20
  • 07-15-2008 13:56 In reply to

    Re: Save and load MDI state

    It all depends on how you want to store the data. If you want to convert the bytes of the saved binary layout file to some other format, you can use that. I just used Base64 because it is the standard way to store binary data.

    • Post Points: 5
  • 07-23-2008 1:57 In reply to

    • vrn
    • Top 25 Contributor
    • 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!

    • Post Points: 20
  • 07-23-2008 9:37 In reply to

    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.

    • Post Points: 20
  • 07-24-2008 4:25 In reply to

    • vrn
    • Top 25 Contributor
    • 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.

     

     

    • Post Points: 20
  • 07-24-2008 12:29 In reply to

    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.

    • Post Points: 5
  • 09-01-2008 12:53 In reply to

    • mike2008
    • Top 150 Contributor
    • 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

     

    • Post Points: 20
  • 09-15-2008 11:49 In reply to

    Re: Save and load MDI state

    I am not sure what the problem is from the stack trace. It could be a problem with the application or the tabbed mdi manager. I would recommend submitting a sample and the old layout file to the support group so it can be investigated further: http://www.infragistics.com/gethelp.

    • Post Points: 20
  • 09-15-2008 11:59 In reply to

    • mike2008
    • Top 150 Contributor
    • 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. 

    • Post Points: 5
Page 2 of 2 (28 items) < Previous 1 2
Powered by Community Server (Commercial Edition), by Telligent Systems