Esempio n. 1
0
 //Constructor
 public Waitress(YeOldePub yeOldePub)
 {
     CurrentState = RunState.Idle;
     tray         = new List <PintGlass>();
     _hasGoneHome = false;
     var taskWaitress = Task.Factory.StartNew(() => Activate(yeOldePub));
 }
Esempio n. 2
0
 private RunState CheckState(YeOldePub yeOldePub)
 {
     if (yeOldePub.currentPubState is PubState.Closed)
     {
         return(RunState.LeavingThePub);
     }
     return(RunState.Work);
 }
 static public void OpenClosePub()   
 {
     yeOldePub = new YeOldePub();
     while(yeOldePub.currentPubState is PubState.Open)
     {
         InsertMessageLog(yeOldePub);
     }
    // yeOldePub.Bartender.MessageLogged += InsertMessageLog(MessageLogEventArgs;
 }
Esempio n. 4
0
 //Constructor
 public Patron(YeOldePub yeOldePub)
 {
     Name         = SetRandomPatronName();
     CurrentState = RunState.WalkingToBar;
     _hasGoneHome = false;
     //_isThirsty = true;
     //_isSitting = false;
     var taskPatron = Task.Factory.StartNew(() => Activate(yeOldePub));
 }
Esempio n. 5
0
 private RunState CheckState(YeOldePub yeOldePub)
 {
     if (yeOldePub.Patrons is null && yeOldePub.currentPubState is PubState.Closed)
     {
         return(RunState.LeavingThePub);
     }
     if (yeOldePub.Tables != null)
     {
         return(RunState.Work);
     }
     return(RunState.Idle);
 }
Esempio n. 6
0
 private RunState CheckState(YeOldePub yeOldePub)
 {
     //Check to see if bartender should work or go home
     if (yeOldePub.Patrons is null && yeOldePub.currentPubState is PubState.Closed)
     {
         return(RunState.LeavingThePub);
     }
     if (yeOldePub.PatronsWaitingForBeer.IsEmpty == false && yeOldePub.Shelves.Count > 0)
     {
         return(RunState.Work);
     }
     return(RunState.Idle);
 }
Esempio n. 7
0
        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;
                }
            }
        }
Esempio n. 8
0
        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;
                }
            }
        }
Esempio n. 9
0
        public override void Activate(YeOldePub yeOldePub)
        {
            while (_hasGoneHome is false)
            {
                switch (CheckState(yeOldePub))
                {
                case RunState.Work:
                    for (int patron = 0; patron < NumOfPatronsToLetInside; patron++)
                    {
                        var newPatron = new Patron(yeOldePub);
                        while (!(yeOldePub.Patrons.TryAdd(newPatron.Name, newPatron)))
                        {
                            ;
                        }
                    }
                    Thread.Sleep(GetLeadTime());
                    break;

                case RunState.LeavingThePub:
                    _hasGoneHome = true;
                    break;
                }
            }
        }
Esempio n. 10
0
        //public event EventHandler MessageLogged;

        //Constructor
        public Bartender(YeOldePub yeOldePub)
        {
            _hasGoneHome = false;
            var taskBartender = Task.Factory.StartNew(() => Activate(yeOldePub));
        }
Esempio n. 11
0
 public virtual void Activate(YeOldePub yeOldePub)
 {
 }
Esempio n. 12
0
 static void InsertMessageLog(YeOldePub yeOldePub)
 {
     
     if (yeOldePub.Bartender.MessageLog != null) yeOldePub.Bartender.MessageLog.TryDequeue()
 }
Esempio n. 13
0
        public override void Activate(YeOldePub yeOldePub)
        {
            while (_hasGoneHome is false)
            {
                switch (CurrentState)
                {
                case RunState.WalkingToBar:
                    MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} entered and is walking to the bar");
                    Thread.Sleep(1000);
                    yeOldePub.PatronsWaitingForBeer.Enqueue(this);
                    CurrentState = RunState.WaitingForBeer;
                    break;

                case RunState.WaitingForBeer:
                    if (PintGlass is null)
                    {
                        MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} is waiting for a pint of beer");
                        Thread.Sleep(TimeSpentWaiting);     // Give the bartender som time before trying again
                    }
                    else
                    {
                        MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} got a pint of beer");
                        MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} is waiting for an available chair");
                        DequeuePatron(CurrentQueue, this);
                        CurrentState = RunState.WaitingForChair;
                    }

                    break;

                case RunState.WaitingForChair:
                    yeOldePub.PatronsWaitingForChair.Enqueue(this);

                    //Check to see if patron is first in line
                    var isFirstInQueue = false;
                    while (isFirstInQueue is false)
                    {
                        //Spend time checking
                        Thread.Sleep(TimeSpentWaiting);
                        isFirstInQueue = yeOldePub.PatronsWaitingForChair.TryPeek(out var result);
                        if (this != result)
                        {
                            continue;
                        }
                        foreach (var chair in yeOldePub.Chairs)
                        {
                            if (!(chair.IsAvailable))
                            {
                                continue;
                            }
                            this.Chair        = chair; //Dibs on available chair
                            chair.IsAvailable = false;
                            DequeuePatron(CurrentQueue, this);
                            CurrentState = RunState.GoingToChair;
                        }
                    }

                    break;

                case RunState.GoingToChair:
                    MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} is walking to a chair");
                    Thread.Sleep(TimeSpentWalkingToChair);
                    //_isSitting = true;
                    CurrentState = RunState.DrinkingBeer;
                    break;

                case RunState.DrinkingBeer:
                    //Drink beer
                    MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} is drinking a pint of beer");
                    Thread.Sleep(TimeSpentDrinkingBeer);
                    PintGlass.HasBeer = false;
                    //_isThirsty = false;

                    //Place empty glass on table
                    MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} is done drinking and is getting ready to leave");
                    yeOldePub.Tables.Add(PintGlass);
                    //_isSitting = false;
                    Chair.IsAvailable = true;
                    CurrentState      = RunState.LeavingThePub;
                    break;

                case RunState.LeavingThePub:
                    //Remove patron from pub
                    MessageLog.Enqueue($"{DateTime.UtcNow}: {this.Name} is going home");
                    while (_hasGoneHome is false)
                    {
                        _hasGoneHome = yeOldePub.Patrons.TryRemove(this.Name, out _);
                    }
                    _hasGoneHome = true;
                    break;
                }
                //CheckState(yeOldePub);
            }
        }