Пример #1
0
        //--------------------------------------------------------------------------
        private Document InsertDocument(DocumentParser document)
        {
            // first, check if the document already exists
            Document doc = DocumentsDao.GetDocumentById(document.GutenbergId);

            if ((doc != null) &&
                (doc.TableLoadState == Document.LoadState.Complete))
            {
                throw new Exception("document already exists!");
            }

            if (doc != null)
            {
                // if the document exists but the load state wasn't complete, it means
                // we probably failed to load it previously and so we will run a clean
                // up before trying to reload it
                CleanupDocument(doc);
                doc = null;
            }

            // check we have the minimal set of meta data
            doc = GenerateDocumentModel(document);
            DocumentsDao.Insert(doc);
            _documentCache[doc.Id] = doc;
            return(doc);
        }
Пример #2
0
        //-------------------------------------------------------------------------
        public void Import(XmlDocument document, FileInfo importFilename)
        {
            ImportStorage(importFilename);

            _documentCache.Clear();

            GlobalParamatersService.Delegate.OnDatabaseImportProgress(0);

            DatabaseConnectionService.Instance.SafeTransaction(_ => {
                XmlNodeList xmlDocuments =
                    document.DocumentElement.SelectNodes(".//document");

                int total     = xmlDocuments.Count;
                int processed = 0;

                foreach (XmlNode xmlDocument in xmlDocuments)
                {
                    Document doc           = DocumentsDao.Import(xmlDocument);
                    _documentCache[doc.Id] = doc;

                    processed++;
                    float percent = (float)processed / (float)total;
                    percent      *= 100;
                    GlobalParamatersService.Delegate.OnDatabaseImportProgress(
                        (int)percent);
                }
            });
        }
Пример #3
0
        //--------------------------------------------------------------------------
        private void CleanupDocument(Document doc)
        {
            if (doc == null)
            {
                return;
            }

            ContainsDao.DeleteByDocument(doc);

            _documentCache.Remove(doc.Id);
            DocumentsDao.Delete(doc);
        }
Пример #4
0
        //--------------------------------------------------------------------------
        public Document GetById(long documentId)
        {
            if (_documentCache.ContainsKey(documentId))
            {
                return(_documentCache[documentId]);
            }

            Document document = DocumentsDao.GetDocumentById(documentId);

            _documentCache[document.Id] = document;
            return(document);
        }
Пример #5
0
        //--------------------------------------------------------------------------
        public List <Document> Query(
            List <string> words,
            List <DocumentProperty> properties)
        {
            List <Document> documents = DocumentsDao.Query(words, properties);

            // NOTE: it seems to me to be more efficient if we query the entire
            // Document object from the Dao in this scenario - instaed of getting only
            // a list of IDs and then calling |GetById| on each
            foreach (Document document in documents)
            {
                _documentCache[document.Id] = document;
            }

            return(documents);
        }
Пример #6
0
        //--------------------------------------------------------------------------
        /// <summary>
        /// The function uses all information in SQL tables in the program mySQL and
        /// builds a new XML file containing all that information.
        /// The XML file describes all the books'information
        /// </summary>
        public void ExportDatabase(FileInfo filename)
        {
            Initialize();

            DataSet ds = new DataSet();

            ds.DataSetName = "books-concordance";
            DocumentsDao.FillDataSet(ds);
            WordsDao.FillDataSet(ds);
            ContainsDao.FillDataSet(ds);
            RelationsDao.FillDataSet(ds);
            GroupsDao.FillDataSet(ds);
            PhrasesDao.FillDataSet(ds);

            ds.WriteXml(filename.FullName);

            DocumentsService.Instance.ExportStorage(filename);
        }
Пример #7
0
        //--------------------------------------------------------------------------
        public bool Load(FileInfo file)
        {
            DocumentParser documentParser = DocumentParser.FromFile(file);

            GlobalParamatersService.Delegate.OnLoadDocumentParsed(file);

            // Insert the document into the DB
            Document document = InsertDocument(documentParser);

            // load document's contents into DB - this can be a very long task
            // due to the amounts of INSERT statements performed - therefore,
            // we wrap the call to |InsertWords| inside a transaction and basically
            // perform one big bulk.  This tremendously improves performance
            DatabaseConnectionService.Instance.SafeTransaction(_ => {
                InsertWords(file, documentParser, document);
                document.TableLoadState = Document.LoadState.Complete;
                DocumentsDao.Update(document);
            });

            GlobalParamatersService.Delegate.OnLoadDocumentComplete(
                file, true, null);
            return(true);
        }
Пример #8
0
 //--------------------------------------------------------------------------
 public List <Document> QueryByWords(List <string> words)
 {
     return(DocumentsDao.QueryByWords(words));
 }
Пример #9
0
 //--------------------------------------------------------------------------
 public void DropTable()
 {
     DocumentsDao.DropTable();
     _documentCache.Clear();
 }
Пример #10
0
 //--------------------------------------------------------------------------
 public void CreateTable()
 {
     DocumentsDao.CreateTable();
 }
Пример #11
0
 //--------------------------------------------------------------------------
 public Int64 GetCount()
 {
     return(DocumentsDao.GetCount());
 }