public static bool GetOrReserveEventType <TStreamId>(
            this INameIndex <TStreamId> eventTypeIndex,
            IRecordFactory <TStreamId> recordFactory,
            string eventType,
            long logPosition,
            out TStreamId eventTypeId,
            out IPrepareLogRecord <TStreamId> eventTypeRecord)
        {
            var preExisting = eventTypeIndex.GetOrReserve(eventType, out eventTypeId, out var addedNumber, out var addedName);

            var appendNewEventType = recordFactory.ExplicitEventTypeCreation && !preExisting;

            if (!appendNewEventType)
            {
                eventTypeRecord = null;
                return(preExisting);
            }

            eventTypeRecord = recordFactory.CreateEventTypeRecord(
                eventTypeId: Guid.NewGuid(),
                parentEventTypeId: Guid.Empty,
                eventType: addedName,
                eventTypeNumber: addedNumber,
                eventTypeVersion: 0,
                logPosition: logPosition,
                timeStamp: DateTime.UtcNow);

            return(preExisting);
        }
Beispiel #2
0
        // todo: rename to GetOrReserveStream when we generalise to EventTypes too.
        /// Generates a StreamRecord if necessary
        public static bool GetOrReserve <TStreamId>(
            this INameIndex <TStreamId> streamNameIndex,
            IRecordFactory <TStreamId> recordFactory,
            string streamName,
            long logPosition,
            out TStreamId streamId,
            out IPrepareLogRecord <TStreamId> streamRecord)
        {
            var preExisting = streamNameIndex.GetOrReserve(streamName, out streamId, out var addedId, out var addedName);

            var appendNewStream = recordFactory.ExplicitStreamCreation && !preExisting;

            if (!appendNewStream)
            {
                streamRecord = null;
                return(preExisting);
            }

            streamRecord = recordFactory.CreateStreamRecord(
                streamId: Guid.NewGuid(),
                logPosition: logPosition,
                timeStamp: DateTime.UtcNow,
                streamNumber: addedId,
                streamName: addedName);

            return(preExisting);
        }
Beispiel #3
0
 private TStreamId GetEpochInformationEventType()
 {
     if (!_eventTypeIndex.GetOrReserve(SystemEventTypes.EpochInformation, out var eventTypeId, out _, out _))
     {
         throw new Exception($"{SystemEventTypes.EpochInformation} event type does not exist");
     }
     return(eventTypeId);
 }
Beispiel #4
0
 private TStreamId GetEpochInformationStream()
 {
     if (!_streamNameIndex.GetOrReserve(SystemStreams.EpochInformationStream, out var streamId, out _, out _))
     {
         throw new Exception($"{SystemStreams.EpochInformationStream} stream does not exist");
     }
     return(streamId);
 }
Beispiel #5
0
 protected void GetOrReserve(string eventStreamName, out TStreamId eventStreamId, out long newPos)
 {
     newPos = WriterCheckpoint.ReadNonFlushed();
     _streamNameIndex.GetOrReserve(_logFormat.RecordFactory, eventStreamName, newPos, out eventStreamId, out var streamRecord);
     if (streamRecord != null)
     {
         Writer.Write(streamRecord, out newPos);
     }
 }
        public bool GetOrReserve(string eventType, out uint eventTypeId, out uint createdId, out string createdName)
        {
            Ensure.NotNull(eventType, "eventType");

            if (LogV3SystemEventTypes.TryGetSystemEventTypeId(eventType, out eventTypeId))
            {
                createdId   = default;
                createdName = default;
                return(true);
            }

            return(_wrapped.GetOrReserve(eventType, out eventTypeId, out createdId, out createdName));
        }
Beispiel #7
0
        public bool GetOrReserve(string streamName, out StreamId streamId, out StreamId createdId, out string createdName)
        {
            Ensure.NotNullOrEmpty(streamName, "streamName");
            if (SystemStreams.IsMetastream(streamName))
            {
                streamName = SystemStreams.OriginalStreamOf(streamName);
                var ret = GetOrReserve(streamName, out streamId, out createdId, out createdName);
                streamId = _metastreams.MetaStreamOf(streamId);
                return(ret);
            }

            if (LogV3SystemStreams.TryGetVirtualStreamId(streamName, out streamId))
            {
                createdId   = default;
                createdName = default;
                return(true);
            }

            return(_wrapped.GetOrReserve(streamName, out streamId, out createdId, out createdName));
        }