public void Handle(ClientMessage.FilteredSubscribeToStream msg) { var streamAccess = _readIndex.CheckStreamAccess( msg.EventStreamId.IsEmptyString() ? SystemStreams.AllStream : msg.EventStreamId, StreamAccessType.Read, msg.User); if (streamAccess.Granted) { var lastEventNumber = msg.EventStreamId.IsEmptyString() ? (long?)null : _readIndex.GetStreamLastEventNumber(msg.EventStreamId); var lastCommitPos = _readIndex.LastIndexedPosition; SubscribeToStream(msg.CorrelationId, msg.Envelope, msg.ConnectionId, msg.EventStreamId, msg.ResolveLinkTos, lastCommitPos, lastEventNumber, msg.EventFilter, msg.CheckpointInterval); var subscribedMessage = new ClientMessage.SubscriptionConfirmation(msg.CorrelationId, lastCommitPos, lastEventNumber); msg.Envelope.ReplyWith(subscribedMessage); } else { msg.Envelope.ReplyWith( new ClientMessage.SubscriptionDropped(msg.CorrelationId, SubscriptionDropReason.AccessDenied)); } }
private TcpPackage WrapSubscribedToStreamV1(ClientMessage.SubscriptionConfirmation msg) { var dto = new TcpClientMessageDto.SubscriptionConfirmation(msg.LastCommitPosition, msg.LastEventNumber == null ? msg.LastEventNumber : StreamVersionConverter.Downgrade(msg.LastEventNumber.Value)); return(new TcpPackage(TcpCommand.SubscriptionConfirmation, msg.CorrelationId, dto.Serialize())); }
public void when_wrapping_subscribe_to_stream_confirmation_with_null_last_event_number_should_not_change() { var msg = new ClientMessage.SubscriptionConfirmation(Guid.NewGuid(), 100, null); var package = _dispatcher.WrapMessage(msg, _version); Assert.IsNotNull(package, "Package is null"); Assert.AreEqual(TcpCommand.SubscriptionConfirmation, package.Value.Command, "TcpCommand"); var dto = package.Value.Data.Deserialize <TcpClientMessageDto.SubscriptionConfirmation>(); Assert.IsNotNull(dto, "DTO is null"); Assert.IsNull(dto.LastEventNumber); }
when_wrapping_subscribe_to_stream_confirmation_when_stream_deleted_should_not_downgrade_last_event_number_for_v2_clients() { var msg = new ClientMessage.SubscriptionConfirmation(Guid.NewGuid(), 100, long.MaxValue); var package = _dispatcher.WrapMessage(msg, (byte)ClientVersion.V2); Assert.IsNotNull(package, "Package is null"); Assert.AreEqual(TcpCommand.SubscriptionConfirmation, package.Value.Command, "TcpCommand"); var dto = package.Value.Data.Deserialize <TcpClientMessageDto.SubscriptionConfirmation>(); Assert.IsNotNull(dto, "DTO is null"); Assert.AreEqual(long.MaxValue, dto.LastEventNumber, "Last Event Number"); }
public void Handle(ClientMessage.SubscribeToStream msg) { var lastEventNumber = msg.EventStreamId.IsEmptyString() ? (long?)null : _readIndex.GetStreamLastEventNumber(msg.EventStreamId); var lastIndexedPos = _readIndex.LastIndexedPosition; SubscribeToStream(msg.CorrelationId, msg.Envelope, msg.ConnectionId, msg.EventStreamId, msg.ResolveLinkTos, lastIndexedPos, lastEventNumber, EventFilter.None); var subscribedMessage = new ClientMessage.SubscriptionConfirmation(msg.CorrelationId, lastIndexedPos, lastEventNumber); msg.Envelope.ReplyWith(subscribedMessage); }
private TcpPackage WrapSubscribedToStream(ClientMessage.SubscriptionConfirmation msg) { var dto = new TcpClientMessageDto.SubscriptionConfirmation(msg.LastCommitPosition, msg.LastEventNumber); return(new TcpPackage(TcpCommand.SubscriptionConfirmation, msg.CorrelationId, dto.Serialize())); }