Exemplo n.º 1
0
 public static DocumentModel GetDocument(int id)
 {
     using (var db = new DocumentDbContext())
     {
         return(db.Documents.Single(x => x.Id == id));
     }
 }
Exemplo n.º 2
0
 public static List <DocumentModel> GetAllDocuments()
 {
     using (var db = new DocumentDbContext())
     {
         return(db.Documents.ToList());
     }
 }
Exemplo n.º 3
0
        public static void AddDocument(string path)
        {
            var extractor = new TikaOnDotNet.TextExtraction.TextExtractor();
            var result    = extractor.Extract(path);

            string description = result.Metadata?.FirstOrDefault(x => x.Key.ToLower() == "description").Value; //pobiera wartości z metadanych
            string author      = result.Metadata?.FirstOrDefault(x => x.Key.ToLower() == "author").Value;
            string title       = result.Metadata?.FirstOrDefault(x => x.Key.ToLower() == "title").Value;

            var document = new Models.DocumentModel()
            {
                FileName    = Path.GetFileName(path),
                Author      = (author == null) ? "": author,
                Description = (description == null) ? "" : description,
                Title       = (title == null) ? "" : title
            };

            using (var db = new DocumentDbContext())
            {
                db.Documents.Add(document);
                db.SaveChanges();
            }
            Services.LuceneSearch.AddUpdateLuceneIndex(document);
        }
Exemplo n.º 4
0
        public static string GetContent(int id)
        {
            string path;
            string fileName;
            string result;

            using (var db = new DocumentDbContext())
            {
                fileName = db.Documents.Single(x => x.Id == id).FileName;
            }

            path = Path.Combine(HttpContext.Current.Server.MapPath("~/Files/"), fileName);

            if (Path.GetExtension(fileName) == ".html")
            {
                result = getHtmlContent(path);
            }
            else
            {
                result = getDocumentContent(path);
            }

            return(result);
        }