コード例 #1
0
ファイル: PageList.cs プロジェクト: moayyaed/YetaWF-Modules
        /// <summary>
        /// Create a page list for the current site.
        /// </summary>
        public async Task <string> CreateAsync()
        {
            StringBuilder sb = new StringBuilder();

            // Designed pages (only)
            List <Guid> pageGuids = await PageDefinition.GetDesignedGuidsAsync();

            List <string> pages = new List <string>();

            foreach (Guid guid in pageGuids)
            {
                PageDefinition page = await PageDefinition.LoadPageDefinitionAsync(guid);

                if (page != null)
                {
                    pages.Add(page.EvaluatedCanonicalUrl);
                }
            }
            pages = pages.OrderBy(s => s).ToList();
            foreach (string page in pages)
            {
                sb.AppendLine(Manager.CurrentSite.MakeFullUrl(page));
            }
            return(sb.ToString());
        }
コード例 #2
0
ファイル: SiteMaps.cs プロジェクト: moayyaed/YetaWF-Modules
        /// <summary>
        /// Creates a site map for the current site.
        /// </summary>
        public async Task CreateAsync(bool slow = false)
        {
            string file = GetTempFile();
            await FileSystem.FileSystemProvider.DeleteFileAsync(file);

            // header
            await FileSystem.FileSystemProvider.AppendAllTextAsync(file,
                                                                   "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" +
                                                                   "<urlset xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns =\"http://www.sitemaps.org/schemas/sitemap/0.9\" >\r\n"
                                                                   );

            // Dynamic Urls in types
            DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl();
            List <Type>     types       = dynamicUrls.GetDynamicUrlTypes();

            foreach (Type type in types)
            {
                ISiteMapDynamicUrls iSiteMap = Activator.CreateInstance(type) as ISiteMapDynamicUrls;
                if (iSiteMap != null)
                {
                    await iSiteMap.FindDynamicUrlsAsync(AddSiteMapPageAsync, ValidForSiteMap);
                }
            }

            // search all designed modules that have dynamic urls
            foreach (DesignedModule desMod in await DesignedModules.LoadDesignedModulesAsync())
            {
                ModuleDefinition mod = await ModuleDefinition.LoadAsync(desMod.ModuleGuid, AllowNone : true);

                if (mod != null)
                {
                    ISiteMapDynamicUrls iSiteMap = mod as ISiteMapDynamicUrls;
                    if (iSiteMap != null)
                    {
                        await iSiteMap.FindDynamicUrlsAsync(AddSiteMapPageAsync, ValidForSiteMap);
                    }
                }
            }

            // Designed pages
            List <Guid> pages = await PageDefinition.GetDesignedGuidsAsync();

            foreach (Guid pageGuid in pages)
            {
                PageDefinition page = await PageDefinition.LoadAsync(pageGuid);

                if (page == null)
                {
                    continue;
                }
                if (!PagesFound.Contains(page.PageGuid)) // don't include same again (this could be a page that generates dynamic Urls)
                {
                    await AddUrlAsync(file, page, page.EvaluatedCanonicalUrl, page.Updated, page.SiteMapPriority, page.ChangeFrequency);
                }
            }

            // end
            await FileSystem.FileSystemProvider.AppendAllTextAsync(file,
                                                                   "</urlset>\r\n"
                                                                   );

            string finalFile = GetFile();
            await FileSystem.FileSystemProvider.DeleteFileAsync(finalFile);

            await FileSystem.FileSystemProvider.MoveFileAsync(file, finalFile);

            if (Manager.CurrentSite.DefaultSiteMap)
            {
                await FileSystem.FileSystemProvider.CopyFileAsync(finalFile, Path.Combine(YetaWFManager.RootFolder, "sitemap.xml"));
            }
        }
コード例 #3
0
ファイル: Search.cs プロジェクト: moayyaed/YetaWF-Modules
        public async Task SearchSiteAsync(bool slow)
        {
            SearchConfigData searchConfig = await SearchConfigDataProvider.GetConfigAsync();

            DateTime searchStarted = DateTime.UtcNow; // once we have all new keywords, delete all keywords that were added before this date/time

            using (SearchDataProvider searchDP = new SearchDataProvider()) {
                // Search all generated pages (unique modules or classes, like data providers)
                DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl();
                List <Type>     types       = dynamicUrls.GetDynamicUrlTypes();
                // search types that generate dynamic urls
                foreach (Type type in types)
                {
#if DEBUG
                    //                  if (type.Name != "FileDocumentDisplayModule") continue;//used for debugging
#endif
                    ISearchDynamicUrls iSearch = Activator.CreateInstance(type) as ISearchDynamicUrls;
                    if (iSearch != null)
                    {
                        try {
                            SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted);
                            await iSearch.KeywordsForDynamicUrlsAsync(searchWords);

                            if (slow)
                            {
                                Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items)
                            }
                        } catch (Exception exc) {
                            Logging.AddErrorLog("KeywordsForDynamicUrls failed for {0}", type.FullName, exc);
                        }
                    }
                }

                // search all designed modules that have dynamic urls
                foreach (DesignedModule desMod in await DesignedModules.LoadDesignedModulesAsync())
                {
                    try {
                        ModuleDefinition mod = await ModuleDefinition.LoadAsync(desMod.ModuleGuid, AllowNone : true);

                        if (mod != null && types.Contains(mod.GetType()) && mod.WantSearch)
                        {
                            ISearchDynamicUrls iSearch = mod as ISearchDynamicUrls;
                            if (iSearch != null)
                            {
                                SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted);
                                await iSearch.KeywordsForDynamicUrlsAsync(searchWords);

                                if (slow)
                                {
                                    Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items)
                                }
                            }
                        }
                    } catch (Exception exc) {
                        Logging.AddErrorLog("KeywordsForDynamicUrls failed for module {0}", desMod.ModuleGuid, exc);
                    }
                }

                // Search all designed pages and extract keywords
                List <Guid> pages = await PageDefinition.GetDesignedGuidsAsync();

                foreach (Guid pageGuid in pages)
                {
                    PageDefinition page = await PageDefinition.LoadAsync(pageGuid);

                    if (page != null)
                    {
                        SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted);
                        await SearchPageAsync(searchWords, page);

                        if (slow)
                        {
                            Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items)
                        }
                    }
                }

                // Remove old keywords
                await searchDP.RemoveOldItemsAsync(searchStarted);
            }
        }