mardi 5 mai 2015

Designing a windows application to maintain states across MDI child forms

It's a pretty long post and I shall try my best to explain the working of the application that I have developed and want your assistance in extending it for the future.

I need to design a windows based application in C# which basically monitors events from an external communication source and plots the data on a graph. The application subscribes to events from communication objects and updates the UI as and when there are data events. A graph component inside these monitoring classes will use the data inside the communication data buffers to plot the data as a line graph.

enter image description here

To achieve this, I have created a Factory class which will instantiate a particular monitoring class (CWindowFirst or CWindowSecond etc) based on Model information I provide (device model type).

These classes implement standard contract (IFactoryInterface) for initialization , data acquisition and cleanup operations. So at any given point of time I can instantiate a particular class and start the monitoring operation to receive the data and populate the graph in the process. So far so good, I can display the data in the form of a graph for a particular device.Also at the moment I'm destroying(disposing) the object of CWindowFirst whenever the main application chooses another window (i.e. CWindowSecond or CWindowThird).

As the saying goes in "SW development the only constant is the Change", A new requirement has come up where I need to give the user an option to Pause/Stop feature for the graph. I should be able to Pause the graph (i.e. pause the data communication ) and go to main window play around and also should be able to open another window (CWindowSecond) play there around a bit with the graph again (should be able to pause the communication here as well). Come back to the first window CWindowFirst and resume the previously saved data communication.

Now comes the million $ question, how do I achieve or rather modify the existing design to implement the feature as described above.

I can think of the following implementation but I'm not sure if its really a pragmatic one.

On issue of Pause command I shall

  1. Stop the communication (unsubscribe communication event) on Pause.
  2. Save the state of the event data buffers and graph in a collection.
  3. Serialize the complete object to a file before exit.
  4. On return to the same form, I shall deserialize the object
  5. Get the event data buffer from the deserialized object
  6. Populate in the graph and enable the event handlers so that I continue to receive events from the communication layer.

Experts out there I need your assistance out here. Please guide / suggest improvements / share your idea

Aucun commentaire:

Enregistrer un commentaire