Esempio n. 1
0
        public static void Test2()
        {
            var orderItem = new OrderItemEntity();

            orderItem.ProductId  = 1;
            orderItem.SupplierId = 1;
            orderItem.SetStatus(OrderItemStatus.Enquired);

            var stateMachine = new StateMachine <OrderItemStatus, EventType>(() => orderItem.Status, status => orderItem.SetStatus(status));

            stateMachine.Configure(OrderItemStatus.Enquired)
            .Permit(EventType.SupplierConfirm, OrderItemStatus.SupplierConfirmed)
            .Permit(EventType.Cancel, OrderItemStatus.Cancelled);

            stateMachine.Configure(OrderItemStatus.SupplierConfirmed)
            .OnEntry(() => { SupplierConfirm(orderItem, orderItem.Status, stateMachine.State); })
            .OnExit(() => { SupplierConfirmed(orderItem, stateMachine.State); })
            .Permit(EventType.Confirm, OrderItemStatus.Confirmed)
            .Permit(EventType.Cancel, OrderItemStatus.Cancelled);

            Console.WriteLine(stateMachine.State);
            Console.WriteLine(orderItem.Status);

            stateMachine.Fire(EventType.SupplierConfirm);
            Console.WriteLine(stateMachine.State);
            Console.WriteLine(orderItem.Status);

            var validate1 = stateMachine.IsInState(OrderItemStatus.SupplierConfirmed);

            stateMachine.Fire(EventType.Cancel);
            Console.WriteLine(stateMachine.State);
            Console.WriteLine(orderItem.Status);

            string graph = UmlDotGraph.Format(stateMachine.GetInfo());

            Console.ReadLine();
        }
Esempio n. 2
0
 private static void SupplierConfirmed(OrderItemEntity item, OrderItemStatus status)
 {
     Console.WriteLine($"Supplier Confirmed Exit. Status {status}");
 }
Esempio n. 3
0
 private static void SupplierConfirm(OrderItemEntity item, OrderItemStatus oldStatus, OrderItemStatus newStatus)
 {
     Console.WriteLine($"Supplier Confirmed Entry. Old Status {oldStatus},New Status {newStatus}");
 }