Exemplo n.º 1
0
        public IEvent Execute(AggregatorState currentState, IEvent e)
        {
            switch (currentState)
            {
            case AggregatorState.Aggregating:
                if (e.Type == EventType.Shipment)
                {
                    this.shipmentReceived = true;
                }
                if (e.Type == EventType.OnHand)
                {
                    this.onHandReceived = true;
                }

                this.aggregatedData += e.Data;
                if (this.onHandReceived && this.shipmentReceived)
                {
                    return(new ResolveEvent
                    {
                        Data = this.aggregatedData
                    });
                }

                break;

            default:
                break;
            }

            return(null);
        }
Exemplo n.º 2
0
        public void MoveNext(IEvent e)
        {
            this.CurrentState = Next(e.Type);
            IEvent isComplete = _aggregate.Execute(this.CurrentState, e);

            if (isComplete != null)
            {
                MoveNext(isComplete);
            }
        }
Exemplo n.º 3
0
 public AggregatorMachine()
 {
     CurrentState = AggregatorState.Inactive;
     _aggregate   = new Aggregate();
     transitions  = new Dictionary <Transition, AggregatorState>
     {
         { new Transition(AggregatorState.Inactive, EventType.OnHand), AggregatorState.Aggregating },
         { new Transition(AggregatorState.Inactive, EventType.Shipment), AggregatorState.Aggregating },
         { new Transition(AggregatorState.Aggregating, EventType.OnHand), AggregatorState.Aggregating },
         { new Transition(AggregatorState.Aggregating, EventType.Shipment), AggregatorState.Aggregating },
         { new Transition(AggregatorState.Aggregating, EventType.Resolve), AggregatorState.Resolved },
     };
 }
Exemplo n.º 4
0
 public static object Miner(this AggregatorState ext, Func <MinerStatistics, object> val)
 {
     return(ext == null ?  null : val(ext.MinerApiInfo));
 }
Exemplo n.º 5
0
        public static object Card(this AggregatorState ext, int id, Func <CardParam, object> val)
        {
            var card = ext?.Cards.FirstOrDefault(x => x.Id == id);

            return(card == null ? null : val(card));
        }
Exemplo n.º 6
0
 public void UpdateState(AggregatorState currentState)
 {
     _currentState = currentState;
 }
Exemplo n.º 7
0
 public Transition(AggregatorState currentState, EventType eventType)
 {
     _currentState = currentState;
     _eventType    = eventType;
 }
Exemplo n.º 8
0
 public Result Validate(IBaseConditionModel model, AggregatorState systemState)
 {
     _systemState = systemState;
     return(Visit(model));
 }