예제 #1
0
        /// <summary>
        /// Gets the collection of all updates to the stream.
        /// </summary>
        /// <returns>A collection of updates to the stream.  If the boolean value is true then the update is an upsert operation, otherwise it's a delete operation.</returns>
        public IEnumerable <(bool, dynamic, DateTime)> GetUncommittedUpdates()
        {
            List <(bool, dynamic, DateTime)> updates = new List <(bool, dynamic, DateTime)>();

            foreach (DateTime originatingTime in this.updateList.Keys)
            {
                StreamUpdateWithView <T> update = this.updateList[originatingTime];
                updates.Add((update.UpdateType != StreamUpdateType.Delete, update.Message.Data, originatingTime));
            }

            this.updateList.Clear();

            return(updates);
        }
예제 #2
0
        /// <summary>
        /// Called when the simple reader has read a new message from the store.
        /// </summary>
        /// <param name="data">The data in the message that was read.</param>
        /// <param name="env">The envelope of the message that was read.</param>
        private void OnReceiveData(T data, Envelope env)
        {
            if (!this.IsStopped)
            {
                // If the update list contains an item with the same originating
                // time, then use that instead of the data coming from the store.
                if (this.updateList.Any() && this.updateList.ContainsKey(env.OriginatingTime))
                {
                    // Get the update object
                    StreamUpdateWithView <T> update = this.updateList[env.OriginatingTime];

                    // If the update was an Add, add its message to the data buffer instead
                    // of the one read from the store. If the update was a delete, then
                    // don't add anything to the data buffer.
                    switch (update.UpdateType)
                    {
                    case StreamUpdateType.Add:
                        lock (this.dataLock)
                        {
                            this.dataBuffer.Add(update.Message);
                        }

                        break;

                    case StreamUpdateType.Delete:
                        // The item was deleted, so do nothing.
                        break;

                    default:
                        throw new InvalidOperationException("The update type is not supported.");
                    }
                }
                else
                {
                    // the data is obtained from an IStreamReader, and we therefore need to clone it
                    // to hold on to it past the lifetime of the OnReceiveData method.
                    var message = new Message <T>(data.DeepClone(), env.OriginatingTime, env.CreationTime, env.SourceId, env.SequenceId);
                    lock (this.dataLock)
                    {
                        this.dataBuffer.Add(message);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Called when the simple reader has read a new message from the store.
        /// </summary>
        /// <param name="data">The data in the message that was read.</param>
        /// <param name="env">The envelope of the message that was read.</param>
        private void OnReceiveData(T data, Envelope env)
        {
            if (!this.IsCanceled)
            {
                lock (this.bufferLock)
                {
                    // If the update list contains an item with the same originating
                    // time, then use that instead of the data coming from the store.
                    if (this.updateList.ContainsKey(env.OriginatingTime))
                    {
                        // Get the update object
                        StreamUpdateWithView <T> update = this.updateList[env.OriginatingTime];

                        // If the update was an Add, add its message to the data buffer instead
                        // of the one read from the store. If the update was a Deletem then
                        // don't add anything to the data buffer.
                        switch (update.UpdateType)
                        {
                        case StreamUpdateType.Add:
                            this.dataBuffer.Add(update.Message);
                            break;

                        case StreamUpdateType.Delete:
                            // The item was deleted, so do nothing.
                            break;

                        default:
                            throw new InvalidOperationException("The update type is not supported.");
                        }
                    }
                    else
                    {
                        this.dataBuffer.Add(new Message <T>(data, env.OriginatingTime, env.CreationTime, env.SourceId, env.SequenceId));
                    }
                }
            }
        }