Skip to main content

Persistence of Wave Manager user's preferences to an XML file

Steve asks:
I figured out how to set the background, foreground etc to the user setting config file but I am having trouble saving the opened children widows on closing to the settings. Is it approprate to save this info to the user setting config file?
I create a new setting of type String Collection but at start-up when reading the user setting file it is extreamly slow. Would I be better off in the registry.

Youssef's Reply:
Steve, you have several choices but I believe you may be making it more difficult that it needs to be. Putting some configuration in an xml/config file and the rest in the settings file is not acceptable. The Settings even though may seem straight forward is not the right place and will most likely cause you more grief than it's worth.
The choices you had are:
1- Simplest:
1a- Make a UserPreferences class that conatins all the persistent information (WaveBackColor, WaveForeColor, WaveThickness, FileViewFont, etc., and what you need is a StringCollection (like a List) for the open document files and you need a Rectangle which represents the Main Window dimensions and location).
1b- Build a UserPreferencesMgr static class that contains a single static member of type UserPreferences.
1c- When the user changes a color, font, thickness, etc, Simply use the UserPreferencesMgr to set those values into the fields of the UserPreferences class.
1d- Once you have that, all you need to do is Within the Main Form's Closing event, set the Window Rectangle in UserPreferences to that of your main Form Window and the list of Open MDI Child wave files.
1e- Within the Main Form's Closing event Then Serialize that UserPreferences class using SoapFormatter (SOAP = XML, ugly XML but XML nonetheless). This is the easiest choice.
2- A bit more Complex but cleaner:
2a- Same as 1a-1d.
2b- But instead of serializing the UserPreferences using SOA, write the values of each of the fields one by one to an XML file using an XmlWriter class or one of its cousins (See FileIO slides)
I just took the final project source I have and spent 15 minutes and switched from registry to an xml file using approach #1 above. I have uploaded the sample(version 1.0.0.7) and XML file.
Hope this helps

Comments

  1. Note that if you are using SoapFormatter, this formatter has a bug that has been (by design) outstanding for 5 years, and when I contacted Microsoft about it 5 years ago they said, they are not going to fix because SoapFormatter will no longer be supported moving forward. So SoapFOrmatter does not know how to serialize any Generic type like List for example. So instead you can use StringCollection.

    ReplyDelete

Post a Comment

Popular posts from this blog

WCF Dos and Don'ts

Do not inherit interfaces from other interfaces. Interfaces are contracts. Contracts must be explicit, otherwise the flexibility and maintainability of your design would run into issues. An interface is a pure contract definition and should remain explicit and pure. Consider the following example: [ServiceContract] public interface IMyService1 { [OperationContract] void Test1(); } [ServiceContract] public interface IMyService2 : IMyService1 { [OperationContract] void Test2(); } [ServiceBehavior(…)] class MyService : IMyService2, IMyService1 { #region IMyService2 Members public void Test2() { } #endregion #region IMyService1 Members public void Test1() { } #endregion } What happens when you Publish your Service and open its communication channels. If you do the following: ServiceHost serviceHost = new ServiceHost(typeof(MyService, …) ServiceEndpoint ep = serviceHost.AddServiceEndpoint(typeof(IMyService1), typeof(IMyService2)); You will get

How to turn off the annoying adobe updater

Mainly for peole who only installed adobe reader, this becomes an annoying intrusive behavior. Who cares about the updated version of Adobe. 1- Run Adobe Reader 2- Invoke the "Edit" > "Preferences" menu 3- Select the Updater node at the bottom. 4- Select the "Do not download or install updates automatically" 5- Press OK. Done!!!!!!!!!!!! Phew

TF31001 error when connecting to TFS 2010

The Server returned the following error: 246021. An error occurred while processing your request. Technical Information (for Administrator): SQL Server Error 1934 (retry) This error is caused due to SQL Server Server settings of "noCount" and/or "numeric round about" being turned on. Run ssms.exe, right click on the SQl Server node, and invoke the Proerties dialog. Select the "Connections" node, and turn off both items.