public ConsumerPushResult PushMessageToClient(ResolvedEvent ev)
        {
            if (_state == null)
            {
                return ConsumerPushResult.NoMoreCapacity;
            }

            if (_state.AvailableCapacity == 0)
            {
                return ConsumerPushResult.NoMoreCapacity;
            }


            uint bucket = GetAssignmentId(ev);

            if (_state.Assignments[bucket].State != BucketAssignment.BucketState.Assigned)
            {
                _state.AssignBucket(bucket);
            }

            if (!_state.Assignments[bucket].Node.Client.Push(ev))
            {
                return ConsumerPushResult.Skipped;
            }

            _state.RecordEventSent(bucket);
            return ConsumerPushResult.Sent;
        }
        public static string SmartFormat(ResolvedEvent evnt, ICodec targetCodec)
        {
            var dto = CreateDataDto(evnt);

            switch (targetCodec.ContentType)
            {
                case ContentType.Xml:
                case ContentType.ApplicationXml:
                    {
                        var serializeObject = JsonConvert.SerializeObject(dto.data);
                        var deserializeXmlNode = JsonConvert.DeserializeXmlNode(serializeObject, "data");
                        return deserializeXmlNode.InnerXml;
                    }
                case ContentType.Json:
                    return targetCodec.To(dto.data);


                case ContentType.Atom:
                case ContentType.EventXml:
                {
                    var serializeObject = JsonConvert.SerializeObject(dto);
                    var deserializeXmlNode = JsonConvert.DeserializeXmlNode(serializeObject, "event");
                    return deserializeXmlNode.InnerXml;
                }

                case ContentType.EventJson:
                    return targetCodec.To(dto);


                default:
                    throw new NotSupportedException();
            }
        }
Пример #3
0
 public OutstandingMessage(Guid eventId, PersistentSubscriptionClient handlingClient, ResolvedEvent resolvedEvent, int retryCount) : this()
 {
     EventId = eventId;
     HandlingClient = handlingClient;
     ResolvedEvent = resolvedEvent;
     RetryCount = retryCount;
 }
Пример #4
0
 public static string GetJsonEventReadResult(ResolvedEvent evnt, bool dataJson = true, bool metadataJson = true)
 {
     return string.Format(JsonEventReadFormat,
                          WrapIntoQuotes(evnt.Event.EventStreamId),
                          evnt.Event.EventNumber,
                          WrapIntoQuotes(evnt.Event.EventType),
                          dataJson ? JsonData : WrapIntoQuotes(AsString(evnt.Event.Data)),
                          metadataJson ? JsonMetadata : WrapIntoQuotes(AsString(evnt.Event.Metadata)));
 }
        private string GetLinkToFor(ResolvedEvent ev)
        {
            if (ev.Event == null) // Unresolved link so just use the bad/deleted link data.
            {
                return Encoding.UTF8.GetString(ev.Link.Data);
            }

            return string.Format("{0}@{1}", ev.Event.EventNumber, ev.Event.EventStreamId);
        }
        public void BeginParkMessage(ResolvedEvent ev,string reason, Action<ResolvedEvent, OperationResult> completed)
        {
            var metadata = new ParkedMessageMetadata {Added = DateTime.Now, Reason = reason, SubscriptionEventNumber = ev.OriginalEventNumber};
            
            string data = GetLinkToFor(ev);

            var parkedEvent = new Event(Guid.NewGuid(), SystemEventTypes.LinkTo, false, data, metadata.ToJson());

            _ioDispatcher.WriteEvent(_parkedStreamId, ExpectedVersion.Any, parkedEvent, SystemAccount.Principal, x => WriteStateCompleted(completed, ev, x));
        }
        public ReadAllResult(ResolvedEvent[] events, int maxCount, TFPos currentPos, TFPos nextPos, TFPos prevPos, long tfEofPosition)
        {
            Ensure.NotNull(events, "events");

            Events = events;
            MaxCount = maxCount;
            CurrentPos = currentPos;
            NextPos = nextPos;
            PrevPos = prevPos;
            TfEofPosition = tfEofPosition;
        }
        public override ConsumerPushResult PushMessageToClient(ResolvedEvent ev)
        {
            for (int i = 0; i < Clients.Count; i++)
            {
                if (Clients.Peek().Push(ev))
                {
                    return ConsumerPushResult.Sent;
                }
                var c = Clients.Dequeue();
                Clients.Enqueue(c);
            }

            return ConsumerPushResult.NoMoreCapacity;
        }
 public virtual ConsumerPushResult PushMessageToClient(ResolvedEvent ev)
 {
     for (int i = 0; i < Clients.Count; i++)
     {
         var c = Clients.Dequeue();
         var pushed = c.Push(ev);
         Clients.Enqueue(c);
         if (pushed)
         {
             return ConsumerPushResult.Sent;
         }
     }
     return ConsumerPushResult.NoMoreCapacity;
 }
Пример #10
0
 public void can_handle_read_events_completed()
 {
     _edp.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success,
             new[]
     {
         ResolvedEvent.ForUnresolvedEvent(
             new EventRecord(
                 1, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "a", ExpectedVersion.Any,
                 DateTime.UtcNow,
                 PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                 "event_type", new byte[0], new byte[0]), 0)
     }, null, false, "", 2, 4, false, 100));
 }
Пример #11
0
        when_wrapping_stream_event_appeared_with_deleted_event_should_not_downgrade_version_for_v2_clients()
        {
            var msg = new ClientMessage.StreamEventAppeared(Guid.NewGuid(),
                                                            ResolvedEvent.ForUnresolvedEvent(CreateDeletedEventRecord(), 0));

            var package = _dispatcher.WrapMessage(msg, (byte)ClientVersion.V2);

            Assert.IsNotNull(package, "Package is null");
            Assert.AreEqual(TcpCommand.StreamEventAppeared, package.Value.Command, "TcpCommand");

            var dto = package.Value.Data.Deserialize <StreamEventAppeared>();

            Assert.IsNotNull(dto, "DTO is null");
            Assert.AreEqual(long.MaxValue, dto.Event.Event.EventNumber, "Event Number");
        }
        public static HttpClientMessageDto.ReadEventCompletedText CreateDataDto(ResolvedEvent evnt)
        {
            var dto = new HttpClientMessageDto.ReadEventCompletedText(evnt);
            if (evnt.Event.Flags.HasFlag(PrepareFlags.IsJson))
            {
                var deserializedData = Codec.Json.From<object>((string) dto.data);
                var deserializedMetadata = Codec.Json.From<object>((string) dto.metadata);

                if (deserializedData != null)
                    dto.data = deserializedData;
                if (deserializedMetadata != null)
                    dto.metadata = deserializedMetadata;
            }
            return dto;
        }
        private void DeliverEvent(
            EventStore.Core.Data.ResolvedEvent @event, long lastCommitPosition, TFPos currentFrom)
        {
            _deliveredEvents++;
            EventRecord positionEvent    = (@event.Link ?? @event.Event);
            TFPos       receivedPosition = @event.OriginalPosition.Value;

            if (currentFrom > receivedPosition)
            {
                throw new Exception(
                          string.Format(
                              "ReadFromTF returned events in incorrect order.  Last known position is: {0}.  Received position is: {1}",
                              currentFrom, receivedPosition));
            }
            TFPos originalPosition;

            if (@event.IsResolved)
            {
                if (positionEvent.Metadata != null && positionEvent.Metadata.Length > 0)
                {
                    var parsedPosition =
                        positionEvent.Metadata.ParseCheckpointTagJson().Position;
                    originalPosition = parsedPosition != new TFPos(long.MinValue, long.MinValue)
                                           ? parsedPosition
                                           : new TFPos(-1, @event.OriginalEvent.LogPosition);
                }
                else
                {
                    originalPosition = new TFPos(-1, @event.OriginalEvent.LogPosition);
                }
            }
            else
            {
                originalPosition = receivedPosition;
            }

            _publisher.Publish(
                new ReaderSubscriptionMessage.CommittedEventDistributed(
                    EventReaderCorrelationId,
                    new ResolvedEvent(
                        positionEvent.EventStreamId, positionEvent.EventNumber, @event.Event.EventStreamId,
                        @event.Event.EventNumber, @event.Link != null, receivedPosition,
                        originalPosition, @event.Event.EventId, @event.Event.EventType,
                        (@event.Event.Flags & PrepareFlags.IsJson) != 0, @event.Event.Data, @event.Event.Metadata,
                        @event.Link == null ? null : @event.Link.Metadata, positionEvent.TimeStamp),
                    _stopOnEof ? (long?)null : receivedPosition.PreparePosition,
                    100.0f * positionEvent.LogPosition / lastCommitPosition, source: this.GetType()));
        }
        private void PublishCommand(ResolvedEvent resolvedEvent)
        {
            var command = resolvedEvent.Event.EventType;

            Log.Debug("Response received: {command}", command);
            switch (command)
            {
            case "$measured": {
                var body = resolvedEvent.Event.Data.ParseJson <PartitionMeasuredResponse>();
                _publisher.Publish(
                    new PartitionMeasured(
                        _workerId,
                        _masterProjectionId,
                        Guid.ParseExact(body.SubscriptionId, "N"),
                        body.Partition,
                        body.Size));
                break;
            }

            case "$progress": {
                var body = resolvedEvent.Event.Data.ParseJson <PartitionProcessingProgressResponse>();
                _publisher.Publish(
                    new PartitionProcessingProgress(
                        _workerId,
                        _masterProjectionId,
                        Guid.ParseExact(body.SubscriptionId, "N"),
                        body.Progress));
                break;
            }

            case "$result": {
                var body = resolvedEvent.Event.Data.ParseJson <PartitionProcessingResultResponse>();
                _publisher.Publish(
                    new PartitionProcessingResult(
                        _workerId,
                        _masterProjectionId,
                        Guid.ParseExact(body.SubscriptionId, "N"),
                        body.Partition,
                        Guid.ParseExact(body.CausedBy, "N"),
                        body.Position,
                        body.Result));
                break;
            }

            default:
                throw new Exception("Unknown response: " + command);
            }
        }
Пример #15
0
        private void DeliverEvent(EventStore.Core.Data.ResolvedEvent pair, float progress, ref int sequenceNumber)
        {
            EventRecord positionEvent = pair.OriginalEvent;

            if (positionEvent.EventNumber != sequenceNumber)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Event number {0} was expected in the stream {1}, but event number {2} was received",
                              sequenceNumber, _streamName, positionEvent.EventNumber));
            }
            sequenceNumber = positionEvent.EventNumber + 1;
            var resolvedEvent = new ResolvedEvent(pair, null);

            string deletedPartitionStreamId;

            if (resolvedEvent.IsLinkToDeletedStream && !resolvedEvent.IsLinkToDeletedStreamTombstone)
            {
                return;
            }

            bool isDeletedStreamEvent = StreamDeletedHelper.IsStreamDeletedEventOrLinkToStreamDeletedEvent(resolvedEvent, out deletedPartitionStreamId);

            if (isDeletedStreamEvent)
            {
                var deletedPartition = deletedPartitionStreamId;

                if (_produceStreamDeletes)
                {
                    _publisher.Publish(
                        //TODO: publish both link and event data
                        new ReaderSubscriptionMessage.EventReaderPartitionDeleted(
                            EventReaderCorrelationId, deletedPartition, source: this.GetType(), lastEventNumber: -1,
                            deleteEventOrLinkTargetPosition: null, deleteLinkOrEventPosition: resolvedEvent.EventOrLinkTargetPosition,
                            positionStreamId: resolvedEvent.PositionStreamId,
                            positionEventNumber: resolvedEvent.PositionSequenceNumber));
                }
            }

            else if (!resolvedEvent.IsStreamDeletedEvent)
            {
                _publisher.Publish(
                    //TODO: publish both link and event data
                    new ReaderSubscriptionMessage.CommittedEventDistributed(
                        EventReaderCorrelationId, resolvedEvent, _stopOnEof ? (long?)null : positionEvent.LogPosition,
                        progress, source: this.GetType()));
            }
        }
Пример #16
0
        public new void When()
        {
            _ab12Tag = new Dictionary <string, int> {
                { "a", 1 }, { "b", 2 }
            };
            _abStreams = new[] { "a", "b" };

            _distibutionPointCorrelationId = Guid.NewGuid();
            _fakeTimeProvider = new FakeTimeProvider();
            _edp = new MultiStreamEventReader(
                _ioDispatcher, _bus, _distibutionPointCorrelationId, null, 0, _abStreams, _ab12Tag, false,
                _fakeTimeProvider);
            _edp.Resume();
            _firstEventId  = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success,
                    new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any, _fakeTimeProvider.Now,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
            }, null, false, "", 2, 1, true, 200));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "b", 100, 100, ReadStreamResult.Success,
                    new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 100, Guid.NewGuid(), _secondEventId, 100, 0, "b", ExpectedVersion.Any, _fakeTimeProvider.Now,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
            }, null, false, "", 3, 2, true, 200));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 2, 1, true, 400));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "b", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 3, 2, true, 400));
            _fakeTimeProvider.AddTime(TimeSpan.FromMilliseconds(500));
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    _distibutionPointCorrelationId, "a", 100, 100, ReadStreamResult.Success, new ResolvedEvent[] { }, null, false, "", 2, 1, true, 600));
        }
        public void can_handle_following_read_events_completed()
        {
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last(x => x.EventStreamId == "a").CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success,
                    new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        3, 250, Guid.NewGuid(), Guid.NewGuid(), 250, 0, "a", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type", new byte[0], new byte[0]))
            }, null, false, "", 4, 4, false, 300));
        }
Пример #18
0
            protected void DeliverEvent(float progress, ResolvedEvent resolvedEvent, TFPos position,
                                        EventStore.Core.Data.ResolvedEvent pair)
            {
                if (resolvedEvent.EventOrLinkTargetPosition <= _reader._lastEventPosition)
                {
                    return;
                }
                _reader._lastEventPosition = resolvedEvent.EventOrLinkTargetPosition;
                //TODO: this is incomplete.  where reading from TF we need to handle actual deletes

                string deletedPartitionStreamId;


                if (resolvedEvent.IsLinkToDeletedStream && !resolvedEvent.IsLinkToDeletedStreamTombstone)
                {
                    return;
                }

                bool isDeletedStreamEvent = StreamDeletedHelper.IsStreamDeletedEventOrLinkToStreamDeletedEvent(
                    resolvedEvent, pair.ResolveResult, out deletedPartitionStreamId);

                if (isDeletedStreamEvent)
                {
                    var deletedPartition = deletedPartitionStreamId;

                    if (_reader._includeDeletedStreamNotification)
                    {
                        _reader._publisher.Publish(
                            //TODO: publish both link and event data
                            new ReaderSubscriptionMessage.EventReaderPartitionDeleted(
                                _reader.EventReaderCorrelationId, deletedPartition, source: this.GetType(),
                                lastEventNumber: -1, deleteEventOrLinkTargetPosition: position,
                                deleteLinkOrEventPosition: resolvedEvent.EventOrLinkTargetPosition,
                                positionStreamId: resolvedEvent.PositionStreamId,
                                positionEventNumber: resolvedEvent.PositionSequenceNumber));
                    }
                }
                else
                {
                    _reader._publisher.Publish(
                        //TODO: publish both link and event data
                        new ReaderSubscriptionMessage.CommittedEventDistributed(
                            _reader.EventReaderCorrelationId, resolvedEvent,
                            _reader._stopOnEof ? (long?)null : position.PreparePosition, progress,
                            source: this.GetType()));
                }
            }
        public new void When()
        {
            _distributionCorrelationId = Guid.NewGuid();
            _fakeTimeProvider          = new FakeTimeProvider();
            var fromPositions = new Dictionary <string, long>();

            fromPositions.Add("$et-eventTypeOne", 0);
            fromPositions.Add("$et-eventTypeTwo", 0);
            _eventReader = new EventByTypeIndexEventReader(_bus, _distributionCorrelationId,
                                                           null, new [] { "eventTypeOne", "eventTypeTwo" },
                                                           false, new TFPos(0, 0),
                                                           fromPositions, true,
                                                           _fakeTimeProvider,
                                                           stopOnEof: true);

            _eventReader.Resume();

            _checkpointStreamCorrelationId = TimeoutRead("$et", Guid.Empty);

            CompleteForwardStreamRead("$et-eventTypeOne", Guid.Empty, new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "$et-eventTypeOne", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd | PrepareFlags.IsJson,
                        "$>", Helper.UTF8NoBom.GetBytes("0@test-stream"), Helper.UTF8NoBom.GetBytes(TFPosToMetadata(new TFPos(50, 50))))),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 150, Guid.NewGuid(), Guid.NewGuid(), 150, 0, "$et-eventTypeOne", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "$>", Helper.UTF8NoBom.GetBytes("1@test-stream"), Helper.UTF8NoBom.GetBytes(TFPosToMetadata(new TFPos(150, 150)))))
            });

            CompleteForwardStreamRead("$et-eventTypeTwo", Guid.Empty, new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 100, Guid.NewGuid(), Guid.NewGuid(), 100, 0, "$et-eventTypeTwo", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd | PrepareFlags.IsJson,
                        "$>", Helper.UTF8NoBom.GetBytes("2@test-stream"), Helper.UTF8NoBom.GetBytes(TFPosToMetadata(new TFPos(100, 100))))),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 200, Guid.NewGuid(), Guid.NewGuid(), 200, 0, "$et-eventTypeTwo", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "$>", Helper.UTF8NoBom.GetBytes("3@test-stream"), Helper.UTF8NoBom.GetBytes(TFPosToMetadata(new TFPos(200, 200)))))
            });
        }
        private void DeliverEvent(
            EventStore.Core.Data.ResolvedEvent @event, long lastCommitPosition, TFPos currentFrom)
        {
            EventRecord linkEvent     = @event.Link;
            EventRecord targetEvent   = @event.Event ?? linkEvent;
            EventRecord positionEvent = (linkEvent ?? targetEvent);

            TFPos receivedPosition = @event.OriginalPosition.Value;

            if (currentFrom > receivedPosition)
            {
                throw new Exception(
                          string.Format(
                              "ReadFromTF returned events in incorrect order.  Last known position is: {0}.  Received position is: {1}",
                              currentFrom, receivedPosition));
            }

            var resolvedEvent = new ResolvedEvent(@event, null);

            string deletedPartitionStreamId;

            if (resolvedEvent.IsLinkToDeletedStream && !resolvedEvent.IsLinkToDeletedStreamTombstone)
            {
                return;
            }

            bool isDeletedStreamEvent = StreamDeletedHelper.IsStreamDeletedEventOrLinkToStreamDeletedEvent(
                resolvedEvent, out deletedPartitionStreamId);

            _publisher.Publish(
                new ReaderSubscriptionMessage.CommittedEventDistributed(
                    EventReaderCorrelationId,
                    resolvedEvent,
                    _stopOnEof ? (long?)null : receivedPosition.PreparePosition,
                    100.0f * positionEvent.LogPosition / lastCommitPosition,
                    source: this.GetType()));
            if (isDeletedStreamEvent)
            {
                _publisher.Publish(
                    new ReaderSubscriptionMessage.EventReaderPartitionDeleted(
                        EventReaderCorrelationId, deletedPartitionStreamId, source: this.GetType(), lastEventNumber: -1,
                        deleteEventOrLinkTargetPosition: resolvedEvent.EventOrLinkTargetPosition,
                        deleteLinkOrEventPosition: resolvedEvent.LinkOrEventPosition,
                        positionStreamId: positionEvent.EventStreamId, positionEventNumber: positionEvent.EventNumber));
            }
        }
 public void cannot_handle_repeated_read_events_completed()
 {
     Assert.Throws <InvalidOperationException>(() => {
         _edp.Handle(
             new ClientMessage.ReadStreamEventsForwardCompleted(
                 _distibutionPointCorrelationId, "stream", 100, 100, ReadStreamResult.Success,
                 new[] {
             ResolvedEvent.ForUnresolvedEvent(
                 new EventRecord(
                     10, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "stream", ExpectedVersion.Any,
                     DateTime.UtcNow,
                     PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin |
                     PrepareFlags.TransactionEnd,
                     "event_type", new byte[0], new byte[0]))
         }, null, false, "", 11, 10, true, 100));
     });
 }
Пример #22
0
        public void cannot_handle_repeated_read_events_completed()
        {
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last().CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        10, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "stream", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type", new byte[0], new byte[0]))
            }, null, false, "", 11, 10, true, 100));
            Assert.AreEqual(1, HandledMessages.OfType <ReaderSubscriptionMessage.Faulted>().Count());
        }
		public ClientMessage.ReadStreamEventsBackwardCompleted ReadOrderStream(
			ClientMessage.ReadStreamEventsBackward message) {
			ResolvedEvent[] events;
			if (!_hasRead) {
				var checkpoint =
					CheckpointTag.FromStreamPositions(0, new Dictionary<string, long> {{"a", 5}, {"b", 5}, {"c", 5}});
				events = IODispatcherTestHelpers.CreateResolvedEvent(message.EventStreamId, "$>",
					"10@a", checkpoint.ToJsonString(new ProjectionVersion(3, 0, 1)));
				_hasRead = true;
			} else {
				events = new ResolvedEvent[0] { };
			}

			return new ClientMessage.ReadStreamEventsBackwardCompleted(message.CorrelationId, message.EventStreamId,
				message.FromEventNumber,
				message.MaxCount, ReadStreamResult.Success, events, null, true, "",
				message.FromEventNumber - events.Length, message.FromEventNumber, true, 10000);
		}
Пример #24
0
        public void cannot_handle_repeated_read_events_completed()
        {
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last(x => x.EventStreamId == "a").CorrelationId;

            Assert.Throws <InvalidOperationException>(() => {
                _edp.Handle(
                    new ClientMessage.ReadStreamEventsForwardCompleted(
                        correlationId, "a", 100, 100, ReadStreamResult.Success,
                        new[]
                {
                    ResolvedEvent.ForUnresolvedEvent(
                        new EventRecord(
                            2, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "a", ExpectedVersion.Any, DateTime.UtcNow,
                            PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                            "event_type", new byte[0], new byte[0]))
                }, null, false, "", 3, 4, false, 100));
            });
        }
Пример #25
0
        public new void When()
        {
            _distibutionPointCorrelationId = Guid.NewGuid();
            _fakeTimeProvider = new FakeTimeProvider();
            _edp = new StreamEventReader(_bus, _distibutionPointCorrelationId, null, "stream", 10, _fakeTimeProvider,
                                         false,
                                         produceStreamDeletes: false);
            _edp.Resume();
            _firstEventId  = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last()
                                .CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        10, 50, Guid.NewGuid(), _firstEventId, 50, 0, "stream", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        11, 100, Guid.NewGuid(), _secondEventId, 100, 0, "stream", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type2", new byte[] { 3 }, new byte[] { 4 }))
            }, null, false, "", 12, 11, true, 200));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>().Last()
                            .CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new ResolvedEvent[] { }, null, false, "", 12, 11, true, 400));
            _fakeTimeProvider.AddToUtcTime(TimeSpan.FromMilliseconds(500));
            correlationId = ((ClientMessage.ReadStreamEventsForward)(_consumer.HandledMessages
                                                                     .OfType <AwakeServiceMessage.SubscribeAwake>().Last().ReplyWithMessage)).CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "stream", 100, 100, ReadStreamResult.Success,
                    new ResolvedEvent[] { }, null, false, "", 12, 11, true, 400));
        }
Пример #26
0
        protected void SendPrerecordedEvent(
            EventStore.Core.Data.ResolvedEvent pair, CheckpointTag positionTag,
            long prerecordedEventMessageSequenceNumber)
        {
            var position       = pair.OriginalEvent;
            var committedEvent = new ReaderSubscriptionMessage.CommittedEventDistributed(
                Guid.Empty,
                new ResolvedEvent(
                    position.EventStreamId, position.EventNumber, pair.Event.EventStreamId, pair.Event.EventNumber,
                    pair.Link != null, new TFPos(-1, position.LogPosition), new TFPos(-1, pair.Event.LogPosition),
                    pair.Event.EventId, pair.Event.EventType, (pair.Event.Flags & PrepareFlags.IsJson) != 0,
                    pair.Event.Data, pair.Event.Metadata, pair.Link == null ? null : pair.Link.Metadata,
                    pair.Event.TimeStamp), null, -1, source: this.GetType());

            _publisher.Publish(
                EventReaderSubscriptionMessage.CommittedEventReceived.FromCommittedEventDistributed(
                    committedEvent, positionTag, null, _projectionCorrelationId,
                    prerecordedEventMessageSequenceNumber));
        }
Пример #27
0
 public new void When()
 {
     _streamEventReader.Handle(
         new ClientMessage.ReadStreamEventsForwardCompleted(
             _distibutionPointCorrelationId, _streamId, 100, 100, ReadStreamResult.Success,
             new[]
     {
         ResolvedEvent.ForUnresolvedEvent(
             new EventRecord(
                 10, 50, Guid.NewGuid(), _firstEventId, 50, 0, _streamId, ExpectedVersion.Any, DateTime.UtcNow,
                 PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                 "event_type1", new byte[] { 1 }, new byte[] { 2 })),
         ResolvedEvent.ForUnresolvedEvent(
             new EventRecord(
                 11, 100, Guid.NewGuid(), _secondEventId, 100, 0, _streamId, ExpectedVersion.Any,
                 DateTime.UtcNow,
                 PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd | PrepareFlags.IsJson,
                 "event_type2", new byte[] { 3 }, new byte[] { 4 }))
     }, null, false, "", 12, 11, true, 200));
 }
Пример #28
0
            public ReadEventCompletedText(ResolvedEvent evnt)
            {
                if (evnt.Event != null)
                {
                    eventStreamId = evnt.Event.EventStreamId;
                    eventNumber = evnt.Event.EventNumber;
                    eventType = evnt.Event.EventType;

                    data = Helper.UTF8NoBom.GetString(evnt.Event.Data ?? Empty.ByteArray);
                    metadata = Helper.UTF8NoBom.GetString(evnt.Event.Metadata ?? Empty.ByteArray);
                }
                else
                {
                    eventStreamId = null;
                    eventNumber = EventNumber.Invalid;
                    eventType = null;
                    data = null;
                    metadata = null;
                }
            }
Пример #29
0
        private void HandleEvents(string stream, long[] eventNumbers)
        {
            string eventType            = "event_type";
            List <ResolvedEvent> events = new List <ResolvedEvent>();

            foreach (long eventNumber in eventNumbers)
            {
                events.Add(
                    ResolvedEvent.ForUnresolvedEvent(
                        new EventRecord(
                            eventNumber, 50 * (eventNumber + 1), Guid.NewGuid(), Guid.NewGuid(), 50 * (eventNumber + 1),
                            0, stream, ExpectedVersion.Any, DateTime.UtcNow,
                            PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                            eventType, new byte[] { 0 }, new byte[] { 0 }
                            )
                        )
                    );
            }

            long start, end;

            if (eventNumbers.Length > 0)
            {
                start = eventNumbers[0];
                end   = eventNumbers[eventNumbers.Length - 1];
            }
            else
            {
                start = _fromSequenceNumber;
                end   = _fromSequenceNumber;
            }

            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                                .Last(x => x.EventStreamId == stream).CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, stream, start, 100, ReadStreamResult.Success, events.ToArray(), null, false, "",
                    start + 1, end, true, 200)
                );
        }
Пример #30
0
        when_wrapping_read_all_events_forward_completed_with_deleted_event_should_not_downgrade_last_event_number_for_v2_clients()
        {
            var events = new ResolvedEvent[] {
                ResolvedEvent.ForUnresolvedEvent(CreateDeletedEventRecord(), 0),
            };
            var msg = new ClientMessage.ReadAllEventsForwardCompleted(Guid.NewGuid(), ReadAllResult.Success, "", events,
                                                                      new StreamMetadata(), true, 10, new TFPos(0, 0),
                                                                      new TFPos(200, 200), new TFPos(0, 0), 100);

            var package = _dispatcher.WrapMessage(msg, (byte)ClientVersion.V2);

            Assert.IsNotNull(package, "Package is null");
            Assert.AreEqual(TcpCommand.ReadAllEventsForwardCompleted, package.Value.Command, "TcpCommand");

            var dto = package.Value.Data.Deserialize <ReadAllEventsCompleted>();

            Assert.IsNotNull(dto, "DTO is null");
            Assert.AreEqual(1, dto.Events.Count(), "Number of events");

            Assert.AreEqual(long.MaxValue, dto.Events[0].Event.EventNumber, "Event Number");
        }
Пример #31
0
        private void DeliverEvent(EventStore.Core.Data.ResolvedEvent pair, float progress)
        {
            _deliveredEvents++;
            var    positionEvent = pair.OriginalEvent;
            string streamId      = positionEvent.EventStreamId;
            long   fromPosition  = _fromPositions.Streams[streamId];

            if (positionEvent.EventNumber != fromPosition)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Event number {0} was expected in the stream {1}, but event number {2} was received",
                              fromPosition, streamId, positionEvent.EventNumber));
            }
            _fromPositions = _fromPositions.UpdateStreamPosition(streamId, positionEvent.EventNumber + 1);
            _publisher.Publish(
                //TODO: publish both link and event data
                new ReaderSubscriptionMessage.CommittedEventDistributed(
                    EventReaderCorrelationId, new ResolvedEvent(pair, null),
                    _stopOnEof ? (long?)null : positionEvent.LogPosition, progress, source: this.GetType()));
        }
        public new void When()
        {
            _ab12Tag = new Dictionary <string, long> {
                { "a", 1 }, { "b", 0 }
            };
            _abStreams = new[] { "a", "b" };

            _distibutionPointCorrelationId = Guid.NewGuid();
            _edp = new MultiStreamEventReader(
                _ioDispatcher, _bus, _distibutionPointCorrelationId, null, 0, _abStreams, _ab12Tag, false,
                new RealTimeProvider());
            _edp.Resume();
            _firstEventId  = Guid.NewGuid();
            _secondEventId = Guid.NewGuid();
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                                .Last(x => x.EventStreamId == "a").CorrelationId;

            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), _firstEventId, 50, 0, "a", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 100, Guid.NewGuid(), _secondEventId, 100, 0, "a", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type2", new byte[] { 3 }, new byte[] { 4 }))
            }, null, false, "", 3, 2, true, 200));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                            .Last(x => x.EventStreamId == "b").CorrelationId;
            _edp.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "b", 100, 100, ReadStreamResult.Success, new ResolvedEvent[0], null, false, "",
                    -1, ExpectedVersion.NoStream, true, 200));
        }
Пример #33
0
        public new void When()
        {
            _distributionCorrelationId = Guid.NewGuid();
            _fakeTimeProvider          = new FakeTimeProvider();
            var fromPositions = new Dictionary <string, long>();

            fromPositions.Add("$et-eventTypeOne", 0);
            fromPositions.Add("$et-eventTypeTwo", 0);
            _eventReader = new EventByTypeIndexEventReader(_bus, _distributionCorrelationId,
                                                           null, new string[] { "eventTypeOne", "eventTypeTwo" },
                                                           false, new TFPos(0, 0),
                                                           fromPositions, true,
                                                           _fakeTimeProvider,
                                                           stopOnEof: true);

            _eventReader.Resume();

            CompleteForwardStreamRead("$et-eventTypeOne", Guid.Empty);
            CompleteForwardStreamRead("$et-eventTypeTwo", Guid.Empty);
            CompleteBackwardStreamRead("$et", Guid.Empty);

            _readAllEventsForwardCorrelationId = TimeoutRead("$all", Guid.Empty);

            CompleteForwardAllStreamRead(_readAllEventsForwardCorrelationId, new[]
            {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "test_stream", ExpectedVersion.Any,
                        _fakeTimeProvider.Now,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "eventTypeOne", new byte[] { 1 }, new byte[] { 2 }), 100),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 150, Guid.NewGuid(), Guid.NewGuid(), 150, 0, "test_stream", ExpectedVersion.Any,
                        _fakeTimeProvider.Now,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "eventTypeTwo", new byte[] { 1 }, new byte[] { 2 }), 200),
            });
        }
Пример #34
0
 public void HandleReadCompleted(ResolvedEvent[] events, int newposition, bool isEndOfStream)
 {
     lock (_lock)
     {
         if ((_state & PersistentSubscriptionState.OutstandingPageRequest) == 0) return;
         _state &= ~PersistentSubscriptionState.OutstandingPageRequest;
         if (_streamBuffer.Live) return;
         foreach (var ev in events)
         {
             _streamBuffer.AddReadMessage(new OutstandingMessage(ev.OriginalEvent.EventId, null, ev, 0));
         }
         if (_streamBuffer.Live)
         {
             SetLive();
         }
         if (isEndOfStream)
         {
             SetLive();
             _streamBuffer.MoveToLive();
             return;
         }
         _lastPulledEvent = newposition;
         TryReadingNewBatch();
         TryPushingMessagesToClients();
     }
 }
Пример #35
0
 private static TcpClientMessageDto.ResolvedEvent[] ConvertToResolvedEvents(ResolvedEvent[] events)
 {
     var result = new TcpClientMessageDto.ResolvedEvent[events.Length];
     for (int i = 0; i < events.Length; ++i)
     {
         result[i] = new TcpClientMessageDto.ResolvedEvent(events[i]);
     }
     return result;
 }
        public new void When()
        {
            _ab12Tag = new Dictionary <string, long> {
                { "a", 1 }, { "b", 2 }
            };
            _abStreams = new[] { "a", "b" };
            _distibutionPointCorrelationId = Guid.NewGuid();
            _eventReader = new MultiStreamEventReader(
                _ioDispatcher, _bus, _distibutionPointCorrelationId, null, 0, _abStreams, _ab12Tag, false,
                new RealTimeProvider());
            _eventReader.Resume();
            var correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                                .Last(x => x.EventStreamId == "a").CorrelationId;

            _eventReader.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        1, 50, Guid.NewGuid(), Guid.NewGuid(), 50, 0, "a", ExpectedVersion.Any, DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd |
                        PrepareFlags.IsJson,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 150, Guid.NewGuid(), Guid.NewGuid(), 150, 0, "a", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type2", new byte[] { 3 }, new byte[] { 4 }))
            }, null, false, "", 3, 2, true, 200));
            //timeout follows
            _eventReader.Handle(
                new ProjectionManagementMessage.Internal.ReadTimeout(correlationId, "a"));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                            .Last(x => x.EventStreamId == "b").CorrelationId;
            _eventReader.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "b", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        2, 100, Guid.NewGuid(), Guid.NewGuid(), 100, 0, "b", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type1", new byte[] { 1 }, new byte[] { 2 })),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        3, 200, Guid.NewGuid(), Guid.NewGuid(), 200, 0, "b", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type2", new byte[] { 3 }, new byte[] { 4 }))
            }, null, false, "", 4, 3, true, 200));
            //timeout follows
            _eventReader.Handle(
                new ProjectionManagementMessage.Internal.ReadTimeout(correlationId, "b"));
            correlationId = _consumer.HandledMessages.OfType <ClientMessage.ReadStreamEventsForward>()
                            .Last(x => x.EventStreamId == "a").CorrelationId;
            _consumer.HandledMessages.Clear();
            //timeout before read completes
            _eventReader.Handle(
                new ProjectionManagementMessage.Internal.ReadTimeout(correlationId, "a"));
            _eventReader.Handle(
                new ClientMessage.ReadStreamEventsForwardCompleted(
                    correlationId, "a", 100, 100, ReadStreamResult.Success,
                    new[] {
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        3, 300, Guid.NewGuid(), Guid.NewGuid(), 300, 0, "a", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd |
                        PrepareFlags.IsJson,
                        "event_type1", new byte[] { 4 }, new byte[] { 6 })),
                ResolvedEvent.ForUnresolvedEvent(
                    new EventRecord(
                        4, 400, Guid.NewGuid(), Guid.NewGuid(), 400, 0, "a", ExpectedVersion.Any,
                        DateTime.UtcNow,
                        PrepareFlags.SingleWrite | PrepareFlags.TransactionBegin | PrepareFlags.TransactionEnd,
                        "event_type2", new byte[] { 6 }, new byte[] { 8 }))
            }, null, false, "", 3, 2, true, 200));
        }
Пример #37
0
            public ReadAllEventsBackwardCompleted(Guid correlationId, ReadAllResult result, string error, ResolvedEvent[] events, 
                                                  StreamMetadata streamMetadata, bool isCachePublic, int maxCount,
                                                  TFPos currentPos, TFPos nextPos, TFPos prevPos, long tfLastCommitPosition)
            {
                Ensure.NotNull(events, "events");

                CorrelationId = correlationId;
                Result = result;
                Error = error;
                Events = events;
                StreamMetadata = streamMetadata;
                IsCachePublic = isCachePublic;
                MaxCount = maxCount;
                CurrentPos = currentPos;
                NextPos = nextPos;
                PrevPos = prevPos;
                TfLastCommitPosition = tfLastCommitPosition;
            }
Пример #38
0
            public ReadEventCompleted(Guid correlationId, string eventStreamId, ReadEventResult result,
                                      ResolvedEvent record, StreamMetadata streamMetadata, bool isCachePublic, string error)
            {
                Ensure.NotNullOrEmpty(eventStreamId, "eventStreamId");
                if (result == ReadEventResult.Success)
                    Ensure.NotNull(record.Event, "record.Event");

                CorrelationId = correlationId;
                EventStreamId = eventStreamId;
                Result = result;
                Record = record;
                StreamMetadata = streamMetadata;
                IsCachePublic = isCachePublic;
                Error = error;
            }
Пример #39
0
 private void RetryMessage(ResolvedEvent @event, int count)
 {
     Log.Debug("Retrying message {0} {1}/{2}", SubscriptionId, @event.OriginalStreamId, @event.OriginalPosition);
     _outstandingMessages.Remove(@event.OriginalEvent.EventId);
     _pushClients.RemoveProcessingMessage(@event.OriginalEvent.EventId);
     _streamBuffer.AddRetry(new OutstandingMessage(@event.OriginalEvent.EventId, null, @event, count + 1));
 }
Пример #40
0
 private void ParkMessage(ResolvedEvent resolvedEvent, string reason, int count)
 {
     _settings.MessageParker.BeginParkMessage(resolvedEvent, reason, (e, result) =>
     {
         if (result != OperationResult.Success)
         {
             if (count < 5)
             {
                 Log.Info("Unable to park message {0}/{1} operation failed {2} retrying.", e.OriginalStreamId,
                 e.OriginalEventNumber, result);
                 ParkMessage(e, reason, count + 1);
                 return;
             }
             Log.Error("Unable to park message {0}/{1} operation failed {2} after retries. Possible message loss.", e.OriginalStreamId,
                 e.OriginalEventNumber, result);
         }
         lock (_lock)
         {
             _outstandingMessages.Remove(e.OriginalEvent.EventId);
             _pushClients.RemoveProcessingMessage(e.OriginalEvent.EventId); 
             TryPushingMessagesToClients();
         }
     });
 }
Пример #41
0
            private void DeliverEventRetrievedFromTf(EventStore.Core.Data.ResolvedEvent pair, float progress, TFPos position)
            {
                var resolvedEvent = new ResolvedEvent(pair, null);

                DeliverEvent(progress, resolvedEvent, position);
            }
Пример #42
0
 public PendingEvent(EventStore.Core.Data.ResolvedEvent resolvedEvent, TFPos tfPosition, float progress)
 {
     ResolvedEvent = resolvedEvent;
     Progress      = progress;
     TfPosition    = tfPosition;
 }
        private void PublishCommand(EventStore.Core.Data.ResolvedEvent resolvedEvent)
        {
            var command = resolvedEvent.Event.EventType;

            if (!Logging.FilteredMessages.Contains(command))
            {
                Log.Debug("PROJECTIONS: Command received: {eventNumber}@{command}", resolvedEvent.OriginalEventNumber,
                          command);
            }

            switch (command)
            {
            case "$create-prepared": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <CreatePreparedCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.CreatePrepared(
                        Guid.ParseExact(commandBody.Id, "N"),
                        Guid.Empty,
                        commandBody.Name,
                        commandBody.Version,
                        commandBody.Config.ToConfig(),
                        commandBody.SourceDefinition,
                        commandBody.HandlerType,
                        commandBody.Query));
                break;
            }

            case "$create-and-prepare": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <CreateAndPrepareCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.CreateAndPrepare(
                        Guid.ParseExact(commandBody.Id, "N"),
                        Guid.Empty,
                        commandBody.Name,
                        commandBody.Version,
                        commandBody.Config.ToConfig(),
                        commandBody.HandlerType,
                        commandBody.Query));
                break;
            }

            case "$create-and-prepare-slave": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <CreateAndPrepareSlaveCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.CreateAndPrepareSlave(
                        Guid.ParseExact(commandBody.Id, "N"),
                        Guid.Empty,
                        commandBody.Name,
                        commandBody.Version,
                        commandBody.Config.ToConfig(),
                        Guid.ParseExact(commandBody.MasterWorkerId, "N"),
                        Guid.ParseExact(commandBody.MasterCoreProjectionId, "N"),
                        commandBody.HandlerType,
                        commandBody.Query));
                break;
            }

            case "$spool-stream-reading": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <SpoolStreamReadingCommand>();
                _publisher.Publish(
                    new ReaderSubscriptionManagement.SpoolStreamReadingCore(
                        Guid.ParseExact(commandBody.SubscriptionId, "N"),
                        commandBody.StreamId,
                        commandBody.CatalogSequenceNumber,
                        commandBody.LimitingCommitPosition));
                break;
            }

            case "$load-stopped": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <LoadStoppedCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.LoadStopped(
                        Guid.ParseExact(commandBody.Id, "N"),
                        Guid.Empty));
                break;
            }

            case "$start": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <StartCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.Start(Guid.ParseExact(commandBody.Id, "N"), Guid.Empty));
                break;
            }

            case "$stop": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <StopCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.Stop(Guid.ParseExact(commandBody.Id, "N"), Guid.Empty));
                break;
            }

            case "$kill": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <KillCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.Kill(Guid.ParseExact(commandBody.Id, "N"), Guid.Empty));
                break;
            }

            case "$dispose": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <DisposeCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.Dispose(Guid.ParseExact(commandBody.Id, "N"), Guid.Empty));
                break;
            }

            case "$get-state": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <GetStateCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.GetState(
                        Guid.ParseExact(commandBody.CorrelationId, "N"),
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.Partition,
                        Guid.Empty));
                break;
            }

            case "$get-result": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <GetResultCommand>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.GetResult(
                        Guid.ParseExact(commandBody.CorrelationId, "N"),
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.Partition,
                        Guid.Empty));
                break;
            }

            case "$slave-projections-started": {
                var commandBody = resolvedEvent.Event.Data.ParseJson <SlaveProjectionsStartedResponse>();
                _publisher.Publish(
                    new ProjectionManagementMessage.SlaveProjectionsStarted(
                        Guid.ParseExact(commandBody.CorrelationId, "N"),
                        Guid.Empty,
                        commandBody.SlaveProjections));
                break;
            }

            default:
                throw new Exception("Unknown command: " + command);
            }
        }
Пример #44
0
        public static EntryElement ToEntry(ResolvedEvent eventLinkPair, string userHostName, EmbedLevel embedContent)
        {
            if (eventLinkPair.Event == null || userHostName == null)
                return null;

            var evnt = eventLinkPair.Event;

            EntryElement entry;
            if (embedContent > EmbedLevel.None)
            {
                var richEntry = new RichEntryElement();
                entry = richEntry;

                richEntry.EventType = evnt.EventType;
                richEntry.EventNumber = evnt.EventNumber;
                richEntry.StreamId = evnt.EventStreamId;
                richEntry.PositionEventNumber = (eventLinkPair.Link ?? eventLinkPair.Event).EventNumber;
                richEntry.PositionStreamId = (eventLinkPair.Link ?? eventLinkPair.Event).EventStreamId;
                richEntry.IsJson = (evnt.Flags & PrepareFlags.IsJson) != 0;
                if (embedContent >= EmbedLevel.Body)
                {
                    if (richEntry.IsJson)
                    {
                        if (embedContent >= EmbedLevel.PrettyBody)
                            try
                            {
                                richEntry.Data = Encoding.UTF8.GetString(evnt.Data);
                                // next step may fail, so we have already assigned body
                                richEntry.Data = FormatJson(Encoding.UTF8.GetString(evnt.Data));
                            }
                            catch
                            {
                                // ignore - we tried
                            }
                        else 
                            richEntry.Data = Encoding.UTF8.GetString(evnt.Data);
                    }
                    else if (embedContent >= EmbedLevel.TryHarder)
                    {
                        try
                        {
                            richEntry.Data = Encoding.UTF8.GetString(evnt.Data);
                            // next step may fail, so we have already assigned body
                            richEntry.Data = FormatJson(richEntry.Data);
                            // it is json if successed
                            richEntry.IsJson = true;
                        }
                        catch 
                        {
                            // ignore - we tried
                        }
                    }
                    // metadata
                    if (embedContent >= EmbedLevel.PrettyBody)
                    {
                        try
                        {
                            richEntry.MetaData = Encoding.UTF8.GetString(evnt.Metadata);
                            richEntry.IsMetaData = richEntry.MetaData.IsNotEmptyString();
                            // next step may fail, so we have already assigned body
                            richEntry.MetaData = FormatJson(richEntry.MetaData);
                        }
                        catch
                        {
                            // ignore - we tried
                        }
                        var lnk = eventLinkPair.Link;
                        if (lnk != null)
                        {
                            try
                            {
                                richEntry.LinkMetaData = Encoding.UTF8.GetString(lnk.Metadata);
                                richEntry.IsLinkMetaData = richEntry.LinkMetaData.IsNotEmptyString();
                                // next step may fail, so we have already assigned body
                                richEntry.LinkMetaData = FormatJson(richEntry.LinkMetaData);
                            }
                            catch
                            {
                                // ignore - we tried
                            }
                        }
                    }
                }
            }
            else
            {
                entry = new EntryElement();
            }

            var escapedStreamId = Uri.EscapeDataString(evnt.EventStreamId);
            entry.SetTitle(evnt.EventNumber + "@" + evnt.EventStreamId);
            entry.SetId(HostName.Combine(userHostName, "/streams/{0}/{1}", escapedStreamId, evnt.EventNumber));
            entry.SetUpdated(evnt.TimeStamp);
            entry.SetAuthor(AtomSpecs.Author);
            entry.SetSummary(evnt.EventType);

            entry.AddLink("edit", HostName.Combine(userHostName, "/streams/{0}/{1}", escapedStreamId, evnt.EventNumber));
            entry.AddLink(null, HostName.Combine(userHostName, "/streams/{0}/event/{1}?format=text", escapedStreamId, evnt.EventNumber), ContentType.PlainText);
            entry.AddLink("alternate", HostName.Combine(userHostName, "/streams/{0}/event/{1}?format=json", escapedStreamId, evnt.EventNumber), ContentType.Json);
            entry.AddLink("alternate", HostName.Combine(userHostName, "/streams/{0}/event/{1}?format=xml", escapedStreamId, evnt.EventNumber), ContentType.Xml);

            return entry;
        }
Пример #45
0
 private long?EventPairToPosition(EventStore.Core.Data.ResolvedEvent resolvedEvent)
 {
     return(resolvedEvent.OriginalEvent.LogPosition);
 }
Пример #46
0
 public void NotifyLiveSubscriptionMessage(ResolvedEvent resolvedEvent)
 {
     lock (_lock)
     {
         if (resolvedEvent.OriginalEvent.EventNumber < _settings.StartFrom) return;
         if (_state == PersistentSubscriptionState.NotReady) return;
         _statistics.SetLastKnownEventNumber(resolvedEvent.OriginalEventNumber);
         var waslive = _streamBuffer.Live; //hacky
         _streamBuffer.AddLiveMessage(new OutstandingMessage(resolvedEvent.OriginalEvent.EventId, null,
             resolvedEvent, 0));
         if (!_streamBuffer.Live)
         {
             SetBehind();
             if (waslive) _lastPulledEvent = resolvedEvent.OriginalEventNumber;
         }
         TryPushingMessagesToClients();
     }
 }
Пример #47
0
 public void AddMessageAsProcessing(ResolvedEvent ev, PersistentSubscriptionClient client)
 {
     lock (_lock)
     {
         _outstandingMessages.StartMessage(new OutstandingMessage(ev.OriginalEvent.EventId, client, ev, 0),
             DateTime.Now + _settings.MessageTimeout);
     }
 }
 private void PublishCommand(ResolvedEvent resolvedEvent)
 {
     var command = resolvedEvent.Event.EventType;
     Log.Debug("Response received: {0}", command);
     switch (command)
     {
         case "$measured":
         {
             var body = resolvedEvent.Event.Data.ParseJson<PartitionMeasuredResponse>();
             _publisher.Publish(
                 new PartitionMeasured(
                     _workerId,
                     _masterProjectionId,
                     Guid.ParseExact(body.SubscriptionId, "N"),
                     body.Partition,
                     body.Size));
             break;
         }
         case "$progress":
         {
             var body = resolvedEvent.Event.Data.ParseJson<PartitionProcessingProgressResponse>();
             _publisher.Publish(
                 new PartitionProcessingProgress(
                     _workerId,
                     _masterProjectionId,
                     Guid.ParseExact(body.SubscriptionId, "N"),
                     body.Progress));
             break;
         }
         case "$result":
         {
             var body = resolvedEvent.Event.Data.ParseJson<PartitionProcessingResultResponse>();
             _publisher.Publish(
                 new PartitionProcessingResult(
                     _workerId,
                     _masterProjectionId,
                     Guid.ParseExact(body.SubscriptionId, "N"),
                     body.Partition,
                     Guid.ParseExact(body.CausedBy, "N"),
                     body.Position,
                     body.Result));
             break;
         }
         default:
             throw new Exception("Unknown response: " + command);
     }
 }
Пример #49
0
        public void HandleParkedReadCompleted(ResolvedEvent[] events, int newposition, bool isEndofStrem, int stopAt)
        {
            lock (_lock)
            {
                if ((_state & PersistentSubscriptionState.ReplayingParkedMessages) == 0) return;

                foreach (var ev in events)
                {
                    if (ev.OriginalEventNumber == stopAt)
                    {
                        break;
                    }

                    Log.Debug("Retrying event {0} on subscription {1}", ev.OriginalEvent.EventId, _settings.SubscriptionId);
                    _streamBuffer.AddRetry(new OutstandingMessage(ev.OriginalEvent.EventId, null, ev, 0));
                }

                TryPushingMessagesToClients();

                if (isEndofStrem || stopAt <= newposition)
                {
                    var replayedEnd = newposition == -1 ? stopAt : Math.Min(stopAt, newposition);
                    _settings.MessageParker.BeginMarkParkedMessagesReprocessed(replayedEnd);
                    _state ^= PersistentSubscriptionState.ReplayingParkedMessages;
                }
                else
                {
                    TryReadingParkedMessagesFrom(newposition, stopAt);                    
                }
            }
        }
 public void SetLoadedEvent(EventStore.Core.Data.ResolvedEvent eventLinkPair)
 {
     _result = eventLinkPair;
 }
Пример #51
0
 public void RetrySingleMessage(ResolvedEvent @event)
 {
     _streamBuffer.AddRetry(new OutstandingMessage(@event.OriginalEvent.EventId, null, @event, 0));
 }
Пример #52
0
        public static EntryElement ToEntry(ResolvedEvent eventLinkPair, Uri requestedUrl, EmbedLevel embedContent, bool singleEntry = false)
        {
            if (requestedUrl == null)
                return null;

            var evnt = eventLinkPair.Event;
            var link = eventLinkPair.Link;
            EntryElement entry;
            if (embedContent > EmbedLevel.Content && evnt != null)
            {
                var richEntry = new RichEntryElement();
                entry = richEntry;

                richEntry.EventId = evnt.EventId;
                richEntry.EventType = evnt.EventType;
                richEntry.EventNumber = evnt.EventNumber;
                richEntry.StreamId = evnt.EventStreamId;
                richEntry.PositionEventNumber = eventLinkPair.OriginalEvent.EventNumber;
                richEntry.PositionStreamId = eventLinkPair.OriginalEvent.EventStreamId;
                richEntry.IsJson = (evnt.Flags & PrepareFlags.IsJson) != 0;
                if (embedContent >= EmbedLevel.Body && eventLinkPair.Event != null)
                {
                    if (richEntry.IsJson)
                    {
                        if (embedContent >= EmbedLevel.PrettyBody)
                        {
                            try
                            {
                                richEntry.Data = Helper.UTF8NoBom.GetString(evnt.Data);
                                // next step may fail, so we have already assigned body
                                richEntry.Data = FormatJson(Helper.UTF8NoBom.GetString(evnt.Data));
                            }
                            catch
                            {
                                // ignore - we tried
                            }
                        }
                        else
                            richEntry.Data = Helper.UTF8NoBom.GetString(evnt.Data);
                    }
                    else if (embedContent >= EmbedLevel.TryHarder)
                    {
                        try
                        {
                            richEntry.Data = Helper.UTF8NoBom.GetString(evnt.Data);
                            // next step may fail, so we have already assigned body
                            richEntry.Data = FormatJson(richEntry.Data);
                            // it is json if successed
                            richEntry.IsJson = true;
                        }
                        catch
                        {
                            // ignore - we tried
                        }
                    }
                    // metadata
                    if (embedContent >= EmbedLevel.Body)
                    {
                        try
                        {
                            richEntry.MetaData = Helper.UTF8NoBom.GetString(evnt.Metadata);
                            richEntry.IsMetaData = richEntry.MetaData.IsNotEmptyString();
                            // next step may fail, so we have already assigned body
                            if (embedContent >= EmbedLevel.PrettyBody)
                            {
                                richEntry.MetaData = FormatJson(richEntry.MetaData);
                            }
                            if (string.IsNullOrEmpty(richEntry.MetaData))
                            {
                                richEntry.MetaData = null;
                            }
                        }
                        catch
                        {
                            // ignore - we tried
                        }
                        var lnk = eventLinkPair.Link;
                        if (lnk != null)
                        {
                            try
                            {
                                richEntry.LinkMetaData = Helper.UTF8NoBom.GetString(lnk.Metadata);
                                richEntry.IsLinkMetaData = richEntry.LinkMetaData.IsNotEmptyString();
                                // next step may fail, so we have already assigned body
                                if (embedContent >= EmbedLevel.PrettyBody)
                                {
                                    richEntry.LinkMetaData = FormatJson(richEntry.LinkMetaData);
                                }
                            }
                            catch
                            {
                                // ignore - we tried
                            }
                        }
                    }
                }
            }
            else
            {
                entry = new EntryElement();
            }
            if (evnt != null && link == null)
            {
                SetEntryProperties(evnt.EventStreamId, evnt.EventNumber, evnt.TimeStamp, requestedUrl, entry);
                entry.SetSummary(evnt.EventType);
                if ((singleEntry || embedContent == EmbedLevel.Content) && ((evnt.Flags & PrepareFlags.IsJson) != 0))
                    entry.SetContent(AutoEventConverter.CreateDataDto(eventLinkPair));
            }
            else if (link != null)
            {
                var eventLoc = GetLinkData(Encoding.UTF8.GetString(link.Data));
                SetEntryProperties(eventLoc.Item1, eventLoc.Item2, link.TimeStamp, requestedUrl, entry);
                entry.SetSummary("$>");
            }
            return entry;
        }
Пример #53
0
            public ReadStreamEventsBackwardCompleted(Guid correlationId,
                                                     string eventStreamId,
                                                     int fromEventNumber,
                                                     int maxCount,
                                                     ReadStreamResult result,
                                                     ResolvedEvent[] events,
                                                     StreamMetadata streamMetadata,
                                                     bool isCachePublic,
                                                     string error,
                                                     int nextEventNumber,
                                                     int lastEventNumber,
                                                     bool isEndOfStream,
                                                     long tfLastCommitPosition)
            {
                Ensure.NotNull(events, "events");

                if (result != ReadStreamResult.Success)
                {
                    Ensure.Equal(nextEventNumber, -1, "nextEventNumber");
                    Ensure.Equal(isEndOfStream, true, "isEndOfStream");
                }

                CorrelationId = correlationId;
                EventStreamId = eventStreamId;
                FromEventNumber = fromEventNumber;
                MaxCount = maxCount;

                Result = result;
                Events = events;
                StreamMetadata = streamMetadata;
                IsCachePublic = isCachePublic;
                Error = error;
                NextEventNumber = nextEventNumber;
                LastEventNumber = lastEventNumber;
                IsEndOfStream = isEndOfStream;
                TfLastCommitPosition = tfLastCommitPosition;
            }
Пример #54
0
 private static bool IsV1StreamCreatedEvent(EventStore.Core.Data.ResolvedEvent e)
 {
     return(e.Link == null && e.OriginalEventNumber == 0 &&
            (e.OriginalEvent.EventType == SystemEventTypes.V1__StreamCreatedImplicit__ ||
             e.OriginalEvent.EventType == SystemEventTypes.V1__StreamCreated__));
 }
Пример #55
0
 public StreamEventAppeared(Guid correlationId, ResolvedEvent @event)
 {
     CorrelationId = correlationId;
     Event = @event;
 }
 public void BeginParkMessage(ResolvedEvent @event, string reason, Action<ResolvedEvent, OperationResult> completed)
 {
     ParkedEvents.Add(@event);
     _parkMessageCompleted = completed;
 }
        private void PublishCommand(ResolvedEvent resolvedEvent)
        {
            var command = resolvedEvent.Event.EventType;

            //TODO: PROJECTIONS: Remove before release
            if (!Logging.FilteredMessages.Contains(x => x == command))
            {
                Log.Debug("PROJECTIONS: Response received: {eventNumber}@{command}", resolvedEvent.OriginalEventNumber, command);
            }
            switch (command)
            {
            case "$response-reader-starting":
                break;

            case "$projection-worker-started":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <ProjectionWorkerStarted>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.ProjectionWorkerStarted(Guid.ParseExact(commandBody.Id, "N")));
                _numberOfStartedWorkers++;
                if (_numberOfStartedWorkers == _numberOfWorkers)
                {
                    _publisher.Publish(new ProjectionManagementMessage.ReaderReady());
                }
                break;
            }

            case "$prepared":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <Prepared>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Prepared(
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.SourceDefinition));
                break;
            }

            case "$faulted":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <Faulted>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Faulted(
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.FaultedReason));
                break;
            }

            case "$started":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <Started>();
                _publisher.Publish(new CoreProjectionStatusMessage.Started(Guid.ParseExact(commandBody.Id, "N")));
                break;
            }

            case "$statistics-report":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <StatisticsReport>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.StatisticsReport(
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.Statistics,
                        -1));
                break;
            }

            case "$stopped":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <Stopped>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.Stopped(
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.Name,
                        commandBody.Completed));
                break;
            }

            case "$state":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <StateReport>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.StateReport(
                        Guid.ParseExact(commandBody.CorrelationId, "N"),
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.Partition,
                        commandBody.State,
                        commandBody.Position));
                break;
            }

            case "$result":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <ResultReport>();
                _publisher.Publish(
                    new CoreProjectionStatusMessage.ResultReport(
                        Guid.ParseExact(commandBody.CorrelationId, "N"),
                        Guid.ParseExact(commandBody.Id, "N"),
                        commandBody.Partition,
                        commandBody.Result,
                        commandBody.Position));
                break;
            }

            case "$slave-projection-reader-assigned":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <SlaveProjectionReaderAssigned>();
                _publisher.Publish(
                    new CoreProjectionManagementMessage.SlaveProjectionReaderAssigned(
                        Guid.ParseExact(commandBody.Id, "N"),
                        Guid.ParseExact(commandBody.SubscriptionId, "N")));
                break;
            }

            case "$abort":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <AbortCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.Abort(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs));
                break;
            }

            case "$disable":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <DisableCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.Disable(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs));
                break;
            }

            case "$enable":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <EnableCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.Enable(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs));
                break;
            }

            case "$get-query":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <GetQueryCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.GetQuery(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs));
                break;
            }

            case "$get-result":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <GetResultCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.GetResult(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.Partition));
                break;
            }

            case "$get-state":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <GetStateCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.GetState(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.Partition));
                break;
            }

            case "$get-statistics":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <GetStatisticsCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.GetStatistics(
                        new NoopEnvelope(),
                        commandBody.Mode,
                        commandBody.Name,
                        commandBody.IncludeDeleted));
                break;
            }

            case "$post":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <PostCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.Post(
                        new NoopEnvelope(),
                        commandBody.Mode,
                        commandBody.Name,
                        commandBody.RunAs,
                        commandBody.HandlerType,
                        commandBody.Query,
                        commandBody.Enabled,
                        commandBody.CheckpointsEnabled,
                        commandBody.EmitEnabled,
                        commandBody.TrackEmittedStreams,
                        commandBody.EnableRunAs));
                break;
            }

            case "$reset":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <ResetCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.Reset(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs));
                break;
            }

            case "$set-runas":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <SetRunAsCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.SetRunAs(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs,
                        commandBody.SetRemove));
                break;
            }

            case "$start-slave-projections":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <StartSlaveProjectionsCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.StartSlaveProjections(
                        new PublishEnvelope(_publisher),
                        commandBody.RunAs,
                        commandBody.Name,
                        commandBody.SlaveProjections,
                        Guid.ParseExact(commandBody.MasterWorkerId, "N"),
                        Guid.ParseExact(commandBody.MasterCorrelationId, "N")));
                break;
            }

            case "$delete":
            {
                var commandBody = resolvedEvent.Event.Data.ParseJson <DeleteCommand>();
                _publisher.Publish(
                    new ProjectionManagementMessage.Command.Delete(
                        new NoopEnvelope(),
                        commandBody.Name,
                        commandBody.RunAs,
                        commandBody.DeleteCheckpointStream,
                        commandBody.DeleteStateStream,
                        commandBody.DeleteEmittedStreams));
                break;
            }

            default:
                throw new Exception("Unknown response: " + command);
            }
        }
 public static ResolvedEvent BuildLinkEvent(Guid id, string stream, int version, ResolvedEvent ev, bool resolved = true)
 {
     var link = new EventRecord(version, 1234567, Guid.NewGuid(), id, 1234567, 1234, stream, version, DateTime.Now, PrepareFlags.SingleWrite, SystemEventTypes.LinkTo, Encoding.UTF8.GetBytes(string.Format("{0}@{1}", ev.OriginalEventNumber, ev.OriginalStreamId)), new byte[0]);
     if (resolved)
         return ResolvedEvent.ForResolvedLink(ev.Event, link);
     else
         return ResolvedEvent.ForUnresolvedEvent(link);
 }
Пример #59
0
 public void SetLoadedEvent(EventStore.Core.Data.ResolvedEvent eventLinkPair)
 {
     _result = eventLinkPair;
 }
 private void WriteStateCompleted(Action<ResolvedEvent, OperationResult> completed, ResolvedEvent ev, ClientMessage.WriteEventsCompleted msg)
 {
     if(completed != null)
         completed(ev, msg.Result);
 }