public void RebuildIndexes() { var categories = CategoryRepository.GetAllCategories(); var totalCategories = categories.Count(); var indexingCategory = 1; foreach (var cat in categories) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, "-"); var articles = CategoryRepository.GetArticles(cat.Id); foreach (var article in articles) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, article.Title); foreach (var attachment in article.Attachments) { try { KbVaultLuceneHelper.RemoveAttachmentFromIndex(attachment); KbVaultLuceneHelper.AddAttachmentToIndex(attachment); } #pragma warning disable CC0004 // Catch block cannot be empty catch (Exception) { } #pragma warning restore CC0004 // Catch block cannot be empty } KbVaultLuceneHelper.AddArticleToIndex(article); } indexingCategory++; } Clients.All.updateProgress(string.Empty, string.Empty, string.Empty, "Finished indexing"); }
public void RebuildIndexes() { var categories = CategoryRepository.GetAllCategories(); int totalCategories = categories.Count(); int indexingCategory = 1; foreach (var cat in categories) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, "-"); var articles = CategoryRepository.GetArticles(cat.Id); foreach (var article in articles) { Clients.All.updateProgress(indexingCategory, totalCategories, cat.Name, article.Title); foreach (var attachment in article.Attachments) { try { KbVaultLuceneHelper.RemoveAttachmentFromIndex(attachment); KbVaultLuceneHelper.AddAttachmentToIndex(attachment); } catch (Exception ex) { //Eat it :d } } KbVaultLuceneHelper.AddArticleToIndex(article); } indexingCategory++; } Clients.All.updateProgress("", "", "", "Finished indexing"); }
public JsonResult Upload() { var result = new JsonOperationResponse { Successful = false }; try { if (Request.Query["ArticleId"] == "") { //result.ErrorMessage = Resources.ErrorMessages.FileUploadArticleNotFound; result.ErrorMessage = "FileUploadArticleNotFound"; } else if (Request.Form.Files.Count == 1) { var articleId = Convert.ToInt64(HttpContext.Request.Query["ArticleId"]); var attachedFile = Request.Form.Files[0]; //var attachment = KbVaultAttachmentHelper.SaveAttachment(articleId, attachedFile, KBVaultHelperFunctions.UserAsKbUser(User).Id, _env); //attachment.Author = KBVaultHelperFunctions.UserAsKbUser(User).Id; var attachment = SaveAttachment(articleId, attachedFile, _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), _env); attachment.AuthorId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); result.Successful = true; //result.Data = new AttachmentViewModel(attachment, _actionContextAccessor); result.Data = new AttachmentViewModel(attachment, _httpContextAccessor); //using (var db = new KbVaultContext(_config)) //{ var sets = _context.Settings.FirstOrDefault(); if (sets != null) { var extensions = sets.IndexFileExtensions.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (extensions.FirstOrDefault(a => a.ToLowerInvariant() == attachment.Extension.ToLowerInvariant()) != null) { //todo VRATI SE _lucene.AddAttachmentToIndex(attachment); } } //} } else { //result.ErrorMessage = Resources.ErrorMessages.FileUploadTooManyFiles; result.ErrorMessage = "FileUploadTooManyFiles"; } return(Json(result)); } catch (Exception ex) { log.Error(ex); result.ErrorMessage = ex.Message; return(Json(result)); } }
public JsonResult Upload() { var result = new JsonOperationResponse { Successful = false }; try { if (Request.Params["ArticleId"] == null) { result.ErrorMessage = ErrorMessages.FileUploadArticleNotFound; } else if (Request.Files.Count == 1) { var articleId = Convert.ToInt64(Request.Params["ArticleId"]); var attachedFile = Request.Files[0]; var attachment = KbVaultAttachmentHelper.SaveAttachment(articleId, attachedFile, KBVaultHelperFunctions.UserAsKbUser(User).Id); attachment.Author = KBVaultHelperFunctions.UserAsKbUser(User).Id; result.Successful = true; result.Data = new AttachmentViewModel(attachment); using (var db = new KbVaultContext()) { var sets = db.Settings.FirstOrDefault(); if (sets != null) { var extensions = sets.IndexFileExtensions.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (extensions.FirstOrDefault(a => a.ToLowerInvariant() == attachment.Extension.ToLowerInvariant()) != null) { KbVaultLuceneHelper.AddAttachmentToIndex(attachment); } } } } else { result.ErrorMessage = ErrorMessages.FileUploadTooManyFiles; } return(Json(result)); } catch (Exception ex) { log.Error(ex); result.ErrorMessage = ex.Message; return(Json(result)); } }