Example #1
0
        private void storeEvent(Session session, BaseClientEvent clientEvent)
        {
            clientEvent.Id = _nextEventId++;

            var events = _eventsBySessionId.GetOrAdd(session.Id, k => new List<BaseClientEvent>());
            lock (events)
            {
                events.Add(clientEvent);
            }
        }
Example #2
0
        public void HandleCommand(Session session, RollDiceCommand command)
        {
            var rollSpec = DiceService.ParseFormula(command.DiceRollFormula);
            var roll = DiceService.RollDice(rollSpec);

            var newEvent = createEvent(command);
            newEvent.Roll = roll;
            storeEvent(session, newEvent);

            //Mappings
            Mapper.CreateMap<BaseClientEvent, BaseClientEventViewModel>()
                  .Include<ClientRolledDiceEvent, ClientRolledDiceEventViewModel>();
            Mapper.CreateMap<ClientRolledDiceEvent, ClientRolledDiceEventViewModel>();
            Mapper.CreateMap<DiceGroupRoll, DiceGroupRollViewModel>();

            var viewModel = Mapper.Map(newEvent, newEvent.GetType(), typeof(ClientRolledDiceEventViewModel));
            _clients.Group(session.Id).onNewMessage(viewModel);
        }
Example #3
0
        public IEnumerable<BaseClientEvent> GetSessionEvents(Session session)
        {
            var events = _eventsBySessionId
                .GetOrAdd(session.Id, k => new List<BaseClientEvent>())
                .ToList();

            return events;
        }
Example #4
0
        public void HandleCommand(Session session, SendMessageCommand command)
        {
            var newEvent = createEvent(command);
            storeEvent(session, newEvent);

            //Mappings
            Mapper.CreateMap<BaseClientEvent, BaseClientEventViewModel>()
                  .Include<ClientSentMessageEvent, ClientSentMessageEventViewModel>();
            Mapper.CreateMap<ClientSentMessageEvent, ClientSentMessageEventViewModel>();

            var viewModel = Mapper.Map(newEvent, newEvent.GetType(), typeof(ClientSentMessageEventViewModel));
            _clients.Group(session.Id).onNewMessage(viewModel);
        }
Example #5
0
        public Session CreateSession()
        {
            var key = createKey();
            var newSession = new Session();
            var retryAttempts = 0;
            while (!_sessionsById.TryAdd(key, newSession))
            {
                key = createKey();
                if (retryAttempts++ >= 100)
                    throw new Exception("Cannot create new session - cannot find a new unique sesion key!");
            }

            newSession.Id = key;
            return newSession;
        }