public void Dispose() { disposed = true; isInitialized = false; Directory = null; if (processor != null) { processor.Dispose(); } processor = null; }
public bool Initialize() { if (disposed) { throw new ObjectDisposedException(nameof(Database <T>)); } if (isInitialized) { return(false); } processor = new DatabaseProcessor <T>(this); processor.LoadIndex(); isInitialized = true; return(isInitialized); }
/// <summary> /// Handles the index building process for specified range. /// </summary> private void BuildIndex(IDatabaseProcessor <T> processor, FileInfo[] dataFiles, int startIndex, int loopCount) { var localIndex = new JObject[loopCount]; for (int i = 0; i < loopCount; i++) { var file = dataFiles[i + startIndex]; localIndex[i] = processor.LoadData(Path.GetFileNameWithoutExtension(file.Name), false).SerializeIndex(); } lock (index) { for (int i = 0; i < localIndex.Length; i++) { Set(localIndex[i]); } } }
/// <summary> /// Rebuilds index from scratch using specified data files. /// </summary> private void RebuildIndex(IDatabaseProcessor <T> processor) { var dataFiles = processor.GetDataFiles(); // Task allocation variables int taskCount = (dataFiles.Length - 1) / RebuildDataPerTask + 1; var tasks = new Task[taskCount]; // Allocate tasks for (int i = 0; i < taskCount; i++) { int startIndex = i * RebuildDataPerTask; int loopCount = Math.Min(RebuildDataPerTask, dataFiles.Length - startIndex); tasks[i] = Task.Run(() => BuildIndex(processor, dataFiles, startIndex, loopCount)); } // Wait for all tasks to finish. Task.WaitAll(tasks); }
public DatabaseQuery(IDatabaseProcessor <T> processor) { this.processor = processor; }
public void Dispose() { disposed = true; processor = null; filterHandlers = null; }
public DatabaseEditor(IDatabaseProcessor <T> processor) { this.processor = processor; }
public DatabaseIndex(IDatabaseProcessor <T> processor) { RebuildIndex(processor); }