I'm a relatively young coder that has been pulling my hair out trying to
design a nice reusable architecture for a project that I'm working on and
could really use the advice of some experts. I posted here because my
language choice isn't too important, but I'm using C# in this case.
I'm working with an embedded system that sends data packets at varying rates
over Ethernet. There are several "channels" of data that indicate various
bits of system data and I have a class that contains a "current view" of the
system. This gets updated every time I get a new piece of data, that data
also gets logged to a database. I have a custom collection that derives from
ArrayList and fires a public NewData() event whenever it is updated.
That all works fine, I get my various bits of data at their different rates
and my class stays current with the system status. The problem comes in now
that I need to display this data (and there is a lot of it). When I first
started my design I was going to use the NewData event to have controls
"subscribe" to the data class. I then realized that this was going to
require me to implement a ton of event_handlers and I think there has to be a
better way to do it.
I thought about binding to the "logging" database but that doesn't seem to
make sense because I always want to display the current state of the system.
I would have to have some kind of database entry that was the "current" view
and that becomes really messy, really fast. Maybe I was missing something
there.
I next looked at directly binding to the current view class itself. Let's
call it MyMachine. MyMachine has a bunch of ArrayLists that hold information
like "Temperature". What I really want to do is an easy way to bind the
single element MyMachine.Temperature[0] to a textbox. I want to be able to
change the individual element I'm binding to on the fly. Say I have 10
texboxes. I want textbox 1 to show Temperature[5] but I can change it so
that it shows Temperature[10] at runtime. I realize that I can use
Reflection to get a list of all Properties of my class. But then instead of
having a nice ArrayList of all Temperatures, I have float properties fTemp1,
fTemp2... etc... I really want the ability for the user to have a drop-down
list of available data types (the array lists), say Temperature, Motor
Current, Supply Voltage and another drop-down of individual elements in those
arrays (Temp1, Temp2, Temp3)
I thought about extending my own versions of textbox, label, etc... so that
they can bind to a list and I specify an individual element. Is that the
right way to go? Most of the time I'm using some custom developed controls
to display the data anyway so extending those wouldn't be too bad. I'm just
wondering if I'm overlooking a really simple solution to this.
Thanks in advance!
-Adam
|