public WorkingState(int time)
        {
            _cancellationTokenSource = new CancellationTokenSource();
            var task = Task.Delay(TimeSpan.FromSeconds(time), _cancellationTokenSource.Token);

            task.ContinueWith(x => { CoffeeMachine.TransistionTo(new IdleState()); _cancellationTokenSource.Dispose(); });
        }
Ejemplo n.º 2
0
        public static void Execute()
        {
            var machine = new CoffeeMachine();

            machine.LargeCoffee();

            Task.Delay(TimeSpan.FromSeconds(7)).ContinueWith(x => machine.SmallCoffee());

            Task.Delay(TimeSpan.FromSeconds(15)).ContinueWith(x => machine.LargeCoffee());

            Task.Delay(TimeSpan.FromSeconds(20)).ContinueWith(x => machine.LargeCoffee());
        }
Ejemplo n.º 3
0
 public override void SmallCoffee()
 {
     Console.WriteLine("WorkingState: make small coffee");
     CoffeeMachine.TransistionTo(new WorkingState(5));
 }
Ejemplo n.º 4
0
 public override void LargeCoffee()
 {
     Console.WriteLine("WorkingState: make large coffee");
     CoffeeMachine.TransistionTo(new WorkingState(10));
 }
Ejemplo n.º 5
0
 public void SetContext(CoffeeMachine coffeeMachine)
 {
     CoffeeMachine = coffeeMachine;
 }
        public HeatingUpState()
        {
            var task = Task.Delay(TimeSpan.FromSeconds(5));

            task.ContinueWith(x => CoffeeMachine.TransistionTo(new IdleState()));
        }