src/ZKEACMS.Redirection/Service/UrlRedirectService.cs

(开头部分) 5KB

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

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

using Easy;
using Easy.Cache;
using Easy.Constant;
using Easy.RepositoryPattern;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ZKEACMS.Redirection.Models;

namespace ZKEACMS.Redirection.Service
{
    public class UrlRedirectService : ServiceBase<UrlRedirect, CMSDbContext>, IUrlRedirectService
    {
        private const string CacheKey = "AllUrlRedirectItems";
        private readonly ICacheManager<IEnumerable<UrlRedirect>> _cacheManager;
        public UrlRedirectService(IApplicationContext applicationContext, CMSDbContext dbContext, ICacheManager<IEnumerable<UrlRedirect>> cacheManager) : base(applicationContext, dbContext)
        {
            _cacheManager = cacheManager;
        }
        private void RemoveCache()
        {
            _cacheManager.Remove(CacheKey);
        }
        private ServiceResult<UrlRedirect> PatternTest(UrlRedirect item)
        {
            ServiceResult<UrlRedirect> exceptionResult = new ServiceResult<UrlRedirect>();
            if (item.IsPattern ?? false)
            {
                try
                {
                    item.ParsePattern();
                }
                catch (Exception ex)
                {
                    exceptionResult.AddRuleViolation("InComingUrl", ex.Message);

                }
            }
            return exceptionResult;
        }
        private ServiceResult<UrlRedirect> LoopTest(UrlRedirect item)
        {
            ServiceResult<UrlRedirect> result = new ServiceResult<UrlRedirect>();
            List<string> direction = new List<string>();
            direction.Add(item.DestinationURL.ToLowerInvariant());
            UrlRedirect destiantion = item;
            List<UrlRedirect> allRedirects = GetAll().Where(m => m.ID != item.ID).ToList();
            allRedirects.Add(item);
            while (true)
            {
                destiantion = allRedirects.FirstOrDefault(m => m.IsMatch(destiantion.DestinationURL));
                if (destiantion == null)
                {
                    break;
后面还有 111 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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