1
yanjinhui
10 天以前 0b81608b03c5e1e8a20db987dd04cb45bd94c1ad
1
已添加8个文件
152 ■■■■■ 文件已修改
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/DownLoad/face-plugin.zip 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/AutoMapperConfig.cs 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/AutoMapperSetup.cs 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/AutofacPropertityModuleReg.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/CustomAuthorizeFilter.cs 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/CustomProfile.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/WebSocketHostService.cs 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/WebSocketSetup.cs 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/DownLoad/face-plugin.zip
Binary files differ
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/AutoMapperConfig.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,18 @@
using AutoMapper;
namespace WIDESEAWCS_WCSServer.Filter
{
    /// <summary>
    /// é™æ€å…¨å±€ AutoMapper é…ç½®æ–‡ä»¶
    /// </summary>
    public class AutoMapperConfig
    {
        public static MapperConfiguration RegisterMappings()
        {
            return new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new CustomProfile());
            });
        }
    }
}
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/AutoMapperSetup.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,16 @@
namespace WIDESEAWCS_WCSServer.Filter
{
    /// <summary>
    /// Automapper å¯åŠ¨æœåŠ¡
    /// </summary>
    public static class AutoMapperSetup
    {
        public static void AddAutoMapperSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            services.AddAutoMapper(typeof(AutoMapperConfig));
            AutoMapperConfig.RegisterMappings();
        }
    }
}
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/AutofacPropertityModuleReg.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,17 @@
using Autofac;
using Microsoft.AspNetCore.Mvc;
namespace WIDESEAWCS_WCSServer.Filter
{
    public class AutofacPropertityModuleReg : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            var controllerBaseType = typeof(ControllerBase);
            builder.RegisterAssemblyTypes(typeof(Program).Assembly)
                .Where(t => controllerBaseType.IsAssignableFrom(t) && t != controllerBaseType)
                .PropertiesAutowired();
        }
    }
}
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/CustomAuthorizeFilter.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
namespace WIDESEAWCS_Server.Filter
{
    public class CustomAuthorizeFilter : IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            // ä½ çš„自定义授权逻辑
            // ä¾‹å¦‚,‌检查用户是否已登录,‌或者他们是否有特定的角色或权限
            if (!context.HttpContext.User.Identity.IsAuthenticated)
            {
                // ç”¨æˆ·æœªç™»å½•,‌重定向到登录页面或返回401状态码
                context.Result = new ChallengeResult();
            }
        }
    }
}
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/CustomProfile.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,27 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_DTO.System;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
namespace WIDESEAWCS_WCSServer.Filter
{
    public class CustomProfile : Profile
    {
        /// <summary>
        /// é…ç½®æž„造函数,用来创建关系映射
        /// </summary>
        public CustomProfile()
        {
            CreateMap<Sys_Menu, MenuDTO>();
            CreateMap<Dt_DeviceInfo,DeviceInfoDTO>();
            CreateMap<WMSTaskDTO, Dt_Task>().ForMember(a => a.WMSId, b => b.MapFrom(b => b.Id));
        }
    }
}
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/WebSocketHostService.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,25 @@

using HslCommunication.WebSocket;
namespace WIDESEAWCS_Server.Filter
{
    public class WebSocketHostService : IHostedService
    {
        WebSocketServer _webSocketServer;
         public WebSocketHostService(WebSocketServer webSocketServer)
        {
            _webSocketServer = webSocketServer;
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _webSocketServer.PublishAllClientPayload("程序启动");
            return Task.CompletedTask;
        }
        public Task StopAsync(CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }
    }
}
ÏîÄ¿´úÂë/ºó¶Ë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/WebSocketSetup.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,29 @@
using HslCommunication.WebSocket;
using WIDESEAWCS_Core.Helper;
namespace WIDESEAWCS_Server.HostedService
{
    public static class WebSocketSetup
    {
        public static void AddWebSocketSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            if(AppSettings.Get("WebSocketEnable").ObjToBool())
            {
                int port = AppSettings.Get("WebSocketPort").ObjToInt();
                if (port == 0)
                {
                    port = 9296;
                }
                services.AddSingleton(x =>
                {
                    WebSocketServer socketServer = new WebSocketServer();
                    socketServer.ServerStart(port);
                    return socketServer;
                });
            }
        }
    }
}