I need to independently record events on different computers and reconstruct which order those events happened relative to each other. The solution calls for each computer to be relatively independent; they cannot directly talk to each other or a single source.
My initial solution recorded the time on each machine, but since times can be different on different machines, and can change throughout the day, this did not completely solve my problem. I decided to share with all machines whenever a machine (1) starts the process, or (2) has its system clock change.
So from each machine I get a log full of these
public class Activity {
DateTime TimeOccurred { get; set; }
string Description { get; set; }
}
Whenever (1) or (2) happens above, I add an activity to the log and broadcast it to the other machines, who add the same activity to their log, with the TranslatedTime being their own time:
public class TimeSynchronization : Activity {
string SourceMachine { get; set; }
DateTime TranslatedTime { get; set; }
}
So machine A would have (in order):
TimeSynchronization "started" at 3:00 am.
Activity "asked a question" at 3:05 am.
TimeSynchronization from machine B at 3:05 am.
TimeSynchronization "clock changed" at 3:03 am.
Activity "received an answer" at 3:04 am.
And machine B would have (in order):
TimeSynchronization "started" at 3:05 am.
TimeSynchronization "clock changed" at 3:06
So I need to reconstruct the same order and timing of these above events, to something like:
On machine A: TimeSynchronization "started" at 0:00
On machine A: Activity "asked a question" at 0:05
On machine B: TimeSynchronization "started" at 0:05
On machine A: TimeSychronization from machine B at 0:05
On machine A: TimeSynchronization "clock changed" at 0:06
On machine B: TimeSynchronization "clock changed" at 0:06
On machine A: Activity "received an answer" at 0:07
What is the best way to take a List<Activity>
from each machine and merge it into one list with the events in order?