Ejemplo n.º 1
0
 public static StreamData <TStreamItemCollection, TStreamItem, TStreamItemId> Create(
     StreamInfo <TStreamItemCollection> streamInfo,
     StreamFilterBase <TStreamItem, TStreamItemId> filter,
     ILogger logger,
     Func <TStreamItemCollection, StreamData <TStreamItemCollection, TStreamItem, TStreamItemId>, Task> processFunc)
 {
     var streamData = new StreamData <TStreamItemCollection, TStreamItem, TStreamItemId>
     {
         CompletionTask   = new TaskCompletionSource <int>(),
         CancelationToken = streamInfo.CancelationToken,
         Stream           = streamInfo.Stream,
         Keys             = streamInfo.Keys,
         Peer             = streamInfo.Peer,
         LastSentData     = null,
         Filter           = filter,
         Queue            = new Queue <TStreamItemCollection>(),
         Cursor           = default,
Ejemplo n.º 2
0
        public async Task <StreamData <TStreamItemCollection, TStreamItem, TStreamItemId> > RegisterStream(StreamInfo <TStreamItemCollection> streamInfo,
                                                                                                           StreamFilterBase <TStreamItem, TStreamItemId> filter)
        {
            await BeforeStreamRegistered(streamInfo);

            _logger.LogDebug($"StreamService<{typeof(TStreamItemCollection).Name}> Register stream connection (peer: {streamInfo.Peer})");

            var data = StreamData <TStreamItemCollection, TStreamItem, TStreamItemId> .Create(
                streamInfo,
                filter,
                this._logger,
                this.WriteToStream);

            _readerWriterLock.AcquireWriterLock(Timeout.Infinite);

            try
            {
                _streamList.Add(data);
            }
            finally
            {
                _readerWriterLock.ReleaseWriterLock();
            }

            return(data);
        }