public KeyedDataStore(DimensionSet dimensionSet, RecyclableMemoryStreamManager memoryStreamManager,
                              MemoryStream initialData, int dataKeyCount, PersistedDataType initialDataType, string sourceTag = "unknown with data")
        {
            this.allocationStack =
#if COLLECT_STACKS
                sourceTag + " " + Environment.StackTrace;
#else
                string.Empty;
#endif

            this.DimensionSet        = dimensionSet;
            this.memoryStreamManager = memoryStreamManager;

            if (initialData != null && dataKeyCount > 0)
            {
                this.mergedData = this.CreateDataFromStream(initialData, initialDataType, dataKeyCount);
            }
            else
            {
                this.mergedData = new QueryableSingleValueData(null, DimensionSet.Empty);
                if (initialData != null)
                {
                    initialData.Dispose();
                }
            }

            this.multiValue = (new TInternal()).MultiValue;
        }
        public void Merge()
        {
            if (!this.HasUnmergedData)
            {
                return;
            }

            this.dirty = true;

            lock (this)
            {
                this.SealWriteBuffer(null);

                foreach (var pair in this.unmergedData)
                {
                    pair.PrepareForMerge(this.DimensionSet);
                }

                // Obviously this data was already merged and does not need a second preparation. We will clear out the
                // current list afterwards.
                this.unmergedData.Add(this.mergedData);

                this.mergedData = this.MergeBuffers(this.unmergedData);
            }
        }
        private void Dispose(bool disposing)
        {
            if (disposing && this.disposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }

            this.disposed = true;

            if (this.pendingDataStream != null)
            {
                this.pendingDataStream.Dispose();
                this.pendingDataStream = null;
            }

            foreach (var pair in this.unmergedData)
            {
                pair.Dispose();
            }
            this.unmergedData.Clear();

            if (this.mergedData != null)
            {
                this.mergedData.Dispose();
                this.mergedData = null;
            }
        }
        private void AddData(QueryableData data)
        {
            this.unmergedData.Add(data);
            int totalUnmergedSize = 0;

            for (var i = 0; i < this.unmergedData.Count; ++i)
            {
                totalUnmergedSize += this.unmergedData[i].Size;
            }

            if (totalUnmergedSize >= MaxUnmergedBufferSize && this.unmergedData.Count > 1)
            {
                for (var i = 0; i < this.unmergedData.Count; ++i)
                {
                    this.unmergedData[i].PrepareForMerge(this.DimensionSet);
                }

                var merged = this.MergeBuffers(this.unmergedData);
                this.unmergedData.Add(merged);
            }
        }
 public IQueryable <TheEntity> QueryBy(Specification <TheEntity> specification)
 {
     return(QueryableData.Where(specification));
 }
 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
 {
     return(QueryableData.GetEnumerator());
 }
 public IEnumerator <TheEntity> GetEnumerator()
 {
     return(QueryableData.GetEnumerator());
 }