public override void Activate(YeOldePub yeOldePub) { while (_hasGoneHome is false) { switch (CheckState(yeOldePub)) { case RunState.Idle: messageLog.Enqueue($"{DateTime.UtcNow}: Is idling"); Thread.Sleep(TimeSpentIdling); break; case RunState.Work: //Gather empty pints from Tables if (yeOldePub.Tables != null) { messageLog.Enqueue($"{DateTime.UtcNow}: Gathering dirty pints from tables"); foreach (var pintGlass in yeOldePub.Tables.Where(g => g.HasBeer is false && g.IsClean is false)) { PintGlass gatheredPintGlass = null; while (gatheredPintGlass is null) { _ = yeOldePub.Tables.TryTake(out gatheredPintGlass); } tray.Add(gatheredPintGlass); } Thread.Sleep(TimeSpentCollectingPintGlass); //Clean glass and place on Shelves messageLog.Enqueue($"{DateTime.UtcNow}: Cleaning {tray.Count} pint(s)"); foreach (var pintGlass in tray) { pintGlass.IsClean = true; var shelved = false; while (shelved is false) { shelved = yeOldePub.Shelves.TryAdd(pintGlass); } tray.Remove(pintGlass); Thread.Sleep(TimeSpentWashingPintGlass); } messageLog.Enqueue($"{DateTime.UtcNow}: Finished placing clean pints on the shelves"); } break; case RunState.LeavingThePub: DataManager.waitressLog.Add($"{DateTime.UtcNow}: Going home"); _hasGoneHome = true; break; } } }
public override void Activate(YeOldePub yeOldePub) { while (_hasGoneHome is false) { switch (CheckState(yeOldePub)) { case RunState.Idle: //Wait before checking for new patron Thread.Sleep(1000); MessageLog.Enqueue($"{DateTime.UtcNow}: Waiting for a patron"); //OnMessageLogged(new MessageLogEventArgs($"{DateTime.UtcNow}: Waiting for a patron")); break; case RunState.Work: //Identify patron in first in queue Patron patronBeingServed = null; while (patronBeingServed is null) { _ = yeOldePub.PatronsWaitingForBeer.TryPeek(out patronBeingServed); } MessageLog.Enqueue($"{DateTime.UtcNow}: Taking order from {patronBeingServed}"); //Get clean glass from Shelves while (_pintGlass is null) { _ = yeOldePub.Shelves.TryTake(out _pintGlass); } Thread.Sleep(TimeSpentGettingGlass); MessageLog.Enqueue($"{DateTime.UtcNow}: Getting a glass from the shelves"); //Fill glass with beer _pintGlass.HasBeer = true; _pintGlass.IsClean = false; Thread.Sleep(TimeSpentFillingGlassWithBeer); MessageLog.Enqueue($"{DateTime.UtcNow}: Filling glass with beer"); //Give glass to customer patronBeingServed.PintGlass = _pintGlass; _pintGlass = null; MessageLog.Enqueue($"{DateTime.UtcNow}: Giving beer to {patronBeingServed}"); break; case RunState.LeavingThePub: MessageLog.Enqueue($"{DateTime.UtcNow}: Going home"); _hasGoneHome = true; break; } } }