using System; using System.Collections.Generic; using System.Linq; using System.Text; using ScrewTurn.Wiki.SearchEngine; using System.Data.Common; namespace ScrewTurn.Wiki.Plugins.SqlCommon { /// /// Defines a connector between an index and a pages storage provider. /// public class IndexConnector : IIndexConnector { private GetWordFetcher getWordFetcher; private GetSize getSize; private GetCount getCount; private ClearIndex clearIndex; private DeleteDataForDocument deleteData; private SaveDataForDocument saveData; private TryFindWord tryFindWord; /// /// Initializes a new instance of the class. /// /// The GetWordFetcher delegate. /// The GetSize delegate. /// The GetCount delegate. /// The ClearIndex delegate. /// The DeleteDataForDocument delegate. /// The SaveData delegate. /// The TryFindWord delegate. public IndexConnector(GetWordFetcher getWordFetcher, GetSize getSize, GetCount getCount, ClearIndex clearIndex, DeleteDataForDocument deleteData, SaveDataForDocument saveData, TryFindWord tryFindWord) { if(getWordFetcher == null) throw new ArgumentNullException("getWordFetcher"); if(getSize == null) throw new ArgumentNullException("getSize"); if(getCount == null) throw new ArgumentNullException("getCount"); if(clearIndex == null) throw new ArgumentNullException("clearIndex"); if(deleteData == null) throw new ArgumentNullException("deleteData"); if(saveData == null) throw new ArgumentNullException("saveData"); if(tryFindWord == null) throw new ArgumentNullException("tryFindWord"); this.getWordFetcher = getWordFetcher; this.getSize = getSize; this.getCount = getCount; this.clearIndex = clearIndex; this.deleteData = deleteData; this.saveData = saveData; this.tryFindWord = tryFindWord; } /// /// Invokes the GetWordFetcher delegate. /// /// The word fetcher. public IWordFetcher GetWordFetcher() { return getWordFetcher(); } /// /// Defines a delegate for a method that gets the size of the approximate index in bytes. /// /// The size of the index, in bytes. public long GetSize() { return getSize(); } /// /// Invokes the GetCount delegate. /// /// The element type. /// The element count. public int GetCount(IndexElementType element) { return getCount(element); } /// /// Invokes the ClearIndex delegate. /// /// A state object passed from the index. public void ClearIndex(object state) { clearIndex(state); } /// /// Invokes the DeleteDataForDocument delegate. /// /// The document. /// A state object passed from the index. public void DeleteDataForDocument(IDocument document, object state) { deleteData(document, state); } /// /// Invokes the SaveDataForDocument delegate. /// /// The document. /// The content words. /// The title words. /// The keywords. /// A state object passed from the index. /// The number of stored occurrences. public int SaveDataForDocument(IDocument document, WordInfo[] content, WordInfo[] title, WordInfo[] keywords, object state) { return saveData(document, content, title, keywords, state); } } }