private void AddChangedPage(string fullPath, object sender, HashSet <string> changedPageUrls) { var replaced = fullPath.Replace('\\', '/'); var pageUrl = AppUrl.ConvertAbsoluteAppPathToUrl(replaced); var directoryEvent = sender == CmsPageWatcher || sender == ContentPageWatcher; if (!directoryEvent) { pageUrl = AppPath.GetDirectoryName(pageUrl); } if (!changedPageUrls.Contains(pageUrl)) { changedPageUrls.Add(pageUrl); } }
private static async Task HandleChangedAppPages(IHtmlHelper htmlHelper) { // Just an extra check so that unnecessary semaphore is avoided if (PageWatcher.CmsPageWatcherFailed || PageWatcher.ContentPageWatcherFailed || PageWatcher.CmsChangedPageUrls.Count > 0 || PageWatcher.ContentChangedPageUrls.Count > 0) { await PageSemaphoreSlim.WaitAsync(); // Only one thread can execute this at a time try { if (PageWatcher.CmsPageWatcherFailed || PageWatcher.ContentPageWatcherFailed) { PageHandler.AppPagesByUrl.Clear(); PageWatcher.CmsPageWatcherFailed = false; PageWatcher.ContentPageWatcherFailed = false; PageWatcher.CmsChangedPageUrls.Clear(); PageWatcher.ContentChangedPageUrls.Clear(); } var allPageUrls = PageWatcher.ContentChangedPageUrls.Concat(PageWatcher.CmsChangedPageUrls); foreach (var pageUrl in allPageUrls) { if (AppPage.IsUrlAppPage(pageUrl)) { var appPage = await Pages.GetByUrl(pageUrl); await appPage.Reload(); } else { // Page has been removed or no longer exists Pages.RemoveUrl(pageUrl); } if (pageUrl != AppUrl.SeparatorString && pageUrl != "") { // Refresh parent page as well var parentUrl = AppPath.GetDirectoryName(pageUrl); if (AppPage.IsUrlAppPage(parentUrl)) { var parentPage = await Pages.GetByUrl(parentUrl); await parentPage.Reload(); } } } PageWatcher.CmsChangedPageUrls.Clear(); PageWatcher.ContentChangedPageUrls.Clear(); } finally { PageSemaphoreSlim.Release(); } } }