C#: capture data, display to user, save to disk, upload to database: BEST approach
January 17, 2009 10:45 PM
Subscribe
I have a program that captures live data from a piece of hardware on a set interval. The data is returned as XML. There are several things I would like to do with this data (in order): -display it to user -save it to disk -eventually, upload it to database
My current approach is to take the XML, parse it into a hashtable so I can display the correct values to the user.
Next, I want to save the XML to a file on disk. For each data capture session I am planning on creating a unique XML file and I will dump all the data into it.
Finally, I would like to reparse the XML and upload it to a MySQL database. The data cannot be immediately uploaded to the database.
This seems really inefficient method of solving this problem and I would love some advice.
Is it a waste of hd space to save the data as XML?
Is it THAT inefficient to have to reparse the XML in order to write it to a database?
Thank you!
To clarify: a typical XML response will be ~1kb and are captured at a rate of about 1 response every 15-60 seconds.
I think I do want to store the XML as XML on the disk because the data is very valuable and a pain to reproduce (if it is even possible). Thank you!
posted by jdlugo to computers & internet (8 comments total)
As far as storing the data on disk, only you can decide if the disk space is worth it. My late-night back-of-envelope bourbon-influenced calculations suggest that uncompressed it will only take up ~5MiB, per day. You can win even more with compression. XML compresses great and if it's just for archival there's not much reason not to. But as long as you're sure you're capturing the data accurately there should be no difference between the original XML and what you extract from it.
Which leads us to the next point. Make sure you use a proper parser and not some regex or other hack to import the XML. And be careful of MySQL. Regular expressions and MySQL are both prone to working great and fast when everything is exactly right, but you can get silent failures and loss of data with the slightest glitch. Write some good tests so you can test your parsing and importing modularly.
Finally, if you're talking about the order of things as priorities, or the order of implementation, that's fine. But as you move forward you might want to rearrange the code so that, for example, there is a dæmon which captures the data, archives it, parses it, and throws it into the database. Meanwhile your GUI can consume this data and display it to the user. Then you can be UI independent and not worry about some UI thread locking thing screwing up your data capture.
Good luck!
posted by vsync at 10:56 PM on January 17