//private IEnumerable<IStateSource<V>> _inputStateSources;

        //protected StateAggregator() {
        //}

        //protected StateAggregator(IEnumerable<IStateSource<V>> inputStateSources) {
        //    _inputStateSources = inputStateSources;
        //}

        //public void Aggregate() {
        //    Aggregate(_inputStateSources);
        //}

        public void Aggregate(IEnumerable <IStateSource <V> > inputStateSources)
        {
            if (inputStateSources == null)
            {
                throw new ArgumentNullException("inputStateSources");
            }

            IStateSource <V>[] inputStateSourcesArray = inputStateSources.ToArray();
            if (inputStateSourcesArray.Length == 0)
            {
                State = default(V);
                return;
            }
            IStateSource <V> firstCommand = inputStateSourcesArray[0];

            if (inputStateSourcesArray.Length == 1)
            {
                State = _GetValueFromState(firstCommand);
                // This is part of two things: context and channel
                //Context: Getting the channel states set in the context; effect is being
                //aggregated into it.
                //Channel: Getting its state set from its context sources.
                return;
            }

            IStateSource <V> state = inputStateSourcesArray.Aggregate(_Combinator);

            State = _GetValueFromState(state);
        }
        //public CommandStateAggregator() {
        //}

        //public CommandStateAggregator(IEnumerable<IStateSource<Command>> stateSources)
        //    : base(stateSources) {
        //}

        //Not being called because there is only a single state; nothing to combine.
        protected override IStateSource <Command> _Combinator(IStateSource <Command> left, IStateSource <Command> right)
        {
            if (left == null)
            {
                return(right);
            }
            if (right == null)
            {
                return(left);
            }

            Command value1 = left.State;
            Command value2 = right.State;

            if (value1 == null)
            {
                return(right);
            }

            if (value2 == null)
            {
                return(left);
            }

            return(new CommandStateSource(value1.Combine(value2)));
        }
 private V _GetValueFromState(IStateSource <V> state)
 {
     return((state != null) ? state.State : default(V));
 }
 abstract protected IStateSource <V> _Combinator(IStateSource <V> left, IStateSource <V> right);
Beispiel #5
0
 public WebSocketState(IContext context, IStateSource source, HttpConfig config)
 {
     _source = source;
     _config = config;
     context.FireNextRead(FrameRequest.CreateConnectedRequest());
 }
Beispiel #6
0
 public HttpState(IStateSource source, HttpConfig config)
 {
     _source    = source;
     _config    = config;
     _keepalive = false;
 }
Beispiel #7
0
 public void RemoveStateSource(IStateSource stateSource)
 {
     _stateSources.Remove(stateSource);
     stateSource.StateUpdated -= UpdateWorldState;
 }
Beispiel #8
0
 public void AddStateSource(IStateSource stateSource)
 {
     _stateSources.Add(stateSource);
     stateSource.StateUpdated += UpdateWorldState;
 }