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

Track Files in Visual Studio

By default, Visual Studio’s Solution Explorer will update its selected item based on the currently active document. This is extremely annoying as it keeps expanding your projects and folders until your solution explorer becomes unmanageable and unusable, unless you collapse all Projects (Only available if you have Visual Studio Power Commands) installed) and even then, after collapsing the entire solution, the saga returns back. Turn off Active tracking 1. Turn your Active tracking off by going to Tools > Options 2. Select “Projects and Solutions” node 3. Uncheck the “Tack Active Item in Solution Explorer” Add a macro to do on-demand tracking 4. Tools > Marcos > Macro Explorer 5. You will see “MyMacros” Module (Node). Right mouse click on MyMacros and invoke “New Module…” 6. Name it anything you like. I Named it Utilities 7. Right mouse click on Utilizes and invoke “new Macro…” menu. The Macros IDE window opens. 8. Paste in the following into it within the Publ...

Google Instant search

Google Instant Search is the worst feature ever!!!. I could not for the life of me find a PERMANENT way to turn it off. Every time I turned it off using different means, it always came back. This is the only link I found useful so far, but the suggestion is not that great. It's OK. http://www.google.com/support/forum/p/Web%20Search/thread?tid=2a8bc9c3770bc11b&hl=en It is so annoying and so intrusive, every time I type a character it interrupts me and then I end up because of the time lag with a different string in the search box than the one I intended to type. Are they hiring a whole new set of STUPID generation at Google. This does not take a rocket scientist to figure out that this feature is useless. Even if they believe that is has some usefulness, let me (the customer, the user) decide. Anyone knows how to turn this stupid feature off?

Reduce Windows Folder Size

I just realized that my Windows directory has over 34 GB of stuff. What the heck!!! When you have Office, a couple of versions of Visual Studio, and few other Microsoft programs, you basically have already gobbled up about 80 GB of hard disk space. I found this online and found it to be useful and effective. It shaves off about 8 GB of your Windows folder. Still not what I had expected but I can definitely use 8 GB for other important documents. I'm just puzzled at what is Micros soft putting in an Operating system folder? huh? 28 GB of crap? Open a command prompt (make sure you either have Admin privileges). If you do not have Admin privileges, then open the command prompt as Admin. dism /online /cleanup-image /spsuperseded /hidesp