Ejemplo n.º 1
0
 private void LoadNextEvent()
 {
     lock (this)
     {
         if (sinkFile.Position == sinkFile.Length)
         {
             // EOF
             nextEvent = null;
             return;
         }
         // delayOffset = difference in when this event actually happened vs scheduled.
         // See comment for nextEventReleaseTime for details
         long delayOffset = timer.ElapsedMilliseconds - (nextEvent == null ? 0 : nextEvent.Time);
         nextEvent = MillipedeEvent.Deserialize(sinkFile);
         nextEventReleaseTime = nextEvent.Time + delayOffset;
         //Console.WriteLine("Loaded event {0}: recorded at {1}ms, shifted by {2}ms to replay at {3}ms",
         //    NumberEvents + 1, nextEvent.Time, delayOffset, nextEventReleaseTime);
         //Console.WriteLine("  " + nextEvent);
         Monitor.Pulse(this);    // wake any listeners in WaitForReplayEvent
     }
 }
Ejemplo n.º 2
0
 public void Record(MillipedeEvent millipedeEvent)
 {
     if(mode == MillipedeMode.Record)
     {
         if (dataSink == null) { return; }
         millipedeEvent.Time = timer.ElapsedMilliseconds;
         lock (this)
         {
             int eventNo = Interlocked.Increment(ref NumberEvents); // important for replaying too
             if (log.IsTraceEnabled)
             {
                 log.Trace(String.Format("[{2}] Recording event #{0}: {1}",
                     eventNo, millipedeEvent, millipedeEvent.Time));
             }
             if(dataSink != null) { millipedeEvent.Serialize(dataSink); }
         }
     }
     else if(mode == MillipedeMode.Playback)
     {
         MillipedeEvent e = nextEvent;
         if(e == null)
         {
             log.Trace("Millipede Playback: no matching event! (nextEvent == null)");
             // although this may be of interest, it's likely because the recorder
             // was explicitly stopped
         }
         else if(!e.Type.Equals(millipedeEvent.Type))
         {
             if (log.IsTraceEnabled)
             {
                 log.Trace("Millipede Playback: different type of operation than expected!");
                 log.Trace("   expected: " + nextEvent.Type);
                 log.Trace("   provided: " + e.Type);
             }
         }
         else if(!e.ObjectDescriptor.Equals(millipedeEvent.ObjectDescriptor))
         {
             if (log.IsTraceEnabled)
             {
                 log.Trace("Millipede Playback: different message sent than expected!");
                 log.Trace("   expected: " + nextEvent.ObjectDescriptor);
                 log.Trace("   provided: " + e.ObjectDescriptor);
             }
         }
         else
         {
             Interlocked.Increment(ref NumberEvents);
             if (log.IsInfoEnabled)
             {
                 log.Trace(String.Format("Recorded packet {0}: {1}", NumberEvents, e));
             }
             LoadNextEvent();
         }
     }
 }