コード例 #1
0
        /// <summary>
        /// Compacts the specified from buffer.
        /// </summary>
        /// <param name="fromBuffer">From buffer.</param>
        /// <param name="indexs">The indexes.</param>
        public static void Compact(ref InternalStorageBuffer fromBuffer, ref ConcurrentDictionary <string, BinaryStorageKey> indexs)
        {
            scrubBuffer.ResetBuffer();

            foreach (var storageKey in indexs.Keys)
            {
                // Scrub out old data ;)
                BinaryStorageKey tmpKey;
                if (indexs.TryRemove(storageKey, out tmpKey))
                {
                    long pos = tmpKey.Position;
                    int  len = tmpKey.Length;

                    var bytes = fromBuffer.FetchFromBuffer(pos, len);

                    var idx = scrubBuffer.InsertSegment(bytes);

                    tmpKey.Position = idx;

                    indexs[storageKey] = tmpKey;
                }
            }

            // now copy over the data ;)
            fromBuffer.ResetBuffer();
            scrubBuffer.TransferTo(ref fromBuffer);
        }
コード例 #2
0
        public Dev2BinaryStorage(string filename, int bufCap)
        {
            if (!string.IsNullOrEmpty(filename))
            {
                lock (DirLock)
                {
                    if (!Directory.Exists(DataListPersistPath))
                    {
                        Directory.CreateDirectory(DataListPersistPath);
                    }

                    if (!_startupCleaned)
                    {
                        foreach (FileInfo f in new DirectoryInfo(DataListPersistPath).GetFiles("*.data"))
                        {
                            try
                            {
                                f.Delete();
                            }
                            // ReSharper disable EmptyGeneralCatchClause
                            catch (Exception err)
                            // ReSharper restore EmptyGeneralCatchClause
                            {
                                Dev2Logger.Log.Debug("Delete error", err);
                                // Best effort ;)
                            }
                        }

                        _startupCleaned = true;
                    }
                }


                _completeFilename = Path.Combine(DataListPersistPath, filename);
            }

            _file           = new FileStream(_completeFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            _internalBuffer = new InternalStorageBuffer {
                Buffer = new byte[bufCap], Capacity = bufCap, UsedStorage = 0
            };
        }
コード例 #3
0
 /// <summary>
 /// Transfers one buffer to another. Used by the background scrubber ;)
 /// </summary>
 /// <param name="toBuffer">The automatic buffer.</param>
 public void TransferTo(ref InternalStorageBuffer toBuffer)
 {
     System.Buffer.BlockCopy(Buffer, 0, toBuffer.Buffer, 0, UsedStorage);
     toBuffer.UsedStorage = UsedStorage;
 }
コード例 #4
0
        // ReSharper restore InconsistentNaming

        public static void Init(int bufCap)
        {
            scrubBuffer = new InternalStorageBuffer {
                Buffer = new byte[bufCap], Capacity = bufCap, UsedStorage = 0
            };
        }