Exemple #1
0
 /// <summary>
 /// Provides a cursor into a sorted set of objects.
 /// </summary>
 /// <param name="SortedObjects">Sorted set of objects.</param>
 /// <param name="RecordHandler">Record handler.</param>
 /// <param name="TimeoutMilliseconds">Time to wait to get access to underlying database.</param>
 internal SortedCursor(SortedDictionary <SortedReference <T>, bool> SortedObjects, IndexRecords RecordHandler,
                       int TimeoutMilliseconds)
 {
     this.sortedObjects       = SortedObjects;
     this.recordHandler       = RecordHandler;
     this.timeoutMilliseconds = TimeoutMilliseconds;
 }
Exemple #2
0
        public void DBFiles_Index_KeyComparison_Test_02_Serialized_NumericalFields()
        {
            object[,] Values = this.GetNumberValues();
            int          x, y;
            int          Rows    = Values.GetLength(0);
            int          Columns = Values.GetLength(1);
            IndexRecords Records = new IndexRecords(string.Empty, Encoding.UTF8, 1000, "Field");

            for (y = 0; y < Rows; y++)
            {
                for (x = 0; x < Columns; x++)
                {
                    BinarySerializer xWriter = new BinarySerializer(string.Empty, Encoding.UTF8);
                    BinarySerializer yWriter = new BinarySerializer(string.Empty, Encoding.UTF8);

                    object xValue = Values[y, x];
                    object yValue = Values[x, y];

                    xWriter.WriteBit(true);
                    Assert.IsTrue(Records.Serialize(xWriter, xValue));
                    xWriter.Write(Guid.Empty);

                    yWriter.WriteBit(true);
                    Assert.IsTrue(Records.Serialize(yWriter, yValue));
                    yWriter.Write(Guid.Empty);

                    byte[] xBin = xWriter.GetSerialization();
                    byte[] yBin = yWriter.GetSerialization();

                    int Comparison = Records.Compare(xBin, yBin);

                    Assert.AreEqual(Math.Sign(x.CompareTo(y)), Math.Sign(Comparison), "x: " + x.ToString() + ", y: " + y.ToString());
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// <see cref="IDisposable.Dispose"/>
        /// </summary>
        public void Dispose()
        {
            this.indexFile?.Dispose();
            this.indexFile = null;

            this.objectFile    = null;
            this.recordHandler = null;
        }
Exemple #4
0
 /// <summary>
 /// Provides a cursor into a sorted set of objects.
 /// </summary>
 /// <param name="SortedObjects">Sorted set of objects.</param>
 /// <param name="RecordHandler">Record handler.</param>
 /// <param name="TimeoutMilliseconds">Time to wait to get access to underlying database.</param>
 internal SortedCursor(SortedDictionary <SortRec, Tuple <T, IObjectSerializer, Guid> > SortedObjects, IndexRecords RecordHandler,
                       int TimeoutMilliseconds)
 {
     this.sortedObjects = SortedObjects;
     this.recordHandler = RecordHandler;
     e = this.sortedObjects.Values.GetEnumerator();
     this.timeoutMilliseconds = TimeoutMilliseconds;
 }
Exemple #5
0
        public double Progress(int fileCount)
        {
            double percentage;

            lock (IndexRecords)
            {
                percentage = Convert.ToDouble(IndexRecords.Count()) / Convert.ToDouble(fileCount);
            }
            return(percentage);
        }
 internal static async Task <IndexBTreeFileEnumerator <T> > Create(IndexBTreeFile File, IndexRecords RecordHandler)
 {
     return(new IndexBTreeFileEnumerator <T>()
     {
         file = File,
         recordHandler = RecordHandler,
         provider = File.ObjectFile.Provider,
         hasCurrent = false,
         currentObjectId = Guid.Empty,
         current = default,
Exemple #7
0
        public bool IsSourceAlreadyProcessed(ISource source)
        {
            bool isProcessed;

            lock (IndexRecords)
            {
                List <IIndexRecord> indexAsList = IndexRecords.ToList();
                isProcessed = indexAsList.Any(s => s.Source.RecordName.Equals(source.RecordName));
            }
            return(isProcessed);
        }
Exemple #8
0
        internal IndexBTreeFileEnumerator(IndexBTreeFile File, IndexRecords RecordHandler)
        {
            this.file                = File;
            this.recordHandler       = RecordHandler;
            this.provider            = this.file.ObjectFile.Provider;
            this.hasCurrent          = false;
            this.currentObjectId     = Guid.Empty;
            this.current             = default;
            this.currentSerializer   = null;
            this.timeoutMilliseconds = File.IndexFile.TimeoutMilliseconds;

            this.e = new ObjectBTreeFileEnumerator <object>(this.file.IndexFile, RecordHandler);
        }
        internal IndexBTreeFileEnumerator(IndexBTreeFile File, bool Locked, IndexRecords RecordHandler, BlockInfo StartingPoint)
        {
            this.file                = File;
            this.locked              = Locked;
            this.recordHandler       = RecordHandler;
            this.provider            = this.file.ObjectFile.Provider;
            this.hasCurrent          = false;
            this.currentObjectId     = Guid.Empty;
            this.current             = default(T);
            this.currentSerializer   = null;
            this.timeoutMilliseconds = File.IndexFile.TimeoutMilliseconds;

            this.e = new ObjectBTreeFileEnumerator <object>(this.file.IndexFile, Locked, RecordHandler, StartingPoint);
        }
Exemple #10
0
        /// <summary>
        /// This class manages an index file to a <see cref="ObjectBTreeFile"/>.
        /// </summary>
        /// <param name="FileName">File name of index file.</param>
        /// <param name="ObjectFile">Object file storing actual objects.</param>
        /// <param name="Provider">Files provider.</param>
        /// <param name="FieldNames">Field names to build the index on. By default, sort order is ascending.
        /// If descending sort order is desired, prefix the corresponding field name by a hyphen (minus) sign.</param>
        internal IndexBTreeFile(string FileName, ObjectBTreeFile ObjectFile, FilesProvider Provider,
                                params string[] FieldNames)
        {
            this.objectFile     = ObjectFile;
            this.collectionName = this.objectFile.CollectionName;
            this.encoding       = this.objectFile.Encoding;

            this.recordHandler     = new IndexRecords(this.collectionName, this.encoding, this.objectFile.InlineObjectSizeLimit, FieldNames);
            this.genericSerializer = new GenericObjectSerializer(this.objectFile.Provider);

            this.indexFile = new ObjectBTreeFile(FileName, string.Empty, string.Empty, this.objectFile.BlockSize,
                                                 this.objectFile.BlobBlockSize, Provider, this.encoding, this.objectFile.TimeoutMilliseconds,
                                                 this.objectFile.Encrypted, this.recordHandler);
            this.recordHandler.Index = this;
        }
Exemple #11
0
 public void Write(int threadId, string updatedText)
 {
     _sourceReadWriteLock.EnterWriteLock();
     try
     {
         // Extra check so that the file is not picked up by other threads.
         if (CheckIndexBeforeUpdate && !IsSourceAlreadyProcessed(Source))
         {
             Source.WriteData(updatedText);
             IndexRecords.Add(IndexRecord);
         }
         else if (!CheckIndexBeforeUpdate)
         {
             Source.WriteData(updatedText);
             IndexRecords.Add(IndexRecord);
         }
     }
     finally
     {
         _sourceReadWriteLock.ExitWriteLock();
     }
 }
 public bool IsSourceAlreadyProcessed(ISource source)
 {
     return(IndexRecords.ToList().Any(s => s.Source.RecordName.Equals(source.RecordName)));
 }
 public void Write(int threadId, string updatedText)
 {
     IndexRecords.Add(IndexRecord);
 }