This is a migrated thread and some comments may be shown as answers.

RadDock.LoadFromXml failed and reset it

5 Answers 247 Views
Dock
This is a migrated thread and some comments may be shown as answers.
MG
Top achievements
Rank 1
MG asked on 03 May 2013, 11:23 AM
Hi,
I have a scenario where the rad dock configuration xml file has be tampered. When loading it, it fails, is there a way to tell to raddock that it needs to ignore settings from xml completely as if there we haven't loaded it from xml file.
Here is a code snippet,
 if (File.Exists(DockStatePath))
 {   
 try { radDock.LoadFromXml(DockStatePath);       
  }    
  catch (XmlException)   
  {
      //suppress do nothing  instead make sure it radDock behaves as we are not loading any settings
  }
}

We can load default settings but that won't help because the users will have different resolution from the one where form is being designed.
If loading fails, it needs to treat as if we never attempted to load from xml file thus it maintains correct layout settings like the one without loading it from Xml file.

Thx in Advance.
M




5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 06 May 2013, 08:42 AM
Hi Milan,

Thank you for writing.

I can confirm the observed issue appears and I have logged it in our Public Issue Tracking System. You can subscribe for its status updates here: http://www.telerik.com/support/pits.aspx#/public/winforms/14957.

To work around this case, you will have to call the following method prior loading the default layout:
if (File.Exists("userDockState.xml"))
{
    try
    {
        radDock1.LoadFromXml("userDockState.xml");
    }
    catch (XmlException)
    {
        radDock1.EndTransactionBlock();
        radDock1.LoadFromXml("defaultDockState.xml");
    }
}

I hope that you find this information useful. Your Telerik Points have been updated for this report.
 
Greetings,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
MG
Top achievements
Rank 1
answered on 07 May 2013, 10:06 AM
Hi Stefan,
Thanks for the reply.

If XmlException is being thrown, we can call radDock.EndTransactionBlock() and it does what I wanted but if it throws other exception like System.FormatException (when raddock config file has int value but been tampered to string), loading default settings has no effect what so ever. In order to verfiy, please change int value in config xml file and try to to load it back with default settings xml.

if (File.Exists("userDockState.xml"))
{
try
{
radDock1.LoadFromXml("userDockState.xml");
}
catch (XmlException)
{
radDock1.EndTransactionBlock();
radDock1.LoadFromXml("defaultDockState.xml");
}catch(Exception)
{
radDock1.EndTransactionBlock();
radDock1.LoadFromXml("defaultDockState.xml"); //it does not do anything

}
}
Please kindly advise.
Many thanks,
M G
0
Stefan
Telerik team
answered on 09 May 2013, 08:43 AM
Hi,

Thank you for writing back.

This scenario seems to be working on my end. Please refer to the attached project and video. Can you please let me know what I am missing?
 

Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
MG
Top achievements
Rank 1
answered on 09 May 2013, 11:13 AM
Hi Stefan,

Thank you for your solution.

I am attaching a sample project that shows the problem I am having. It has 3 tool windows docked to left and 2 windows docked to right.
There is a button to generate "userdockstate.xml" and "defaultsetting.xml" by clicking button1 and button2 in the form.

Once those files are created,
1. Modify "userdockstate.xml" by just changing <RadDock> root element to <RadDock1> and run the application. It throws XmlException and default layout is set by loading "defaultsetting.xml" file. This is fine
2. Now, modify "userdockstate.xml" such that it generates other exception as an example, simple change "AutoSizeScale="0, 0" attribute to contain string "AutoSizeScale="dfdf, 0".   This time, it goes to second catch statement and tries to load the same "defaultsetting.xml" file but the form loses tool window.
I have attached the sample project Iin the support ticket and screenshots of the forms - working one and problematic one for you to review.

Please kindly advise.

Many thanks
M G
0
Accepted
Stefan
Telerik team
answered on 14 May 2013, 06:16 AM
Hi,

I am copying the answer from the support ticket to this thread as well so the community can benefit from it:

In this case, the exception is being thrown at a time when the dock started rebuilding itself, so the workaround that I previously provided will not work in this case. 

To handle this scenario I can suggest creating a new dock instance in memory and attempt to load the layout in it. If it fails, load the default state, alternatively, load the user state.

if (File.Exists("userdockstate.xml"))
{
    try
    {
        RadDock tempDock = new RadDock();
        tempDock.LoadFromXml("userdockstate.xml");
         
        radDock1.LoadFromXml("userdockstate.xml");
    }
    catch (XmlException)
    {
        radDock1.EndTransactionBlock();
        radDock1.LoadFromXml("defaultSettings.xml");
    }
    catch (Exception)
    {
        radDock1.LoadFromXml("defaultSettings.xml");
    }
}

 

All the best,
Stefan
the Telerik team
RadChart for WinForms is obsolete. Now what?
Tags
Dock
Asked by
MG
Top achievements
Rank 1
Answers by
Stefan
Telerik team
MG
Top achievements
Rank 1
Share this question
or