添加跨域策略

main
xiaoguo 2 years ago
parent d6a4fec1cd
commit 2770f0434d

Binary file not shown.

@ -1,15 +0,0 @@
using PVDEMCS.Common.DI;
using PVDEMCS.Services;
namespace PVDEMCS.Common.Configuration
{
public class DeviceConfiguration : IDependency
{
public DeviceConfiguration(IDeviceService deviceService)
{
}
}
}

@ -0,0 +1,12 @@
using PVDEMCS.Common.DI;
using PVDEMCS.Services;
namespace PVDEMCS.Common.Devices
{
public interface IDeviceConfiguration : IDependency
{
}
}

@ -1,61 +0,0 @@
using PVDEMCS.Common.DI;
using PVDEMCS.Services.Models;
using System.Security.Cryptography;
namespace PVDEMCS.Common.Devices
{
/*
*
*/
public interface IDeviceMonitor
{
IPLCCommunicationService PLCCommunicationService { get; }
/// <summary>
/// PLC 点位改变触发
/// </summary>
event EventHandler<DevicePoint> PointChnage;
/// <summary>
/// 获取错误相信
/// </summary>
event EventHandler<string> ErrorMessage;
/// <summary>
/// 间隔时间
/// </summary>
int Interval { get; set; }
/// <summary>
/// 当前点位集合
/// </summary>
ICollection<DevicePoint> Points { get; }
/// <summary>
/// PLC地址与端口
/// </summary>
void Init(string address, int port = 0);
/// <summary>
/// 加载点位
/// </summary>
/// <param name="tuples"></param>
void Load(params DevicePoint[] point);
/// <summary>
/// 清理所有点位
/// </summary>
void Clear();
/// <summary>
/// 开始监控
/// </summary>
Task<bool> StartAsync();
/// <summary>
/// 停止监控
/// </summary>
Task<bool> StopAsync();
}
}

@ -0,0 +1,36 @@
using PVDEMCS.Services;
namespace PVDEMCS.Common.Devices.Impl
{
public class DeviceConfiguration : IDeviceConfiguration
{
private IDeviceService deviceService;
private List<DeviceMonitor> monitors = new List<DeviceMonitor>();
public DeviceConfiguration(IDeviceService device)
{
this.deviceService = device;
}
public void Load()
{
var result = this.deviceService.GetDeviceInfoList("", "", true);
if (result.IsSuccess)
{
var devices = result.Content;
foreach (var device in devices)
{
var deviceMonitor = new DeviceMonitor(device);
var devicePoints = deviceService.GetDevicePointList(device.DeviceName);
if (devicePoints.IsSuccess && devicePoints.Content.Count>0)
{
deviceMonitor.Load(devicePoints.Content.ToArray());
}
monitors.Add(deviceMonitor);
}
}
}
}
}

@ -1,9 +1,10 @@
using PVDEMCS.Services.Models;
using Masuit.Tools;
using PVDEMCS.Services.Models;
using System.Security.Cryptography;
namespace PVDEMCS.Common.Devices.Impl
{
public class DeviceMonitor : IDeviceMonitor
public class DeviceMonitor
{
private DeviceInfo deviceInfo;
private IPLCCommunicationService plcCommunicationService;
@ -71,12 +72,16 @@ namespace PVDEMCS.Common.Devices.Impl
/// <summary>
/// 加载点位集合
/// </summary>
/// <param name="tuples"></param>
/// <param name="points"></param>
public void Load(params DevicePoint[] points)
{
if (points.IsNullOrEmpty())
{
throw new ArgumentException($"{nameof(points)}: 不能为空!");
}
if (devicePoints.Where(f => points.Select(ff => ff.PointCode).Contains(f.PointCode)).Count() > 0)
{
throw new ArgumentException($"{nameof(points)}: Name 不能重复!");
throw new ArgumentException($"{nameof(points)}: PointCode 不能重复!");
}
devicePoints.AddRange(points);
}

@ -136,7 +136,7 @@ namespace PVDEMCS.Controllers
/// <param name="pointName">点位列表</param>
/// <returns></returns>
[HttpGet]
public List<DevicePoint> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
public Result<List<DevicePoint>> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
{
var result = _deviceService.GetDevicePointList(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated);
return result;

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -26,4 +26,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Common\Configuration\" />
</ItemGroup>
</Project>

@ -1,5 +1,7 @@
using Masuit.Tools;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using PVDEMCS.Common.Devices;
using PVDEMCS.Common.DI;
using System.Configuration;
using System.Reflection;
@ -17,6 +19,11 @@ builder.Services.AddSwaggerGen(options =>
var xmlPathApp = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
options.IncludeXmlComments(xmlPathApp, true);
});
//添加跨域策略
builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", opt => opt.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().WithExposedHeaders("X-Pagination"));
});
//×¢²á·þÎñ
builder.AddAutofacExt();
//
@ -34,10 +41,23 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
//使用跨域策略
app.UseCors("CorsPolicy");
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
app.Lifetime.ApplicationStarted.Register(() =>
{
var deviceConfiguration = app.Services.GetService<IDeviceConfiguration>();
if (deviceConfiguration == null)
{
}
});
app.Run();

@ -30,7 +30,7 @@ namespace PVDEMCS.Services
/// <param name="deviceCode">控制器编号</param>
/// <param name="deviceName">控制器名称</param>
/// <returns></returns>
Result<List<DeviceInfo>> GetDeviceInfoList(string deviceCode, string deviceName, bool? activated = false);
Result<List<DeviceInfo>> GetDeviceInfoList(string deviceCode="", string deviceName = "", bool? activated = false);
/// <summary>
/// 获取PLC控制器明细
@ -88,7 +88,7 @@ namespace PVDEMCS.Services
/// <param name="pointCode">点位编号</param>
/// <param name="pointName">点位列表</param>
/// <returns></returns>
List<DevicePoint> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated);
Result<List<DevicePoint>> GetDevicePointList(string deviceName="", string deviceCode = "", string equipmentName = "", string equipmentCode = "", string equipmentType = "", string pointCode = "", string pointName = "", bool? activated = true);
/// <summary>
/// 获取PLC控制器点位明细

@ -139,7 +139,7 @@ namespace PVDEMCS.Services.Impl
/// <param name="pointCode">点位编号</param>
/// <param name="pointName">点位列表</param>
/// <returns></returns>
public List<DevicePoint> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
public Result<List<DevicePoint>> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
{
var result = _deviceRepository.GetDevicePointList(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated);

@ -88,7 +88,7 @@ namespace PVDEMCS.Services.Repositories
/// <param name="pointCode">点位编号</param>
/// <param name="pointName">点位列表</param>
/// <returns></returns>
List<DevicePoint> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated);
Result<List<DevicePoint>> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated);
/// <summary>
/// 获取PLC控制器点位明细

@ -249,13 +249,13 @@ namespace PVDEMCS.Services.Repositories.Impl
/// <param name="pointCode">点位编号</param>
/// <param name="pointName">点位列表</param>
/// <returns></returns>
public List<DevicePoint> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
public Result<List<DevicePoint>> GetDevicePointList(string deviceName, string deviceCode, string equipmentName, string equipmentCode, string equipmentType, string pointCode, string pointName, bool? activated)
{
using (var context = new EFContext())
{
var query = DeviceQuery(deviceName, deviceCode, equipmentName, equipmentCode, equipmentType, pointCode, pointName, activated, context);
var list = query.ToList();
return list;
return new Result<List<DevicePoint>>(list);
}
}

@ -59,52 +59,6 @@
报警
</summary>
</member>
<member name="E:PVDEMCS.Common.Devices.IDeviceMonitor.PointChnage">
<summary>
PLC 点位改变触发
</summary>
</member>
<member name="E:PVDEMCS.Common.Devices.IDeviceMonitor.ErrorMessage">
<summary>
获取错误相信
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceMonitor.Interval">
<summary>
间隔时间
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceMonitor.Points">
<summary>
当前点位集合
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.Init(System.String,System.Int32)">
<summary>
PLC地址与端口
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.Load(PVDEMCS.Services.Models.DevicePoint[])">
<summary>
加载点位
</summary>
<param name="tuples"></param>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.Clear">
<summary>
清理所有点位
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.StartAsync">
<summary>
开始监控
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.StopAsync">
<summary>
停止监控
</summary>
</member>
<member name="E:PVDEMCS.Common.Devices.Impl.DeviceMonitor.PointChnage">
<summary>
PLC 点位改变触发
@ -140,7 +94,7 @@
<summary>
加载点位集合
</summary>
<param name="tuples"></param>
<param name="points"></param>
</member>
<member name="M:PVDEMCS.Common.Devices.Impl.DeviceMonitor.Clear">
<summary>

@ -1 +1 @@
b81545b6cee6922e2492904a3e28e855a2da7c43
343174067cd832fbade3d0f003640c7839b8168f

@ -59,52 +59,6 @@
报警
</summary>
</member>
<member name="E:PVDEMCS.Common.Devices.IDeviceMonitor.PointChnage">
<summary>
PLC 点位改变触发
</summary>
</member>
<member name="E:PVDEMCS.Common.Devices.IDeviceMonitor.ErrorMessage">
<summary>
获取错误相信
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceMonitor.Interval">
<summary>
间隔时间
</summary>
</member>
<member name="P:PVDEMCS.Common.Devices.IDeviceMonitor.Points">
<summary>
当前点位集合
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.Init(System.String,System.Int32)">
<summary>
PLC地址与端口
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.Load(PVDEMCS.Services.Models.DevicePoint[])">
<summary>
加载点位
</summary>
<param name="tuples"></param>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.Clear">
<summary>
清理所有点位
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.StartAsync">
<summary>
开始监控
</summary>
</member>
<member name="M:PVDEMCS.Common.Devices.IDeviceMonitor.StopAsync">
<summary>
停止监控
</summary>
</member>
<member name="E:PVDEMCS.Common.Devices.Impl.DeviceMonitor.PointChnage">
<summary>
PLC 点位改变触发
@ -140,7 +94,7 @@
<summary>
加载点位集合
</summary>
<param name="tuples"></param>
<param name="points"></param>
</member>
<member name="M:PVDEMCS.Common.Devices.Impl.DeviceMonitor.Clear">
<summary>

Loading…
Cancel
Save