Beispiel #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);
        }
Beispiel #2
0
        //--------------------------------------------------------------------------
        public Document GetById(long documentId)
        {
            if (_documentCache.ContainsKey(documentId))
            {
                return(_documentCache[documentId]);
            }

            Document document = DocumentsDao.GetDocumentById(documentId);

            _documentCache[document.Id] = document;
            return(document);
        }