//================================================================================================ Internal methods private static void RefreshArticlesAsyncInternal(WikiArticle targetArticle, WikiArticleAction articleAction, string oldName, string oldDisplayName) { if (targetArticle == null || !StorageContext.Search.IsOuterEngineEnabled) return; QueryResult results; //background task, needs to run in admin mode using (new SystemAccount()) { var ws = Workspace.GetWorkspaceForNode(targetArticle); var displayNameFilter = string.IsNullOrEmpty(oldDisplayName) ? string.Format("\"{0}\"", targetArticle.DisplayName) : string.Format("(\"{0}\" \"{1}\")", targetArticle.DisplayName, oldDisplayName); results = ContentQuery.Query(string.Format("+TypeIs:WikiArticle +ReferencedWikiTitles:{0} +InTree:\"{1}\"", displayNameFilter, ws.Path), new QuerySettings {EnableAutofilters = false}); if (results.Count == 0) return; foreach (var article in results.Nodes.Cast<WikiArticle>()) { var articleData = article.WikiArticleText ?? string.Empty; var found = false; switch (articleAction) { case WikiArticleAction.Create: //find references to NONEXISTING articles articleData = ReplaceAddLinksWithExistingLinks(articleData, targetArticle, ref found); break; case WikiArticleAction.Delete: //find references to EXISTING articles articleData = ReplaceExistingLinksWithAddLinks(articleData, targetArticle.Parent, targetArticle.Path, targetArticle.DisplayName, ref found); break; case WikiArticleAction.Rename: //find references to EXISTING articles articleData = ReplaceOldLinksWithRenamedLinks(articleData, targetArticle, RepositoryPath.Combine(targetArticle.ParentPath, oldName), oldDisplayName, ref found); break; } if (!found) continue; article.WikiArticleText = articleData; //TODO: this is a technical save, so set ModificationDate and //ModifiedBy fields to the original values!!!!!!! article.Save(SavingMode.KeepVersion); } } }
public static void RefreshArticlesAsync(WikiArticle targetArticle, WikiArticleAction articleAction) { var refreshArticlesDelegate = new RefreshArticlesDelegate(RefreshArticlesAsyncInternal); refreshArticlesDelegate.BeginInvoke(targetArticle, articleAction, null, null, null, null); }
// ================================================================================================ Internal methods private static void RefreshArticlesAsyncInternal(WikiArticle targetArticle, WikiArticleAction articleAction, string oldName, string oldDisplayName) { if (targetArticle == null || !SearchManager.ContentQueryIsAllowed) { return; } // background task, needs to run in admin mode using (new SystemAccount()) { var ws = Workspace.GetWorkspaceForNode(targetArticle); var displayNameFilter = string.IsNullOrEmpty(oldDisplayName) ? $"\"{targetArticle.DisplayName}\"" : $"(\"{targetArticle.DisplayName}\" \"{oldDisplayName}\")"; var results = ContentQuery.Query(Compatibility.SafeQueries.WikiArticlesByReferenceTitlesAndSubtree, new QuerySettings { EnableAutofilters = FilterStatus.Disabled }, displayNameFilter, ws.Path); if (results.Count == 0) { return; } foreach (var article in results.Nodes.Cast <WikiArticle>()) { var articleData = article.WikiArticleText ?? string.Empty; var found = false; switch (articleAction) { case WikiArticleAction.Create: // find references to NONEXISTING articles articleData = ReplaceAddLinksWithExistingLinks(articleData, targetArticle, ref found); break; case WikiArticleAction.Delete: // find references to EXISTING articles articleData = ReplaceExistingLinksWithAddLinks(articleData, targetArticle.Parent, targetArticle.Path, targetArticle.DisplayName, ref found); break; case WikiArticleAction.Rename: // find references to EXISTING articles articleData = ReplaceOldLinksWithRenamedLinks(articleData, targetArticle, RepositoryPath.Combine(targetArticle.ParentPath, oldName), oldDisplayName, ref found); break; } if (!found) { continue; } article.WikiArticleText = articleData; //TODO: this is a technical save, so set ModificationDate and ModifiedBy fields to the original values!!!!!!! article.Save(SavingMode.KeepVersion); } } }
//================================================================================================ Internal methods private static void RefreshArticlesAsyncInternal(WikiArticle targetArticle, WikiArticleAction articleAction, string oldName, string oldDisplayName) { if (targetArticle == null || !StorageContext.Search.IsOuterEngineEnabled) { return; } QueryResult results; //background task, needs to run in admin mode using (new SystemAccount()) { var ws = Workspace.GetWorkspaceForNode(targetArticle); var displayNameFilter = string.IsNullOrEmpty(oldDisplayName) ? string.Format("\"{0}\"", targetArticle.DisplayName) : string.Format("(\"{0}\" \"{1}\")", targetArticle.DisplayName, oldDisplayName); results = ContentQuery.Query(string.Format("+TypeIs:WikiArticle +ReferencedWikiTitles:{0} +InTree:\"{1}\"", displayNameFilter, ws.Path), new QuerySettings { EnableAutofilters = false }); if (results.Count == 0) { return; } foreach (var article in results.Nodes.Cast <WikiArticle>()) { var articleData = article.WikiArticleText ?? string.Empty; var found = false; switch (articleAction) { case WikiArticleAction.Create: //find references to NONEXISTING articles articleData = ReplaceAddLinksWithExistingLinks(articleData, targetArticle, ref found); break; case WikiArticleAction.Delete: //find references to EXISTING articles articleData = ReplaceExistingLinksWithAddLinks(articleData, targetArticle.Parent, targetArticle.Path, targetArticle.DisplayName, ref found); break; case WikiArticleAction.Rename: //find references to EXISTING articles articleData = ReplaceOldLinksWithRenamedLinks(articleData, targetArticle, RepositoryPath.Combine(targetArticle.ParentPath, oldName), oldDisplayName, ref found); break; } if (!found) { continue; } article.WikiArticleText = articleData; //TODO: this is a technical save, so set ModificationDate and //ModifiedBy fields to the original values!!!!!!! article.Save(SavingMode.KeepVersion); } } }