views:

143

answers:

2

I am designing a list-based app in C# WinForms where I want to store my data in an XML file (which will eventually get serialized into a database). I have a custom control that displays my list data based on my XML, but I'm having trouble determining the best structure to handle the data. I have a ListManager class that keeps track of an XMLDocument, and has methods like CreateList and AddListItem. Should I be using a local copy of the XML structure as what my UI Control reads from, or should I use the actual XML File itself? Is there something better than the XMLDocument that I should be storing as a member variable to keep hold of the data?

Also, how should I go about linking the controller with the UI control? In other words, how should my ListManager alert the ListControl when a new item was added? (Or should it not be doing the update notification at all, and instead the Main Form should do that?)

Thanks!

+2  A: 

I would create a custom class to hold my data using strongly typed collections such as the generic collections System.Collections.Generic.List. Then, you can just serialize this class to and from XML on the client until you are ready to push the content into a database. Using serialization means you can work with plain old C# objects instead of trying to shoe-horn the XMLDocument class into your business object.

Take a look at this article for some details on how serialization works.

Mark Ewer
This makes sense. I will try to abstract the data representation from the data persistence. Thanks!
Kevin
Hope it helps you out. If you get stumped, I have some helper classes I put together to make it easier in a project I am working on. I could slip you a copy if you want it.
Mark Ewer
+1  A: 

imho the scenario you describe could lend itself to several strategies, and key criteria for which implementation strategy you choose might be the dynamic nature of the "data flow," and the sheer size of the data you are handling.

If you are describing a situation where you are dealing with vast stores of data, so that you will not be able to maintain "entire" the internal representation of the external file because of memory constraints : that's one case : in that case you will require "virtualisation" in the sense of that word used to describe presenting "partial views" of the data at any one given moment in time, and, probably, caching so that you keep as much data as you can "ready to display." Or you may elect to use another control for display (like DataGridView) which has "virtual partial display" built-in.

If you are dealing with "asynchronous flows" of new data being added, existing data being removed or edited, hundreds (or thousands) of times per minute, in any order (perhaps from multiple users ?) that's another case.

So, when I suggest you to consider a strategy where :

  1. the ListManager raises custom events to notify subscribers of data change

  2. the custom control (that we assume handles presentation) subscribes to the events of interest raised by the ListManager class, and "does the right thing" : which might involve requesting another "serving" of data from the ListManager, or whatever, to make the current presentation up-to-date.

Please consider that may reflect the simplest possible scenario.

BillW
Conceivably the list could be updated asynchronously in a future version of the application, but there will hardly be more than 4 or 5 users at a time changing it. Also, the lists will not be large enough to warrant virtualization at this time, but I will be keeping it in mind. I felt that using events might be the best option for notifying the view of the updated data. Should the event pass the business object as a paramter to which the UI control updates? Or should it request it once it receives the event from the ListManager object itself?
Kevin