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(); });
        }
        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());
        }
Exemple #3
0
 public override void SmallCoffee()
 {
     Console.WriteLine("WorkingState: make small coffee");
     CoffeeMachine.TransistionTo(new WorkingState(5));
 }
Exemple #4
0
 public override void LargeCoffee()
 {
     Console.WriteLine("WorkingState: make large coffee");
     CoffeeMachine.TransistionTo(new WorkingState(10));
 }
 public void SetContext(CoffeeMachine coffeeMachine)
 {
     CoffeeMachine = coffeeMachine;
 }
        public HeatingUpState()
        {
            var task = Task.Delay(TimeSpan.FromSeconds(5));

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