I'm not sure if I have the terminology correct but I am looking at creating a Checksum / Hash Value from a List of custom objects based on a single Integer value which is technically the primary key in the database.
The use case is the List of custom objects holds is essentially a monitor of various events which are in progress. These events are sent to the GUI program which displays them nicely on the screen. Best way to think of it is as a list of events in progress.
Occasionally I have the issue where the message does not make it to the GUI due to network issues so I'm looking at creating some sort of identifying value which represents the state of the system. This can then be sent down to the GUI with each message and if this value does not match what the GUI has stored, then the GUI can request a refresh list of events.
Any guidance would be appreciated.
UPDATE
Further to this I thought Id provide some samples of what Im trying to achieve to clarify.
My Base Class might be as follows:-
public class BaseEvent {
public DateTime EventDate { get;set;}
public EventName EventName { get;set;}
public int EventID { get;set;}
}
The underlying service and GUI would have a collection with the service being the "master"
List<BaseEvent> _eventList = new List<BaseEvent>();
One the service the events would be generated and added to the list (sample below - not how it would happen in real world scenario)
_eventList.Add(new BaseEvent() { EventID=1, EventName="Event 1", EventDate=DateTime.Now };
_eventList.Add(new BaseEvent() { EventID=2, EventName="Event 2", EventDate=DateTime.Now };
_eventList.Add(new BaseEvent() { EventID=3, EventName="Event 3", EventDate=DateTime.Now };
As each of the events is being received / processed by the server, they would be sent out the socket to all GUI clients (all classes are serializable)
Every time an Event is Added to or removed from the list, the server will store the current hash in a variable.
public class SocketData {
public BaseEvent CurrentEvent { get;set;}
public int CurrentHash { get;set;}
}
So based on the above and a very basic hash of adding the EventIDs together, the following would happen
When Event 1 is sent the Current Hash would be 1
When Event 2 is sent the Current Hash would be 3 ( 1 + 2 )
When Event 3 is sent the Current Hash would be 6 ( 1 + 2 + 3 )
So the goal would be to create a mechanism that would guarantee the "hash" of the System Event ID for all items in the service list would be unique.
Then at the GUI end the goal is when a message is received from the service, it checks the hash value received in the message and compares with its own hash and if they dont match, it will request the events from the service.
Hopefully this clarifies what I am trying to achieve.
THanks.