예제 #1
0
 public Task<Room> AddRoomAsync(Room room)
 {
     return _factory.ExecuteAsync<IRoomRepository, Room>(async roomRepository =>
     {
         var existing = (await roomRepository.AnyAsync(d => d.Name == room.Name).ConfigureAwait(false));
         if (existing)
         {
             throw new RoomAlreadyExistsException("Room '" + room.Name + "' already exists.");
         }
         room.Id = await roomRepository.InsertAsync(room.ToEntity()).ConfigureAwait(false);
         return room;
     });
 }
예제 #2
0
        public RoomAccesActor(IRoomService roomService)
        {
            _roomService = roomService;
            Receive<LoadActiveRoomsMessage>(message =>
            {
                var sender = Sender;
                var self = Self;
                _roomService.GetRoomsAsync().SafelyPipeTo(
                    task => new ActiveRoomsMessage(task.Result),
                    task => new FailedToLoadActiveRoomsMessage(task.Exception?.InnerException),
                    sender, self);
            });

            Receive<CreateRoomMessage>(message =>
            {
                var sender = Sender;
                var self = Self;

                var room = new Room
                {
                    Name = message.Name,
                    CreateTime = message.CreateTime,
                    Users = new List<User>()
                };

                _roomService.AddRoomAsync(room).SafelyPipeTo(
                        task => new RoomCreatedMessage(task.Result),
                        task => new FailedToCreateMessage(message.Creator, task.Exception?.InnerException), 
                        sender, self);
            });

            Receive<GetUsersInRoomMessage>(message =>
            {
                var sender = Sender;
                var self = Self;
                _roomService.GetUsersInRoomAsync(message.RoomId).SafelyPipeTo(
                    task => new UsersInRoomMessage(message.RoomId, task.Result.ToList()),
                    task => new FailedToGetUsersInRoomMessage(message.RoomId, task.Exception?.InnerException),
                    sender, self);
            });

            Receive<RemoveRoomMessage>(message =>
            {
                var sender = Sender;
                var self = Self;
                _roomService.RemoveRoomAsync(message.Room).PipeFailureTo(
                    task => new FailedToRemoveRoomMessage(message.Room.Id, task.Exception?.InnerException), 
                    sender, self);
            });
        }
예제 #3
0
 public Task RemoveRoomAsync(Room room)
 {
     room.IsAlive = false;
     return _factory.ExecuteAsync<IRoomRepository>(roomRepository => 
                 roomRepository.UpdateAsync(room.ToEntity()));
 }