src/ZKEACMS.Article/Service/ArticleUrlService.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy;
using Easy.Extend;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZKEACMS.Article.Models;

namespace ZKEACMS.Article.Service
{
    public class ArticleUrlService : IArticleUrlService
    {
        private readonly IArticleService _articleService;
        private readonly IArticleListWidgetDataService _articleListWidgetService;
        private readonly IArticleTypeService _articleTypeService;

        public ArticleUrlService(IArticleService articleService,
            IArticleListWidgetDataService articleListWidgetService,
            IArticleTypeService articleTypeService)
        {
            _articleService = articleService;
            _articleListWidgetService = articleListWidgetService;
            _articleTypeService = articleTypeService;
        }

        public IEnumerable<ArticleUrl> GetAllPublicUrls()
        {
            HashSet<string> excuted = new HashSet<string>();
            foreach (var item in _articleListWidgetService.Get().ToList())
            {
                string typeDetail = $"{item.DetailPageUrl}-{item.ArticleTypeID}";
                if (item.DetailPageUrl.IsNotNullAndWhiteSpace() && !excuted.Contains(typeDetail))
                {
                    var ids = _articleTypeService.Get(m => m.ID == item.ArticleTypeID || m.ParentID == item.ArticleTypeID).Select(m => m.ID).ToList();
                    var articles = _articleService.Get(m => m.IsPublish && ids.Contains(m.ArticleTypeID ?? 0));
                    foreach (var article in articles)
                    {
                        string post = article.Url.IsNullOrWhiteSpace() ? $"post-{article.ID}" : article.Url;
                        yield return new ArticleUrl
                        {
                            Url = Helper.Url.ToVirtualPath($"{item.DetailPageUrl}/{post}.html"),
                            Article = article
                        };
                    }
                    excuted.Add(typeDetail);
                }
            }
        }

        public string[] GetDetailPages()
        {
            return _articleListWidgetService.Get(m => m.DetailPageUrl != null)
                .Select(m => Helper.Url.ToVirtualPath(m.DetailPageUrl)).Distinct().ToArray();
        }

        public string[] GetPublicUrl(int ID)
后面还有 28 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。