コード例 #1
0
ファイル: StreamReader{T}.cs プロジェクト: xiangzhi/psi
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamReader{T}"/> class.
        /// </summary>
        /// <param name="streamName">the name of the stream to read.</param>
        /// <param name="streamAdapter">the stream adapter to convert data from the stream into the type required by clients of this stream reader.</param>
        public StreamReader(string streamName, IStreamAdapter streamAdapter)
        {
            if (string.IsNullOrWhiteSpace(streamName))
            {
                throw new ArgumentNullException(nameof(streamName));
            }

            this.StreamName        = streamName;
            this.streamAdapter     = streamAdapter;
            this.StreamAdapterType = streamAdapter?.GetType();

            this.pool = PoolManager.Instance.GetPool <T>();

            this.readRequestsInternal = new List <ReadRequest>();
            this.readRequests         = new ReadOnlyCollection <ReadRequest>(this.readRequestsInternal);

            this.bufferLock  = new object();
            this.dataBuffer  = new List <Message <T> >(1000);
            this.indexBuffer = new List <IndexEntry>(1000);

            var itemComparer = Comparer <Message <T> > .Create((m1, m2) => m1.OriginatingTime.CompareTo(m2.OriginatingTime));

            var indexComarer = Comparer <IndexEntry> .Create((i1, i2) => i1.OriginatingTime.CompareTo(i2.OriginatingTime));

            this.data  = new ObservableKeyedCache <DateTime, Message <T> >(null, itemComparer, m => m.OriginatingTime);
            this.index = new ObservableKeyedCache <DateTime, IndexEntry>(null, indexComarer, ie => ie.OriginatingTime);

            this.instantIndexView = null;

            this.instantStreamReaders = new List <EpsilonInstantStreamReader <T> >();

            if (this.needsDisposing)
            {
                this.data.CollectionChanged += this.OnCollectionChanged;
            }
        }
コード例 #2
0
ファイル: DataStoreReader.cs プロジェクト: annelo-msft/psi
        private IStreamReader GetExistingStreamReader(string streamName, IStreamAdapter streamAdapter)
        {
            IStreamReader streamReader = this.streamReaders.Find(sr => sr.StreamName == streamName && sr.StreamAdapterType == streamAdapter?.GetType());

            if (streamReader == null)
            {
                throw new ArgumentException("No stream reader exists for the stream.");
            }

            return(streamReader);
        }
コード例 #3
0
ファイル: DataStoreReader.cs プロジェクト: annelo-msft/psi
        private IStreamReader GetOrCreateStreamReader <T>(string streamName, IStreamAdapter streamAdapter)
        {
            var streamReader = this.streamReaders.Find(sr => sr.StreamName == streamName && sr.StreamAdapterType == streamAdapter?.GetType());

            if (streamReader == null)
            {
                streamReader = new StreamReader <T>(streamName, streamAdapter);
                this.streamReaders.Add(streamReader);
            }

            return(streamReader);
        }
コード例 #4
0
ファイル: DataStoreReader.cs プロジェクト: xiangzhi/psi
        private IStreamReader GetStreamReader <T>(string streamName, IStreamAdapter streamAdapter, bool createIfNecessary)
        {
            var streamReader = this.streamReaders.Find(sr => sr.StreamName == streamName && sr.StreamAdapterType == streamAdapter?.GetType());

            if (streamReader == null)
            {
                if (createIfNecessary)
                {
                    streamReader = new StreamReader <T>(streamName, streamAdapter);
                    this.streamReaders.Add(streamReader);
                }
                else
                {
                    throw new ArgumentException("No stream reader exists for the stream binding.");
                }
            }

            return(streamReader);
        }