예제 #1
0
        private void ValidateAndInitializeSessionIds()
        {
            if (Destination == Source)
            {
                throw new InvalidOperationException("Client cannot accept invitation (or invite) himself");
            }
            if (!Source.GotInviteFrom(Destination.Id))
            {
                throw new InvalidOperationException(
                          $"Client have not received an invitation from a client with ID {Destination.Id}");
            }

            DestinationSessionId = SessionsRepository.GetSessionId(Destination);
            var sourceSessionId = SessionsRepository.GetSessionId(Source);

            if (DestinationSessionId == sourceSessionId)
            {
                throw new InvalidOperationException($"Client {Destination.Id} is already in your session");
            }

            if (SessionsRepository.IsSessionFull(sourceSessionId))
            {
                throw new InvalidOperationException("Client's session is full");
            }
            if (SessionsRepository.IsSessionFull(DestinationSessionId))
            {
                throw new InvalidOperationException("Inviter session is full");
            }

            SessionsRepository.UpdateClientSessionId(Source, DestinationSessionId);
        }
예제 #2
0
 public ServerSendMessage(ClientData source, ISessionsRepository sessionsRepository,
                          IPacketFormatter packetFormatter, string messageToSend)
     : base(source, sessionsRepository, packetFormatter, Operation.Message, Status.Ok)
 {
     _messageToSend   = messageToSend;
     _sourceSessionId = SessionsRepository.GetSessionId(Source);
 }
예제 #3
0
        private void ValidateAndInitializeSessionIds()
        {
            if (Destination == Source)
            {
                throw new InvalidOperationException("Client cannot invite himself to the session");
            }

            if (SessionsRepository.IsSessionFull(_sourceSessionId))
            {
                throw new InvalidOperationException("Session is full");
            }

            if (SessionsRepository.IsSessionFull(DestinationSessionId))
            {
                throw new InvalidOperationException($"Client's {Destination.Id} session is full");
            }

            if (Destination.GotInviteFrom(Source.Id))
            {
                throw new InvalidOperationException(
                          $"Already invited client with ID: {Destination.Id}");
            }

            DestinationSessionId = SessionsRepository.GetSessionId(Destination);
            if (DestinationSessionId == _sourceSessionId)
            {
                throw new InvalidOperationException("Invited client is already in this session");
            }
        }
예제 #4
0
 public ServerInvite(ClientData source, int destinationId, ISessionsRepository sessionsRepository,
                     IPacketFormatter packetFormatter)
     : base(source, sessionsRepository, packetFormatter, Operation.Invite, Status.Ok)
 {
     _destinationId   = destinationId;
     _sourceSessionId = SessionsRepository.GetSessionId(Source);
 }
예제 #5
0
        public override void Execute()
        {
            base.Execute();
            Source.RemoveAllPendingInvites();
            Destination.RemoveAllPendingInvites();

            var sourceNewSessionId = SessionsRepository.GetSessionId(Source);
            var initialPacket      = new Packet(Operation.GetId, Status.Initial, sourceNewSessionId, Source.Id);

            Source.SendTo(PacketFormatter.Serialize(initialPacket));
        }
        protected override void ValidateAndInitializeCommandArguments()
        {
            Destination          = Source;
            DestinationSessionId = SessionsRepository.GetSessionId(Destination);

            // source is only client in session
            if (!SessionsRepository.IsSessionFull(DestinationSessionId))
            {
                throw new InvalidOperationException(
                          "Closing communication session and moving to new one is possible only if other client is in your session");
            }

            SessionsRepository.UpdateClientSessionId(Destination, Guid.NewGuid());
            DestinationSessionId = SessionsRepository.GetSessionId(Destination);
        }
예제 #7
0
 protected override void ValidateAndInitializeCommandArguments()
 {
     Destination          = Source;
     DestinationSessionId = SessionsRepository.GetSessionId(Source);
 }