Infragistics Home

Infragistics Forums

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

Save and load MDI state

Last post 07-24-2008 12:29 by [Infragistics] Mike Dour. 24 replies.
Page 2 of 2 (25 items) < Previous 1 2
Sort Posts: Previous Next
  • 06-12-2008 11:43 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    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 50 Contributor
    • Joined on 03-21-2008
    • Points 2,680

    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 50 Contributor
    • Joined on 03-21-2008
    • Points 2,680

    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 50 Contributor
    • Joined on 03-21-2008
    • Points 2,680

    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 50 Contributor
    • Joined on 03-21-2008
    • Points 2,680

    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
Page 2 of 2 (25 items) < Previous 1 2
Powered by Community Server (Commercial Edition), by Telligent Systems