コード例 #1
0
ファイル: ISessionService.cs プロジェクト: seshbot/campaigns
        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);
            }
        }
コード例 #2
0
ファイル: ISessionService.cs プロジェクト: seshbot/campaigns
        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);
        }
コード例 #3
0
ファイル: ISessionService.cs プロジェクト: seshbot/campaigns
        public IEnumerable<BaseClientEvent> GetSessionEvents(Session session)
        {
            var events = _eventsBySessionId
                .GetOrAdd(session.Id, k => new List<BaseClientEvent>())
                .ToList();

            return events;
        }
コード例 #4
0
ファイル: ISessionService.cs プロジェクト: seshbot/campaigns
        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);
        }
コード例 #5
0
ファイル: ISessionService.cs プロジェクト: seshbot/campaigns
        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;
        }