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); }
public ServerSendMessage(ClientData source, ISessionsRepository sessionsRepository, IPacketFormatter packetFormatter, string messageToSend) : base(source, sessionsRepository, packetFormatter, Operation.Message, Status.Ok) { _messageToSend = messageToSend; _sourceSessionId = SessionsRepository.GetSessionId(Source); }
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"); } }
public ServerInvite(ClientData source, int destinationId, ISessionsRepository sessionsRepository, IPacketFormatter packetFormatter) : base(source, sessionsRepository, packetFormatter, Operation.Invite, Status.Ok) { _destinationId = destinationId; _sourceSessionId = SessionsRepository.GetSessionId(Source); }
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); }
protected override void ValidateAndInitializeCommandArguments() { Destination = Source; DestinationSessionId = SessionsRepository.GetSessionId(Source); }