public static StreamMetadataResult Create(string streamName, StreamRevision revision,
                                                  StreamMetadata metadata)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            return(new StreamMetadataResult(streamName, revision, metadata));
        }
 public Task <WriteResult> SetStreamMetadataAsync(string streamName, StreamRevision expectedRevision,
                                                  StreamMetadata metadata, UserCredentials userCredentials = default,
                                                  CancellationToken cancellationToken = default)
 => SetStreamMetadataInternal(metadata, new AppendReq {
     Options = new AppendReq.Types.Options {
         StreamName = SystemStreams.MetastreamOf(streamName),
         Revision   = expectedRevision
     }
 }, userCredentials,
                              cancellationToken);
 public Task <DeleteResult> TombstoneAsync(
     string streamName,
     StreamRevision expectedRevision,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) =>
 TombstoneInternal(new TombstoneReq {
     Options = new TombstoneReq.Types.Options {
         StreamName = streamName,
         Revision   = expectedRevision
     }
 }, userCredentials, cancellationToken);
 public Task <WriteResult> AppendToStreamAsync(
     string streamName,
     StreamRevision expectedRevision,
     IEnumerable <EventData> eventData,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) =>
 AppendToStreamInternal(new AppendReq {
     Options = new AppendReq.Types.Options {
         StreamName = streamName,
         Revision   = expectedRevision
     }
 }, eventData, userCredentials, cancellationToken);
 public IAsyncEnumerable <ResolvedEvent> ReadStreamBackwardsAsync(
     string streamName,
     StreamRevision revision,
     int count,
     bool resolveLinkTos                 = false,
     UserCredentials userCredentials     = default,
     CancellationToken cancellationToken = default) => ReadInternal(new ReadReq {
     Options = new ReadReq.Types.Options {
         ReadDirection = ReadReq.Types.Options.Types.ReadDirection.Backwards,
         ResolveLinks  = resolveLinkTos,
         Stream        = ReadReq.Types.Options.Types.StreamOptions.FromStreamNameAndRevision(streamName, revision),
         Count         = count
     }
 }, userCredentials,
                                                                    cancellationToken);
 public StreamSubscription SubscribeToStream(string streamName,
                                             StreamRevision start,
                                             Func <StreamSubscription, ResolvedEvent, CancellationToken, Task> eventAppeared,
                                             bool resolveLinkTos = false,
                                             Action <StreamSubscription, SubscriptionDroppedReason, Exception> subscriptionDropped = default,
                                             UserCredentials userCredentials     = default,
                                             CancellationToken cancellationToken = default) => new StreamSubscription(ReadInternal(new ReadReq {
     Options = new ReadReq.Types.Options {
         ReadDirection = ReadReq.Types.Options.Types.ReadDirection.Forwards,
         ResolveLinks  = resolveLinkTos,
         Stream        = ReadReq.Types.Options.Types.StreamOptions.FromStreamNameAndRevision(streamName, start),
         Subscription  = new ReadReq.Types.Options.Types.SubscriptionOptions()
     }
 },
                                                                                                                                   userCredentials,
                                                                                                                                   cancellationToken), eventAppeared, subscriptionDropped);
Example #7
0
 public EventRecord(
     string eventStreamId,
     Uuid eventId,
     StreamRevision eventNumber,
     Position position,
     IDictionary <string, string> metadata,
     byte[] data,
     byte[] customMetadata)
 {
     EventStreamId = eventStreamId;
     EventId       = eventId;
     EventNumber   = eventNumber;
     Position      = position;
     Data          = data;
     Metadata      = customMetadata;
     EventType     = metadata[Constants.Metadata.Type];
     Created       = new DateTime(
         DateTime.UnixEpoch.Ticks + Convert.ToInt64(metadata[Constants.Metadata.Created]),
         DateTimeKind.Utc);
     IsJson = bool.Parse(metadata[Constants.Metadata.IsJson]);
 }
        public PersistentSubscriptionSettings(bool resolveLinkTos      = false, StreamRevision?startFrom = default,
                                              bool extraStatistics     = false, TimeSpan?messageTimeout  = default, int maxRetryCount = 500,
                                              int liveBufferSize       = 500, int readBatchSize          = 10, int historyBufferSize  = 20,
                                              TimeSpan?checkPointAfter = default, int minCheckPointCount = 10, int maxCheckPointCount = 1000,
                                              int maxSubscriberCount   = 0, string namedConsumerStrategy = SystemConsumerStrategies.RoundRobin)
        {
            messageTimeout ??= TimeSpan.FromSeconds(30);
            checkPointAfter ??= TimeSpan.FromSeconds(2);
            startFrom ??= StreamRevision.End;

            if (messageTimeout.Value < TimeSpan.Zero || messageTimeout.Value.TotalMilliseconds > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(messageTimeout),
                          $"{nameof(messageTimeout)} must be greater than {TimeSpan.Zero} and less than or equal to {TimeSpan.FromMilliseconds(int.MaxValue)}");
            }

            if (checkPointAfter.Value < TimeSpan.Zero || checkPointAfter.Value.TotalMilliseconds > int.MaxValue)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(checkPointAfter),
                          $"{nameof(checkPointAfter)} must be greater than {TimeSpan.Zero} and less than or equal to {TimeSpan.FromMilliseconds(int.MaxValue)}");
            }

            ResolveLinkTos        = resolveLinkTos;
            StartFrom             = startFrom.Value;
            ExtraStatistics       = extraStatistics;
            MessageTimeout        = messageTimeout.Value;
            MaxRetryCount         = maxRetryCount;
            LiveBufferSize        = liveBufferSize;
            ReadBatchSize         = readBatchSize;
            HistoryBufferSize     = historyBufferSize;
            CheckPointAfter       = checkPointAfter.Value;
            MinCheckPointCount    = minCheckPointCount;
            MaxCheckPointCount    = maxCheckPointCount;
            MaxSubscriberCount    = maxSubscriberCount;
            NamedConsumerStrategy = namedConsumerStrategy;
        }
        public static async Task <ConditionalWriteResult> ConditionalAppendToStreamAsync(
            this EventStoreGrpcClient client,
            string streamName,
            StreamRevision expectedRevision,
            IEnumerable <EventData> eventData,
            UserCredentials userCredentials     = default,
            CancellationToken cancellationToken = default)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            try {
                var result = await client.AppendToStreamAsync(streamName, expectedRevision, eventData, userCredentials,
                                                              cancellationToken);

                return(ConditionalWriteResult.FromWriteResult(result));
            } catch (StreamDeletedException) {
                return(ConditionalWriteResult.StreamDeleted);
            } catch (WrongExpectedVersionException ex) {
                return(ConditionalWriteResult.FromWrongExpectedVersion(ex));
            }
        }
Example #10
0
 protected static EventData CreateLinkToEvent(string originalStreamName, StreamRevision originalRevision)
 => new EventData(Uuid.NewUuid(), SystemEventTypes.LinkTo,
                  Helper.UTF8NoBom.GetBytes($"{originalRevision.ToInt64()}@{originalStreamName}"));
Example #11
0
 public void ToInt64ExpectedResult(long expected, StreamRevision value)
 => Assert.Equal(expected, value.ToInt64());
Example #12
0
 public void FromInt64ExpectedResult(long value, StreamRevision expected)
 => Assert.Equal(expected, StreamRevision.FromInt64(value));
Example #13
0
        public void Equality()
        {
            var sut = new StreamRevision(1);

            Assert.Equal(new StreamRevision(1), sut);
        }
Example #14
0
 public void Comparability(StreamRevision left, StreamRevision right, int expected)
 => Assert.Equal(expected, left.CompareTo(right));
Example #15
0
        public void InequalityOperator()
        {
            var sut = new StreamRevision(1);

            Assert.True(new StreamRevision(2) != sut);
        }
Example #16
0
        public void Inequality()
        {
            var sut = new StreamRevision(1);

            Assert.NotEqual(new StreamRevision(2), sut);
        }