public void Detach(byte[] sourceStreamId, byte[] streamIdToDetach, long detachedSince)
        {
            ActivityStream stream;

            if (activityFeedStore.TryGetValue(sourceStreamId, out stream))
            {
                var detaching = stream.AttachedStreams.Where(x => ByteArrayHelper.Compare(x.StreamId, streamIdToDetach)).Single();
                detaching.ExpiresAt = detachedSince;
            }
        }
示例#2
0
 public virtual bool Equals(Activity other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(ByteArrayHelper.Compare(ActivityId, other.ActivityId));
 }
        public void Detach(byte[] streamId, byte[] streamIdToDetach, DateTime detachedSince)
        {
            if (ByteArrayHelper.Compare(streamId, streamIdToDetach))
            {
                throw new ArgumentException("Detaching a stream from itself is now allowed.");
            }

            var stream = repository.Load(streamId);
            var result = stream.Detach(streamIdToDetach, detachedSince);

            if (result.IsSuccessful)
            {
                repository.DetachStream(streamId, streamIdToDetach, detachedSince.ToFileTimeUtc());
            }
        }
        public void Attach(byte[] streamId, byte[] streamIdToAttach, DateTime expiresAt)
        {
            if (ByteArrayHelper.Compare(streamId, streamIdToAttach))
            {
                throw new ArgumentException("Attaching a stream to itself is now allowed.");
            }

            var stream = repository.Load(streamId);
            var result = stream.Attach(streamIdToAttach, expiresAt.ToFileTimeUtc());

            if (result.IsSuccessful)
            {
                repository.AttachStream(streamId, streamIdToAttach, expiresAt.ToFileTimeUtc());
            }
        }
        public Result <bool> Detach(byte[] streamId, DateTime detachedSince)
        {
            var streamToDetach = new ActivityStream(streamId);
            var detachedStream = AttachedStreams.Where(x => ByteArrayHelper.Compare(x.StreamId, streamId)).SingleOrDefault() ?? ActivityStream.Empty;

            if (IsEmpty(detachedStream))
            {
                return(Result.Error("No stream found to detach."));
            }

            if (detachedStream.HasExpiration)
            {
                return(Result.Error($"Stream is already detached since {DateTime.FromFileTimeUtc(ExpiresAt).ToShortDateString()}."));
            }

            detachedStream.ExpiresAt = detachedSince.ToFileTimeUtc();
            return(Result.Success);
        }
        public bool Equals(ActivityStream other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            var t = GetType();

            if (t != other.GetType())
            {
                return(false);
            }

            return(ByteArrayHelper.Compare(StreamId, other.StreamId));
        }
示例#7
0
        public void Validate(EventStreamIntegrityPolicy policy)
        {
            var aggregateCommits = new List <AggregateCommit>();

            byte[] currentId = { 0 };
            foreach (var commit in player.LoadAggregateCommits(1000))
            {
                if (ByteArrayHelper.Compare(currentId, commit.AggregateRootId) == false)
                {
                    if (aggregateCommits.Count > 0)
                    {
                        var result = policy.Apply(new EventStream(aggregateCommits));
                        if (result.IsIntegrityViolated)
                        {
                            throw new Exception(result.Output.ToString());
                        }
                        aggregateCommits.Clear();
                    }
                }

                aggregateCommits.Add(commit);
                currentId = commit.AggregateRootId;
            }
        }
 internal static bool CompareBytes(string first, string second)
 {
     return(ByteArrayHelper.Compare(first.ToIso88591EncodingByteArray(), second.ToIso88591EncodingByteArray()));
 }