Ejemplo n.º 1
0
        private ObserverQueue FindObserver(int observerId)
        {
            ObserverQueue q = _observers.FirstOrDefault(p => p.Observer.ObserverId == observerId);

            if (q == null)
            {
                throw new ApplicationException("This observer does not watch this game");
            }
            return(q);
        }
Ejemplo n.º 2
0
 public ObservedGameInfo ObserveNextTurn(Observer observer)
 {
     lock (_liveLock)
     {
         checkRunState();
         ObserverQueue    q  = findObserver(observer.ObserverId);
         ObservedTurnInfo ot = q.Pop();
         if (ot == null && q.IsLive)
         {
             Monitor.Wait(_liveLock, Settings.ObserverPollTimeoutMillis);
             ot = q.Pop();
         }
         ObservedGameInfo gi = new ObservedGameInfo
         {
             GameId      = GameId,
             GameState   = State,
             QueuedTurns = (q.IsLive) ? q.Count : -1,
             TurnInfo    = ot
         };
         return(gi);
     }
 }