add -添加WPF首页界面

dev_caoql
杨威 7 months ago committed by frankiecao
parent 8a7679a3d8
commit 6af83d8423

@ -7,7 +7,6 @@
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
</ItemGroup>
</Project>

@ -1,5 +1,5 @@
using SlnMesnac.Plc;
using SlnMesnac.Rfid;
using System;
using System.Collections.Generic;
using System.Linq;
@ -33,12 +33,12 @@ namespace SlnMesnac.Business.@base
{
private readonly List<PlcAbsractFactory> _plcFactories;
private readonly List<RfidAbsractFactory> _rfidFactories;
public BaseBusiness(List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories)
public BaseBusiness(List<PlcAbsractFactory> plcFactories)
{
_plcFactories = plcFactories;
_rfidFactories = rfidFactories;
}
/// <summary>
@ -72,35 +72,6 @@ namespace SlnMesnac.Business.@base
}
/// <summary>
/// 根据Key获取Rfid连接信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException"></exception>
public RfidAbsractFactory GetRfidByKey(string key)
{
if (_rfidFactories == null)
{
throw new ArgumentNullException($"根据Key获取RFID连接信息异常:PLC 连接信息为空");
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException("根据Key获取RFID连接信息异常:设备Key参数为空");
}
try
{
var info = _rfidFactories.Where(x => x.ConfigKey == key).FirstOrDefault();
return info;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据Key获取RFID连接信息异常:{ex.Message}");
}
}
}
}

@ -1,87 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using SlnMesnac.Config;
using SlnMesnac.Plc;
using SlnMesnac.Rfid;
using SlnMesnac.Rfid.Factory;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Extensions
* 007aaf92-2adf-42a1-8b64-4e02925e3d5b
*
* WenJY
* wenjy@mesnac.com
* 2024-04-12 17:08:27
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Extensions
{
public static class RfidFactorySetup
{
public static void AddRfidFactorySetup(this IServiceCollection services)
{
services.AddSingleton<List<RfidAbsractFactory>>(x =>
{
AppConfig appConfig = x.GetService<AppConfig>();
List <RfidAbsractFactory> absractFactories = new List<RfidAbsractFactory>();
try
{
if (appConfig.rfidConfig != null)
{
foreach (var item in appConfig.rfidConfig)
{
if (item.isFlage)
{
RfidAbsractFactory _rfid = x.GetService<RflyFactory>();
bool connectResult = _rfid.Connect(item.equipIp, item.equipPort);
if (connectResult)
{
Log.Information($"RFID{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
_rfid.ConfigKey = item.equipKey;
if (absractFactories.Contains(_rfid))
{
absractFactories.Remove(_rfid);
}
absractFactories.Add(_rfid);
}
else
{
Log.Information($"RFID{item.equipIp}:{item.equipPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
}
}
}
}
else
{
Log.Error("RFID配置信息为空");
}
}
catch (Exception e)
{
Log.Error($"RFID初始化连接异常{e.Message}");
}
return absractFactories;
});
}
}
}

@ -8,8 +8,11 @@
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SqlSugarCore" Version="5.1.4.134" />
</ItemGroup>
</Project>

@ -1,113 +0,0 @@
using SlnMesnac.Generate.Templates.Service;
using SlnMesnac.Generate.Templates.Service.Impl;
using SqlSugar;
using System;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Generate
* 78595105-fab6-40f0-97b4-1272dc3e0e86
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 13:35:01
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Generate
{
/// <summary>
/// 生成代码
/// </summary>
public class GenerateCode
{
private readonly ISqlSugarClient _sqlSugarClient;
public GenerateCode(ISqlSugarClient sqlSugarClient)
{
_sqlSugarClient = sqlSugarClient;
}
public bool CreateCode(string configId,string tableName,string savePath,string nameSpace)
{
if (string.IsNullOrEmpty(configId))
{
throw new ArgumentNullException($"代码生成异常:configId参数为空");
}
if (string.IsNullOrEmpty(tableName))
{
throw new ArgumentNullException($"代码生成异常:表格名称参数为空");
}
if (string.IsNullOrEmpty(savePath))
{
throw new ArgumentNullException($"代码生成异常:文件存储路径参数为空");
}
if (string.IsNullOrEmpty(nameSpace))
{
throw new ArgumentNullException($"代码生成异常:命名空间参数为空");
}
try
{
savePath += $"\\{tableName}";
var scope = _sqlSugarClient.AsTenant().GetConnectionScope(configId);
scope.DbFirst.IsCreateAttribute()
.FormatPropertyName(it=> ToCamelCase(it)).Where(p => p == tableName).CreateClassFile($"{savePath}\\Entity", nameSpace);
var isc = new IServiceCreate();
bool iscRes = isc.Create(tableName, nameSpace, savePath);
if (!iscRes)
{
throw new InvalidOperationException($"Service接口生成失败");
}
var sc = new ServiceCreate();
var scRes = sc.Create(tableName, nameSpace, savePath);
if (!scRes)
{
throw new InvalidOperationException($"Service实现类生成失败");
}
return true;
}catch (Exception ex)
{
throw new InvalidOperationException($"代码生成异常:{ex.Message}");
}
}
private static string ToCamelCase(string input)
{
// 将字符串转换为驼峰格式,但保持每个单词的首字母大写
string[] words = input.Split('_');
for (int i = 0; i < words.Length; i++)
{
if (i > 0)
{
words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1).ToLower();
}
else
{
words[i] = words[i].ToLower();
}
}
return string.Join("", words);
}
}
}

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NVelocity" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
</ItemGroup>
</Project>

@ -1,78 +0,0 @@
using Commons.Collections;
using NVelocity.App;
using NVelocity.Runtime;
using NVelocity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Generate.Templates
* 4dbafd45-d689-4d1a-b54d-b936dae7d17c
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 13:28:04
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Generate.Templates.Service
{
public class IServiceCreate
{
private static readonly string templateDir = @"E:\桌面\SlnMesnac\SlnMesnac.Generate\Templates\Service\";
public bool Create(string tableName, string NameSpace, string outdir)
{
try
{
VelocityEngine velocityEngine = new VelocityEngine();
ExtendedProperties props = new ExtendedProperties();
props.AddProperty(RuntimeConstants.RESOURCE_LOADER, @"file");
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
//模板的缓存设置
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存
props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒)
velocityEngine.Init(props);
//为模板变量赋值
VelocityContext context = new VelocityContext();
context.Put("tableName", tableName);
context.Put("NameSpace", NameSpace);
context.Put("outdir", outdir);
//从文件中读取模板
Template template = velocityEngine.GetTemplate(@"\IServices.vm");
if (!Directory.Exists(outdir + "\\IServices"))
{
Directory.CreateDirectory(outdir + "\\IServices");
}
//合并模板
using (StreamWriter writer = new StreamWriter(outdir + $"\\IServices\\I{tableName.Substring(0, 1).ToUpper()}{tableName.Substring(1)}Service.cs", false))
{
template.Merge(context, writer);
}
return true;
}catch(Exception ex)
{
throw new InvalidOperationException($"Service接口模板创建异常:{ex.Message}");
}
}
}
}

@ -1,13 +0,0 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;
namespace ${NameSpace}.service
{
public interface I${tableName}Services: IBaseService<${tableName}>
{
}
}

@ -1,75 +0,0 @@
using Commons.Collections;
using NVelocity.App;
using NVelocity.Runtime;
using NVelocity;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Generate.Templates
* 4acc596a-6223-4156-b16c-952c225eff25
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 13:27:33
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Generate.Templates.Service.Impl
{
public class ServiceCreate
{
private static readonly string templateDir = @"E:\桌面\SlnMesnac\SlnMesnac.Generate\Templates\Service\Impl\";
public bool Create(string tableName, string NameSpace, string outdir)
{
try
{
VelocityEngine velocityEngine = new VelocityEngine();
ExtendedProperties props = new ExtendedProperties();
props.AddProperty(RuntimeConstants.RESOURCE_LOADER, @"file");
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDir);
props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
//模板的缓存设置
props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存
props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒)
velocityEngine.Init(props);
//为模板变量赋值
VelocityContext context = new VelocityContext();
context.Put("tableName", tableName);
context.Put("NameSpace", NameSpace);
context.Put("outdir", outdir);
//从文件中读取模板
Template template = velocityEngine.GetTemplate(@"\Services.vm");
if (!Directory.Exists(outdir + "\\Services"))
{
Directory.CreateDirectory(outdir + "\\Services");
}
//合并模板
using (StreamWriter writer = new StreamWriter(outdir + $"\\Services\\{tableName.Substring(0, 1).ToUpper()}{tableName.Substring(1)}ServiceImpl.cs", false))
{
template.Merge(context, writer);
}
return true;
}catch(Exception ex)
{
throw new InvalidOperationException($"Service实现类模板创建异常:{ex.Message}");
}
}
}
}

@ -1,14 +0,0 @@
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
namespace ${NameSpace}.service.Impl
{
public class ${tableName}ServiceImpl : BaseServiceImpl<${tableName}>, I${tableName}Service
{
public ${tableName}ServiceImpl(Repository<${tableName}> repository):base(repository)
{
}
}
}

@ -1,7 +1,7 @@
using Autofac;
using SlnMesnac.Repository;
using System.Reflection;
using TouchSocket.Sockets;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
@ -45,24 +45,21 @@ namespace SlnMesnac.Ioc
//注入Plc
RegisterTypeTransient(builder, Assembly.LoadFrom("SlnMesnac.Plc.dll"));
//注入Rfid
RegisterTypeTransient(builder, Assembly.LoadFrom("SlnMesnac.Rfid.dll"));
//注入通用类
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Common.dll"));
//注入MQTT
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Mqtt.dll"));
//注入TouchSocket
builder.RegisterType(typeof(TcpService));
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.TouchSocket.dll"));
//注入业务类
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Business.dll"));
//注入代码生成
RegisterType(builder, Assembly.LoadFrom("SlnMesnac.Generate.dll"));
}

@ -12,7 +12,6 @@
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" />
</ItemGroup>
</Project>

@ -1,168 +0,0 @@
using System;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using MQTTnet.Client;
using System.Security.Authentication;
using MQTTnet;
using Microsoft.Extensions.Logging;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Mqtt
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Mqtt
{
/// <summary>
/// MQTT客户端
/// </summary>
public class MqttClient
{
private ILogger<MqttClient> _logger;
private IMqttClient _client;
public MqttClient(ILogger<MqttClient> logger)
{
_logger = logger;
}
/// <summary>
/// 链接服务器
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <param name="clientId"></param>
/// <param name="username"></param>
/// <param name="password"></param>
public async void Connect(string ip, int port, string clientId, string username, string password)
{
try
{
MqttClientOptions options = new MqttClientOptionsBuilder()
.WithTcpServer(ip, port)
.WithClientId(clientId)
.WithCredentials(username, password)
.WithTls(o => //开启ssl
{
o.CertificateValidationHandler = _ => true;
o.SslProtocol = SslProtocols.Tls12;
})
.Build();
_client = new MqttFactory().CreateMqttClient();
_client.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceived;
MqttClientConnectResult result = await _client.ConnectAsync(options);
if (result != null)
{
if (result.ResultCode == MQTTnet.Client.MqttClientConnectResultCode.Success)
{
_logger.LogInformation($"连接服务器成功{ip}:{port}");
}
else
{
_logger.LogInformation($"连接服务器失败");
}
}
}
catch (Exception ex)
{
_logger.LogError("连接服务器异常",ex);
}
}
/// <summary>
/// 断开链接
/// </summary>
public void DisConnect()
{
_client.DisconnectAsync();
_logger.LogInformation($"断开连接");
}
/// <summary>
/// 订阅主题
/// </summary>
/// <param name="topic"></param>
public async void SubscriptionAsync(string topic)
{
try
{
var mqttFactory = new MqttFactory();
var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(
f =>
{
f.WithTopic(topic);
})
.Build();
MqttClientSubscribeResult result = await _client.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);
_logger.LogInformation($"订阅主题:{topic}");
}
catch (Exception ex)
{
_logger.LogError("订阅主题异常",ex);
}
}
/// <summary>
/// 取消订阅
/// </summary>
/// <param name="topic"></param>
public void Unsubscribe(string topic)
{
_client.UnsubscribeAsync(topic);
_logger.LogInformation($"取消订阅,主题:{topic}");
}
/// <summary>
/// 推送消息
/// </summary>
/// <param name="topic"></param>
/// <param name="message"></param>
public void Publish(string topic, string message)
{
try
{
var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(message)
.Build();
_client.PublishAsync(msg, CancellationToken.None);
_logger.LogInformation($"向服务端推送成功,主题:{topic};内容:{message}");
}
catch (Exception ex)
{
_logger.LogError("向服务端推送消息异常",ex);
}
}
private async Task MqttClient_ApplicationMessageReceived(MqttApplicationMessageReceivedEventArgs eventArgs)
{
var info = $"接收到主题:{eventArgs.ApplicationMessage.Topic}的消息,内容:{Encoding.UTF8.GetString(eventArgs.ApplicationMessage.Payload)}";
_logger.LogInformation(info);
}
}
}

@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="MQTTnet" Version="4.3.3.952" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
</Project>

@ -6,7 +6,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HslCommunication" Version="11.8.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
@ -16,4 +15,10 @@
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="HslCommunication">
<HintPath>..\SlnMesnac.Library\HslCommunication.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

@ -1,47 +0,0 @@
using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Quartz.Job
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Quartz.Job
{
internal class Job2 : IJob
{
private readonly ILogger<Job2> _logger;
public Job2(ILogger<Job2> logger)
{
_logger = logger;
}
public Task Execute(IJobExecutionContext context)
{
_logger.LogInformation($"执行Job2{DateTime.Now.ToString("HH:mm:ss")}");
return Task.CompletedTask;
}
}
}

@ -1,47 +0,0 @@
using Microsoft.Extensions.Logging;
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Quartz.Job
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Quartz.Job
{
public class MyJob : IJob
{
private readonly ILogger<MyJob> _logger;
public MyJob(ILogger<MyJob> logger)
{
_logger = logger;
}
public Task Execute(IJobExecutionContext context)
{
_logger.LogInformation($"执行MyJob{DateTime.Now.ToString("HH:mm:ss")}");
return Task.CompletedTask;
}
}
}

@ -1,54 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using SlnMesnac.Quartz.Job;
using System;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Quartz
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Quartz
{
public static class QuartzSetUp
{
[Obsolete]
public static void AddQuartzSetUp(this IServiceCollection services)
{
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
q.ScheduleJob<MyJob>(trigger =>
trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例每3s执行一次
);
q.ScheduleJob<Job2>(trigger =>
trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例每5s执行一次
);
});
services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true);
services.AddSingleton<IScheduler>(provider => provider.GetRequiredService<ISchedulerFactory>().GetScheduler().Result);
}
}
}

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Quartz.AspNetCore" Version="3.8.0" />
</ItemGroup>
</Project>

@ -1,92 +0,0 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Redis
* 00418016-53c9-4f87-a13f-daa19d656bba
*
* WenJY
* wenjy@mesnac.com
* 2024-04-12 15:15:25
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Redis
{
public class RedisHandler
{
private ILogger<RedisHandler> _logger;
private readonly AppConfig _appConfig;
private readonly ISubscriber _subscriber;
private readonly ConnectionMultiplexer redis;
public RedisHandler(AppConfig appConfig, ILogger<RedisHandler> logger)
{
_appConfig = appConfig;
redis = ConnectionMultiplexer.Connect(_appConfig.redisConfig);
_subscriber = redis.GetSubscriber();
_logger = logger;
}
/// <summary>
/// 推送消息
/// </summary>
/// <param name="channel"></param>
/// <param name="message"></param>
public void PublishMessage(string channel, string message)
{
long res = _subscriber.Publish(channel, message);
_logger.LogInformation($"向主题:{channel};推送消息:{message};结果:{res}");
}
/// <summary>
/// 订阅消息
/// </summary>
/// <param name="channel"></param>
/// <param name="onMessageReceived"></param>
public void SubscribeToChannel(string channel, Action<string, string> onMessageReceived)
{
_subscriber.Subscribe(channel, (ch, message) =>
{
onMessageReceived(ch, message);
_logger.LogInformation($"订阅主题:{channel};收到主题:{ch};推送的消息:{message}");
});
}
public void CleanExpiredMessages(string channel)
{
var redis = _subscriber.Multiplexer.GetDatabase();
redis.KeyDelete(channel);
}
public void SetValue(string key, string message)
{
IDatabase db = redis.GetDatabase(0);
TimeSpan expiry = TimeSpan.FromSeconds(10);
db.StringSet(key, message, expiry);
}
}
}

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.7.33" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
</ItemGroup>
</Project>

@ -1,31 +0,0 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Rfid.Dto
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Rfid.Dto
{
public class MessagePack
{
//public byte m_beginChar1 = 0xBB; //开始包
public byte[] m_pData = null; //发送数据
//public byte m_EndChar1 = 0x0D; //结束包
}
}

@ -1,43 +0,0 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Rfid.Enum
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Rfid.Enum
{
public enum RecvState
{
//RFly-I160 返回数据 BB DD 00 01 40 41 0D
WaitingBeginChar1_State = 1, //等待接收帧同步字符1 0xBB
WaitingBeginChar2_State = 2, //等待接收帧同步字符2 0xDD
WaitingForBarcodeLength_State = 3, //等待条码长度不固定
WaitingForCode_State = 4, //等待指令编号Code 0x02
WaitingForStus_State = 5, //等待接受状态码 0x00
WaitingForTagCount_State = 6, //等待接受标签组数不固定
WaitingForCount_State = 7, //等待接收第一组标签读取次数 0x01
WaitingForRSSI_State = 8, //等待接收读取信号强度 0xCB
WaitingForAnt_State = 9, //等待接收天线端口 0x01
WaitingForPC1_State = 10, //等待接收EPC区域 0x00
WaitingForPC2_State = 11, //等待接收EPC区域 0x00
WaitingForData_State = 12, //等待接收数据字符
WaitingForXor_State = 13, //等待比对校验位
WaitingForEndChar_State = 14, //等待接收尾字符 0x0D
}
}

@ -1,483 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using SlnMesnac.Common;
using SlnMesnac.Model.dto;
using SlnMesnac.Rfid.Dto;
using SlnMesnac.Rfid.Enum;
using TouchSocket.Core;
using TouchSocket.Sockets;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Rfid.Factory
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Rfid.Factory
{
public class RflyFactory:RfidAbsractFactory
{
private ILogger<RflyFactory> _logger;
private readonly TcpClient _tcpClient = new TcpClient();
private readonly StringChange _stringChange;
public RflyFactory(ILogger<RflyFactory> logger,StringChange stringChange)
{
_logger = logger;
_stringChange = stringChange;
}
/// <summary>
/// 建立连接
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool Connect(string ip, int port)
{
try
{
_tcpClient.Setup(new TouchSocketConfig().SetRemoteIPHost($"{ip}:{port}"));
_tcpClient.Connect();
return true;
}
catch (Exception e)
{
throw new InvalidOperationException($"设备连接异常:{e.Message}");
}
}
/// <summary>
/// 按时间段盘点
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override List<TagInfo> TimePeriodRead(int timeout = 5000)
{
byte[] u16byte = new byte[2];
byte[] bCRC = new byte[4];
try
{
#region 指令封装
MessagePack pMessagePack = new MessagePack();
pMessagePack.m_pData = new byte[8];
pMessagePack.m_pData[0] = 0xAA;
pMessagePack.m_pData[1] = 0x55;
pMessagePack.m_pData[2] = 0x02;
pMessagePack.m_pData[3] = 0x02;
u16byte = BitConverter.GetBytes(timeout); //超时时间
u16byte = _stringChange.Swap16Bytes(u16byte); //协议里为大端在前
Array.Copy(u16byte, 0, pMessagePack.m_pData, 4, 2);
Array.Copy(pMessagePack.m_pData, 2, bCRC, 0, 4);
pMessagePack.m_pData[6] = _stringChange.CalculateVerify(bCRC, bCRC.Length);
pMessagePack.m_pData[7] = 0x0D;
#endregion
var waitClient = _tcpClient.CreateWaitingClient(new WaitingOptions()
{
FilterFunc = response =>
{
return true;
}
});
byte[] reciveBuffer = waitClient.SendThenReturn(pMessagePack.m_pData, timeout);
_logger.LogInformation($"接收原始报文:{_stringChange.bytesToHexStr(reciveBuffer,reciveBuffer.Length)}");
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer,reciveBuffer.Length);
List<TagInfo> tagInfoList = Device_DealTagInfoList(resultBuffer);
return tagInfoList;
}
catch (Exception e)
{
throw new InvalidOperationException($"按时间段盘点异常:{e.Message}");
}
}
#region 标签解析
/// <summary>
/// 状态机函数
/// </summary>
/// <param name="buffer"></param>
/// <param name="iLen"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
private byte[] PareReceiveBufferData(byte[] buffer, int iLen)
{
RecvState enumRecvState = RecvState.WaitingBeginChar1_State;
int m_iPosition = 0;
UInt16 m_iFullMessageLength = 0;
int iBarcodeLength = 0;//条码长度
ArrayList m_FrecvData = new ArrayList();
byte m_iVerify = 0;
try
{
var bufferStr = _stringChange.bytesToHexStr(buffer, iLen);
byte[] m_szFullMessage = new byte[iLen];
for (int i = 0; i < iLen; i++)
{
switch (enumRecvState)
{
case RecvState.WaitingBeginChar1_State: //开始接受数据帧1 0xBB
Array.Clear(m_szFullMessage, 0, iLen);//清空为0
if (buffer[i] == 0xBB)
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
enumRecvState = RecvState.WaitingBeginChar2_State;
}
else
{
m_iFullMessageLength = 0;
m_iPosition = 0;
enumRecvState = RecvState.WaitingBeginChar1_State;
}
break;
case RecvState.WaitingBeginChar2_State: //开始接受数据帧1 0xDD
if (buffer[i] == 0xDD)
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
enumRecvState = RecvState.WaitingForBarcodeLength_State;
}
else
{
m_iFullMessageLength = 0;
m_iPosition = 0;
enumRecvState = RecvState.WaitingBeginChar1_State;
}
break;
case RecvState.WaitingForBarcodeLength_State: //开始接受数据长度(TagCount - EPC)
m_szFullMessage[m_iPosition] = buffer[i];
iBarcodeLength = buffer[i]; //单组标签18两组标签35
m_iPosition++;
enumRecvState = RecvState.WaitingForCode_State;
break;
case RecvState.WaitingForCode_State: //开始接受指令编号
if (buffer[i] == 0x02)
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
enumRecvState = RecvState.WaitingForStus_State;
}
else if (buffer[i] == 0x90) // 如果是心跳BB DD 01 90 00 1F 8E 0D
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
enumRecvState = RecvState.WaitingForEndChar_State;
}
else if (buffer[i] == 0xBF) // 如果是心跳BB DD 04 BF 00 00 00 F9 0B 49 0D
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
enumRecvState = RecvState.WaitingForEndChar_State;
}
else
{
m_iFullMessageLength = 0;
m_iPosition = 0;
enumRecvState = RecvState.WaitingBeginChar1_State;
}
break;
case RecvState.WaitingForStus_State: //开始接受状态码
if (buffer[i] == 0x00)
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
enumRecvState = RecvState.WaitingForTagCount_State;
}
else if (buffer[i] == 0x40)
{
m_szFullMessage[m_iPosition] = buffer[i];
//LogService.Instance.Debug("RFU620等待接受WaitingForEndChar_State:Noread");
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
m_iPosition = 0;
i = iLen;
enumRecvState = RecvState.WaitingBeginChar1_State;
//LogService.Instance.Debug("RFly-I160状态机结束。");
}
break;
case RecvState.WaitingForTagCount_State: //开始接受标签组数
Array.Copy(buffer, i, m_szFullMessage, m_iPosition, iBarcodeLength);//m_iPosition = 5
byte[] tempData = new byte[iBarcodeLength];
Array.Clear(tempData, 0, iBarcodeLength);
Array.Copy(buffer, i, tempData, 0, iBarcodeLength);
m_iPosition = m_iPosition + iBarcodeLength; //m_iPosition = 39
i = i + iBarcodeLength - 1; //i = 39
enumRecvState = RecvState.WaitingForXor_State;
break;
case RecvState.WaitingForXor_State: //开始比对校验位 Rfly160
byte[] m_CRCVerify = new byte[1024]; //此数组用于校验位计算
Array.Clear(m_CRCVerify, 0, m_CRCVerify.Length);
Array.Copy(m_szFullMessage, 2, m_CRCVerify, 0, iBarcodeLength + 3); //校验位计算是从Length - EPC 结束
m_szFullMessage[m_iPosition] = buffer[i];
m_iVerify = m_szFullMessage[m_iPosition];
if (m_iVerify == _stringChange.CalculateVerify(m_CRCVerify, m_CRCVerify.Length))
{
m_iPosition++;
enumRecvState = RecvState.WaitingForEndChar_State;
}
else //如果校验不成功
{
m_iFullMessageLength = 0;
m_iPosition = 0;
enumRecvState = RecvState.WaitingBeginChar1_State;
}
break;
case RecvState.WaitingForEndChar_State:
if (buffer[0] == 0xBB && buffer[1] == 0xDD && buffer[2] == 0x00 && buffer[3] != 0x90) //此处为Noread数据显示
{
m_szFullMessage[0] = 0xBB;
m_szFullMessage[1] = 0xDD;
m_szFullMessage[2] = 0x00;
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
m_iPosition = 0;
i = iLen;
enumRecvState = RecvState.WaitingBeginChar1_State;
}
else if (buffer[0] == 0xBB && buffer[1] == 0xDD && buffer[2] == 0x04 && buffer[3] == 0xBF)
{
Array.Copy(buffer, 0, m_szFullMessage, 0, 11);
i = 11;
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
i = iLen;
}
else if (buffer[i] == 0x00) //获取温度
{
Array.Copy(buffer, 0, m_szFullMessage, 0, 8);
i = 8;
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
i = iLen;
}
else if (buffer[i] == 0x11)
{
Array.Copy(buffer, 0, m_szFullMessage, 0, 7);
i = 7;
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
}
else if (buffer[i] == 0x01)
{
Array.Copy(buffer, 0, m_szFullMessage, 0, 8);
i = 8;
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
}
else
{
m_szFullMessage[m_iPosition] = buffer[i];
m_iPosition++;
if (buffer[i] == 0x0D)
{
lock (m_FrecvData)
{
m_FrecvData.Add(m_szFullMessage);
}
}
}
m_iPosition = 0;
enumRecvState = RecvState.WaitingBeginChar1_State;
break;
}
}
return m_szFullMessage;
}
catch (Exception e)
{
throw new InvalidOperationException($"状态机逻辑处理异常:{e.Message}");
}
}
private Mutex mutauto = new Mutex();
/// <summary>
/// 解析函数
/// </summary>
/// <param name="AutoDealReportData"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public List<TagInfo> Device_DealTagInfoList(byte[] AutoDealReportData)
{
List<TagInfo> tagInfoList = new List<TagInfo>();
byte[] bResultEPC_Data = new byte[14];
byte[] m_AutoReadEPC = null;
int m_readEPCDataLen = 0;
try
{
mutauto.WaitOne();
int iFirstCountPos = 6; //第一次读取标签次数位置
int iFirstRSSIPos = 7; //第一次读取标签强度位置
int iFirstAnt = 8;
int iFirstPC = 9; //第一次读取标签天线位置
int iFirstLeftBarcketPos = 11;//EPC数据起始位置
UInt16 tempDataCount = 0;
int tempDataRSSI = 0;
UInt16 tempDataANT = 0;
int iBarcodeGroupCount = Convert.ToInt32(AutoDealReportData[5].ToString()); //标签组数
int iBarcodeLength = 16; //标签长度
int iCommonSecondFlag = 0;
for (int j = 0; j < iBarcodeGroupCount; j++)
{
TagInfo tag = new TagInfo();
byte[] tempPCByte = new byte[2]; //取出PC
Array.Clear(tempPCByte, 0, 2);
Array.Copy(AutoDealReportData, iFirstPC, tempPCByte, 0, 2);
int pc = Convert.ToInt32(tempPCByte[0].ToString("X"));
int epcLength = EPCLengthByPC(pc);
iBarcodeLength = epcLength;
byte[] tempDataByte = new byte[epcLength];
Array.Clear(tempDataByte, 0, iBarcodeLength);
Array.Copy(AutoDealReportData, iFirstLeftBarcketPos, tempDataByte, 0, iBarcodeLength);
byte[] tempCountByte = new byte[1]; //取出标签次数
Array.Clear(tempCountByte, 0, 1);
Array.Copy(AutoDealReportData, iFirstCountPos, tempCountByte, 0, 1);
tempDataCount = tempCountByte[0];
byte[] tempRSSIByte = new byte[1]; //取出标签强度
Array.Clear(tempRSSIByte, 0, 1);
Array.Copy(AutoDealReportData, iFirstRSSIPos, tempRSSIByte, 0, 1);
tempDataRSSI = _stringChange.HexStringToNegative(_stringChange.bytesToHexStr(tempRSSIByte, 1));
#region add by wenjy 20220829 取出天线号
byte[] tempAntByte = new byte[1]; //取出天线号
Array.Clear(tempAntByte, 0, 1);
Array.Copy(AutoDealReportData, iFirstAnt, tempAntByte, 0, 1);
tempDataANT = tempAntByte[0];
#endregion
tag.Count = tempDataCount;
tag.RSSI = tempDataRSSI;
tag.EPC = tempDataByte;
if (pc == 24)
{
tag.EPCstring = _stringChange.bytesToHexStr(tempDataByte, tempDataByte.Length).Substring(0, 7);
}
else
{
tag.EPCstring = Encoding.ASCII.GetString(tempDataByte);
}
tag.PC = tempPCByte;
tag.Antana = tempDataANT;
tagInfoList.Add(tag);
int iBarcodeListLen = tagInfoList.Count; //特别注意,必须这样,要不然会多一条数据
iFirstCountPos = iFirstCountPos + iBarcodeLength + 5; //次数
iFirstRSSIPos = iFirstCountPos + 1; //强度
iFirstAnt = iFirstRSSIPos + 1; //天线
iFirstPC = iFirstAnt + 1;
iFirstLeftBarcketPos = iFirstLeftBarcketPos + iBarcodeLength + 5;
_logger.LogInformation("----函数调用:Device_DealTagInfoList 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]");
iCommonSecondFlag++;
if (iCommonSecondFlag == iBarcodeGroupCount)
{
mutauto.ReleaseMutex();
_logger.LogInformation("《《《返回标签数据!");
return tagInfoList;
}
}
return tagInfoList;
}
catch (Exception ex)
{
mutauto.ReleaseMutex();
throw new InvalidOperationException($"Device_AutoDealContent 自动处理函数异常:{ex.Message}");
}
}
/// <summary>
/// 根据PC获取EPC长度
/// </summary>
/// <param name="pcValue"></param>
/// <returns></returns>
private int EPCLengthByPC(int pcValue)
{
int epcLength = 0;
if (pcValue >= 10 && pcValue < 20)
{
epcLength = 4;
}
else if (pcValue >= 20 && pcValue < 30)
{
epcLength = 8;
}
else if (pcValue >= 30 && pcValue < 40)
{
epcLength = 12;
}
else if (pcValue >= 40 && pcValue < 50)
{
epcLength = 16;
}
else if (pcValue >= 50 && pcValue < 60)
{
epcLength = 20;
}
else if (pcValue >= 60 && pcValue < 70)
{
epcLength = 24;
}
else if (pcValue >= 70 && pcValue < 80)
{
epcLength = 28;
}
else if (pcValue >= 80 && pcValue < 90)
{
epcLength = 30;
}
return epcLength;
}
#endregion
}
}

@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using SlnMesnac.Model.dto;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Rfid
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Rfid
{
/// <summary>
/// RFID抽象工厂
/// </summary>
public abstract class RfidAbsractFactory
{
public string ConfigKey { get; set; }
/// <summary>
/// 建立连接
/// </summary>
/// <param name="ip"></param>
/// <param name="port"></param>
/// <returns></returns>
public abstract bool Connect(string ip, int port);
/// <summary>
/// 按时间段盘点
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public abstract List<TagInfo> TimePeriodRead(int timeout = 5000);
}
}

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" />
</ItemGroup>
</Project>

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocket" Version="2.0.0-beta.270" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
</Project>

@ -1,114 +0,0 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using TouchSocket.Core;
using TouchSocket.Sockets;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.TouchSocket
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.TouchSocket
{
public class TcpServer
{
private ILogger<TcpServer> _logger;
private readonly TcpService _service;
/// <summary>
/// 接收客户端指令委托
/// </summary>
public delegate void ReceivedClientBuffer(byte[] buffer);
public event ReceivedClientBuffer? ReceivedClientBufferEvent;
public delegate void RefreshClientInfo(TcpService tcpService);
public event RefreshClientInfo? RefreshClientInfoEvent;
public TcpServer(ILogger<TcpServer> logger,TcpService tcpService)
{
_logger = logger;
_service = tcpService;
}
public void Init(int serverPort)
{
try
{
_service.Connecting = (client, e) => {
_logger.LogInformation($"客户端{client.IP}正在接入服务");
return EasyTask.CompletedTask;
};
_service.Connected = (client, e) => {
_logger.LogInformation($"客户端{client.IP}接入服务成功");
RefreshClientInfoEvent?.Invoke(_service);
return EasyTask.CompletedTask;
};
_service.Disconnected = (client, e) => {
_logger.LogInformation($"客户端{client.IP}断开连接");
RefreshClientInfoEvent?.Invoke(_service);
return EasyTask.CompletedTask;
};
_service.Received = (client, e) =>
{
//从客户端收到信息
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
byte[] receivedBuffer = new byte[e.ByteBlock.Len];
Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len);
ReceivedClientBufferEvent?.Invoke(receivedBuffer);
return EasyTask.CompletedTask;
};
_service.Setup(new TouchSocketConfig()//载入配置
.SetListenIPHosts(new IPHost[] { new IPHost($"0.0.0.0:{serverPort}") })
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
{
a.AddConsoleLogger();
})
.ConfigurePlugins(a =>
{
//自定义插件
}));
_service.Start();
_logger.LogInformation($"TcpServer启动成功监听端口{serverPort}");
}
catch (Exception ex)
{
//throw new InvalidOperationException($"TcpServer启动异常{ex.Message}");
_logger.LogError($"TcpServer启动异常{ex.Message}");
}
}
/// <summary>
/// 向所有客户端发送心跳
/// </summary>
public void SendHeartBeat()
{
var clients = _service.SocketClients.GetClients();
foreach (var item in clients)
{
_service.Send(item.Id,"heartbeat");
}
}
}
}

@ -1,45 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Builder;
using TouchSocket.Sockets;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.TouchSocket
* 496f8d2b-70e3-4a05-ae18-a9b0fcd06b82
*
* WenJY
* wenjy@mesnac.com
* 2024-03-27 21:58:35
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.TouchSocket
{
/// <summary>
/// 注册服务
/// </summary>
public static class TouchSocketSetup
{
public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app)
{
var _server = app.ApplicationServices.GetService<TcpServer>();
_server.Init(20108);
return app;
}
}
}

@ -9,7 +9,6 @@ using System.Windows;
using Autofac.Extensions.DependencyInjection;
using SlnMesnac.Plc;
using System.Collections.Generic;
using SlnMesnac.Rfid;
namespace SlnMesnac.WPF
{

@ -1,9 +1,11 @@
<Window x:Class="SlnMesnac.WPF.MainWindow"
<Window
x:Class="SlnMesnac.WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SlnMesnac.WPF"
xmlns:local="clr-namespace:SlnMesnac.WPF" xmlns:viewmodel="clr-namespace:SlnMesnac.WPF.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
mc:Ignorable="d"
Title="MainWindow" Height="1080" Width="1920"
WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize" Topmost="False">
@ -13,17 +15,20 @@
<Border Margin="5" Background="Transparent" CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"></DropShadowEffect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.5*"/>
<RowDefinition Height="7*"/>
<RowDefinition Height="0.7*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="9*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Border Grid.Row="0" BorderBrush="Red" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="2,2">
<Grid>
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="7*"/>
@ -45,7 +50,7 @@
<TextBlock Grid.Column="2" Text="SCADA" FontSize="25" Foreground="White" FontWeight="Bold" Margin="0,0,10,0"/>
</Grid>
</StackPanel>
</Grid>
</Grid>-->
</Border>
<Border Grid.Row="1" BorderBrush="Red" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="2,25,2,2">
@ -55,7 +60,7 @@
<Border.Effect>
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<Grid>
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
@ -70,6 +75,7 @@
<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
-->
<!--多行状态显示-->
<!--<Grid>
<Grid.RowDefinitions>
@ -156,7 +162,7 @@
</Grid>-->
<!--单行状态显示-->
<Grid>
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
@ -255,13 +261,62 @@
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</Grid>-->
<!--
</StackPanel>
</Grid>
</Grid>-->
</Border>
<dx:SimpleButton Grid.Column="1" Content="主画面" FontSize="36" Foreground="White" HorizontalAlignment="Center" Height="120" Margin="0,20,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" CornerRadius="16">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
<dx:SimpleButton Grid.Column="1" Content="层合手动画面" FontSize="36" Foreground="White" HorizontalAlignment="Center" Height="120" Margin="0,160,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" CornerRadius="16">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
<dx:SimpleButton Grid.Column="1" Content="裁切手动画面" FontSize="36" Foreground="White" HorizontalAlignment="Center" Height="120" Margin="0,300,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" CornerRadius="16">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
<dx:SimpleButton Grid.Column="1" Content="数据记录" FontSize="36" Foreground="White" HorizontalAlignment="Center" Height="120" Margin="0,440,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" CornerRadius="16">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
<dx:SimpleButton Grid.Column="1" Content="参数画面" FontSize="36" Foreground="White" HorizontalAlignment="Center" Height="120" Margin="0,580,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" CornerRadius="16">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
<dx:SimpleButton Grid.Column="1" Content="报警记录" FontSize="36" Foreground="White" HorizontalAlignment="Center" Height="120" Margin="0,720,0,0" Grid.Row="1" VerticalAlignment="Top" Width="300" CornerRadius="16">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Grid>
</Border>

@ -1,56 +0,0 @@
<UserControl x:Class="SlnMesnac.WPF.Page.Generate.GenerateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SlnMesnac.WPF.Page.Generate"
xmlns:local1="clr-namespace:SlnMesnac.WPF.Converter.Generate"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="Transparent">
<Control.Resources>
<local1:RowToIndexConverter x:Key="RowToIndexConverter" />
</Control.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="8*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="Green" BorderThickness="2" CornerRadius="5" Margin="0,0,0,10">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="数据库连接:" FontSize="20" Foreground="White" VerticalAlignment="Center" Margin="10,0,10,0"/>
<ComboBox Width="200" Height="35" FontSize="18" VerticalAlignment="Center" Name="comboBox1" ItemsSource="{Binding Options}" SelectedItem="{Binding SelectedOption, Mode=TwoWay}" DisplayMemberPath="."/>
<TextBlock Text="表名:" FontSize="20" Foreground="White" VerticalAlignment="Center" Margin="30,0,10,0"/>
<TextBox x:Name="queryParam" Foreground="White" FontSize="18" Width="200" Height="35"/>
<Button Content="查 询" FontSize="16" Style="{StaticResource BUTTON_AGREE}" Width="120" Height="35" Background="#007DFA" BorderBrush="#007DFA" Margin="20,0,10,0" Command="{Binding QuerySearchCommand}" CommandParameter="{Binding Text, ElementName=queryParam}" />
</StackPanel>
</Border>
<Border Grid.Row="1" BorderBrush="Green" BorderThickness="2" CornerRadius="5" Margin="0,0,0,10">
<DataGrid x:Name="datagrid" Grid.Row="0" ItemsSource="{Binding TablesDataGrid}" Background="Transparent"
FontSize="15" ColumnHeaderHeight="35"
RowHeight="31" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="0" CanUserAddRows="False" HorizontalAlignment="Center"
Foreground="#FFFFFF" >
<!--resourceStyle 399行修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="表名" Width="3*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Description}" Header="说明" Width="3*" IsReadOnly="True"/>
<DataGridTemplateColumn Header="操作" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="生成代码" CommandParameter="{Binding Name}" Background="#009999" Foreground="White" Margin="10,0,0,0" Height="25" BorderBrush="#009999" BorderThickness="0" Width="100" Command="{Binding DataContext.CreateCodeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid }}"/>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>
</Grid>
</UserControl>

@ -0,0 +1,374 @@
<UserControl x:Class="SlnMesnac.WPF.Page.HomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SlnMesnac.WPF.Page" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="20"/>
</Style>
<Style TargetType="DataGrid">
<!--网格线颜色-->
<Setter Property="CanUserResizeColumns" Value="false"/>
<Setter Property="Background" Value="#1152AC" />
<Setter Property="BorderBrush" Value="#4285DE" />
<Setter Property="Foreground" Value="White"/>
<Setter Property="HorizontalGridLinesBrush">
<Setter.Value>
<SolidColorBrush Color="#4285DE"/>
</Setter.Value>
</Setter>
<Setter Property="VerticalGridLinesBrush">
<Setter.Value>
<SolidColorBrush Color="#1152AC"/>
</Setter.Value>
</Setter>
</Style>
<!--列头标题栏样式-->
<Style TargetType="DataGridColumnHeader">
<!--<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>-->
<!--<Setter Property="Background" Value="#dddddd"/>
<Setter Property="Foreground" Value="Black"/>-->
<!--<Setter Property="BorderThickness" Value="1" />-->
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#4285DE" />
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Background" Value="#4285DE"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<!--单元格样式-->
<Style TargetType="DataGridCell">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="#4285DE" />
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}" >
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#4285DE"/>
<!--<Setter Property="Foreground" Value="#dddddd"/>-->
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="1.2*"/>
<RowDefinition/>
<RowDefinition Height="1.6*"/>
</Grid.RowDefinitions>
<Border x:Name="上部" Grid.Row="0" Margin="2" BorderBrush="#FF658CF3" BorderThickness="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="0.6*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border x:Name="层合总数" Grid.Column="0" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="层合总数" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="裁切总数" Grid.Column="1" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="裁切总数" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="一号收料卷" Grid.Column="2" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="一号收料卷" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="二号收料卷" Grid.Column="3" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="二号收料卷" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="一号刀温" Grid.Column="4" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="一号刀温" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="二号刀温" Grid.Column="5" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="二号刀温" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="层合节拍" Grid.Column="6" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="层合节拍" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border x:Name="裁切节拍" Grid.Column="7" Margin="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.9*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock Text="裁切节拍" FontSize="17" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1">
<dxe:TextEdit Margin="3" CornerRadius="6"/>
</Border>
</Grid>
</Border>
</Grid>
</Border>
<Border Grid.Row="1">
<!--<Label Content="Label" FontSize="20" VerticalAlignment="Center" />-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0">
<TextBlock Text="设备状态" FontSize="17" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<Border Grid.Column="1">
<dxe:TextEdit Margin="6" CornerRadius="8"/>
</Border>
</Grid>
</Border>
</Grid>
</Border>
<Border x:Name="中部" Grid.Row="1" Margin="2" BorderBrush="#FF658CF3" BorderThickness="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0">
<dx:SimpleButton Content="登 录" Width="200" Height="60" FontSize="26" Foreground="White" HorizontalAlignment="Left" CornerRadius="8" Margin="20">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF002C6E" Offset="1"/>
<GradientStop Color="#FF1655B4" Offset="0"/>
</LinearGradientBrush>
</Button.Background>
</dx:SimpleButton>
</Border>
<Border Grid.Column="1">
<TextBlock TextWrapping="Wrap" Text="用户等级" FontSize="17" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,15,0"/>
</Border>
<Border Grid.Column="2">
<dxe:TextEdit Height="46" Width="120" CornerRadius="6"/>
</Border>
</Grid>
</Border>
<Border Grid.Column="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<dx:SimpleButton Content="裁切刀1工位" FontSize="17" Height="36" Width="160" VerticalAlignment="Center" CornerRadius="6">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0AA397" Offset="1"/>
<GradientStop Color="#FF8AE6E0" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
<Border Grid.Row="1">
<dx:SimpleButton Content="裁切刀2工位" FontSize="17" Height="36" Width="160" VerticalAlignment="Center" CornerRadius="6">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0AA397" Offset="1"/>
<GradientStop Color="#FF8AE6E0" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
</Grid>
</Border>
</Grid>
</Border>
<Border x:Name="下部" Grid.Row="2" Margin="2" BorderBrush="#FF658CF3" BorderThickness="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2.6*"/>
<ColumnDefinition/>
<ColumnDefinition Width="2.6*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock TextWrapping="Wrap" Text="合层工位" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
</Border>
<Border Grid.Row="1">
<dx:SimpleButton Content="启 动" FontSize="20" Foreground="White" Height="46" Width="240" VerticalAlignment="Center" CornerRadius="6">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0047E2" Offset="1"/>
<GradientStop Color="#FF00A3FF" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
<Border Grid.Row="2">
<dx:SimpleButton Content="回 零" FontSize="20" Foreground="White" Height="46" Width="240" VerticalAlignment="Center" CornerRadius="6">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFF4A00" Offset="1"/>
<GradientStop Color="#FFFFCB00" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
</Grid>
</Border>
<Border Grid.Column="1">
<dx:SimpleButton Content="脱 机" FontSize="26" Foreground="White" Height="120" Width="120" CornerRadius="60" >
<dx:SimpleButton.Background>
<RadialGradientBrush>
<GradientStop Color="#FF0047E2" Offset="1"/>
<GradientStop Color="#FF00A3FF" Offset="0"/>
</RadialGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
<Border Grid.Column="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<TextBlock TextWrapping="Wrap" Text="裁切工位" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
</Border>
<Border Grid.Row="1">
<dx:SimpleButton Content="启 动" FontSize="20" Foreground="White" Height="46" Width="240" VerticalAlignment="Center" CornerRadius="6">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF0047E2" Offset="1"/>
<GradientStop Color="#FF00A3FF" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
<Border Grid.Row="2">
<dx:SimpleButton Content="回 零" FontSize="20" Foreground="White" Height="46" Width="240" VerticalAlignment="Center" CornerRadius="6">
<dx:SimpleButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFF4A00" Offset="1"/>
<GradientStop Color="#FFFFCB00" Offset="0"/>
</LinearGradientBrush>
</dx:SimpleButton.Background>
</dx:SimpleButton>
</Border>
</Grid>
</Border>
</Grid>
</Border>
</Grid>
</UserControl>

@ -1,4 +1,4 @@
using SlnMesnac.WPF.ViewModel.Generate;
using SlnMesnac.WPF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,17 +14,17 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SlnMesnac.WPF.Page.Generate
namespace SlnMesnac.WPF.Page
{
/// <summary>
/// GenerateControl.xaml 的交互逻辑
/// HomePage.xaml 的交互逻辑
/// </summary>
public partial class GenerateControl : UserControl
public partial class HomePage : UserControl
{
public GenerateControl()
public HomePage()
{
InitializeComponent();
this.DataContext = new GenerateControlViewModel();
this.DataContext = new HomePageViewModel();
}
}
}

@ -0,0 +1 @@
DevExpress.Xpf.Editors.TextEdit, DevExpress.Xpf.Core.v22.1, Version=22.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a

@ -7,9 +7,15 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<Compile Remove="ViewModel\Generate\**" />
<EmbeddedResource Remove="ViewModel\Generate\**" />
<None Remove="ViewModel\Generate\**" />
<Page Remove="ViewModel\Generate\**" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="Templates\image\background.jpg" />
</ItemGroup>
<ItemGroup>
@ -18,25 +24,26 @@
</Content>
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="Templates\image\background.jpg" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Business\SlnMesnac.Business.csproj" />
<ProjectReference Include="..\SlnMesnac.Common\SlnMesnac.Common.csproj" />
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Extensions\SlnMesnac.Extensions.csproj" />
<ProjectReference Include="..\SlnMesnac.Generate\SlnMesnac.Generate.csproj" />
<ProjectReference Include="..\SlnMesnac.Ioc\SlnMesnac.Ioc.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.Mqtt\SlnMesnac.Mqtt.csproj" />
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Quartz\SlnMesnac.Quartz.csproj" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.Rfid\SlnMesnac.Rfid.csproj" />
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
<ProjectReference Include="..\SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="devexpress.wpf.core" Version="22.1.5" />
<PackageReference Include="Lierda.WPFHelper" Version="1.0.3" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
<PackageReference Include="NVelocity" Version="1.2.0" />
@ -44,7 +51,9 @@
</ItemGroup>
<ItemGroup>
<Resource Include="Templates\image\background.jpg" />
<Resource Include="Templates\image\background.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>
</Project>

@ -8,7 +8,6 @@ using SlnMesnac.Serilog;
using System;
using Autofac;
using Microsoft.Extensions.Configuration;
using SlnMesnac.Rfid;
using SlnMesnac.Ioc;
using SlnMesnac.Plc;
using SlnMesnac.Extensions;
@ -43,8 +42,6 @@ namespace SlnMesnac.WPF
//注册PLC工厂
services.AddPlcFactorySetup();
//注册RFID工厂
services.AddRfidFactorySetup();
}
/// <summary>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 1.7 MiB

@ -1,163 +0,0 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HslCommunication.LogNet;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.WindowsAPICodePack.Dialogs;
using SlnMesnac.Config;
using SlnMesnac.Generate;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Windows;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.WPF.ViewModel.Generate
* 7f1ddac5-3ff3-4974-ac90-d6eb684167c8
*
* WenJY
* wenjy@mesnac.com
* 2024-04-11 09:31:46
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel.Generate
{
internal class GenerateControlViewModel : ViewModelBase
{
private readonly AppConfig _appConfig;
private readonly GenerateCode _generateCode;
public GenerateControlViewModel()
{
_appConfig = App.ServiceProvider.GetService<AppConfig>();
_generateCode = App.ServiceProvider.GetService<GenerateCode>();
var configIds = _appConfig.sqlConfig.Select(x=>x.configId).ToList();
// 初始化选项列表
Options = new ObservableCollection<string>();
foreach(var configId in configIds)
{
Options.Add(configId);
}
QuerySearchCommand = new RelayCommand<string>(Query);
CreateCodeCommand = new RelayCommand<string>(CreateCode);
}
#region 参数定义
private ObservableCollection<string> _options;
public ObservableCollection<string> Options
{
get { return _options; }
set
{
_options = value;
RaisePropertyChanged(nameof(Options));
}
}
private string _selectedOption;
public string SelectedOption
{
get { return _selectedOption; }
set
{
_selectedOption = value;
RaisePropertyChanged(nameof(SelectedOption));
}
}
private ObservableCollection<DbTableInfo> tablesDataGrid;
public ObservableCollection<DbTableInfo> TablesDataGrid
{
get { return tablesDataGrid; }
set { tablesDataGrid = value; RaisePropertyChanged(() => TablesDataGrid); }
}
#endregion
#region 事件定义
public RelayCommand<string> QuerySearchCommand { get; set; }
public RelayCommand<string> CreateCodeCommand { get;set; }
#endregion
/// <summary>
/// 查询事件
/// </summary>
/// <param name="search"></param>
private void Query(string search)
{
var configId = _selectedOption;
if (!string.IsNullOrEmpty(configId))
{
var db = App.ServiceProvider.GetService<ISqlSugarClient>();
var scope = db.AsTenant().GetConnectionScope(configId);
List<DbTableInfo> tables = scope.DbMaintenance.GetTableInfoList(false);
if(tables != null)
{
TablesDataGrid = new ObservableCollection<DbTableInfo>();
tables.ForEach(t => { TablesDataGrid.Add(t); });
}
}
}
private void CreateCode(string tableName)
{
var info = tableName;
var configId = _selectedOption;
string nameSpace = "SlnMesnac.Repository";
try
{
using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
{
dialog.IsFolderPicker = true; // 设置为选择文件夹
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
string selectedPath = dialog.FileName;
var res = _generateCode.CreateCode(configId, tableName, selectedPath, nameSpace);
if (res)
{
MessageBox.Show($"{tableName}代码生成成功");
}
}
}
}catch(Exception ex)
{
MessageBox.Show($"{tableName}代码生成失败:{ex.Message}");
}
}
}
}

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.WPF.ViewModel
{
public class HomePageViewModel
{
public System.Windows.Controls.UserControl _content;
public System.Windows.Controls.UserControl UserContent
{
get { return _content; }
set
{
_content = value;
//RaisePropertyChanged(nameof(UserContent));
}
}
}
}

@ -2,7 +2,7 @@
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SlnMesnac.WPF.Page.Generate;
using SlnMesnac.WPF.Page;
using System;
using System.Windows;
@ -12,8 +12,7 @@ namespace SlnMesnac.WPF.ViewModel
{
private readonly ILogger<MainWindowViewModel> _logger;
//代码生成
private readonly GenerateControl generateControl = new GenerateControl();
private HomePage homePage = new HomePage();
#region 参数定义
/// <summary>
@ -102,9 +101,7 @@ namespace SlnMesnac.WPF.ViewModel
//Environment.Exit(0);
Application.Current.Shutdown();
break;
case "Generate":
UserContent = generateControl;
break;
// 还原 或者 最大化当前窗口
case "Normal":
if (Application.Current.MainWindow.WindowState == WindowState.Normal)

@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33502.453
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac", "SlnMesnac\SlnMesnac.csproj", "{19445879-B3F3-4C76-A670-EFAE9E25BAB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Common", "SlnMesnac.Common\SlnMesnac.Common.csproj", "{BB71F26A-7007-423E-83E9-7A3BAC25E934}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Config", "SlnMesnac.Config\SlnMesnac.Config.csproj", "{6EF7F087-7149-4689-885C-E0D05E1A9AA8}"
@ -13,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Model", "SlnMesna
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Repository", "SlnMesnac.Repository\SlnMesnac.Repository.csproj", "{C892C06A-496B-43B6-AEC7-AF9D70778C0C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Quartz", "SlnMesnac.Quartz\SlnMesnac.Quartz.csproj", "{12ED397C-951E-411C-9C43-CDABA79CA45B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Serilog", "SlnMesnac.Serilog\SlnMesnac.Serilog.csproj", "{DEE2F305-733C-47C8-891C-502121ABAD00}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Plc", "SlnMesnac.Plc\SlnMesnac.Plc.csproj", "{D17E9024-9D25-4CE4-8E98-8A6C859CE436}"
@ -23,30 +19,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.WPF", "SlnMesnac.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Business", "SlnMesnac.Business\SlnMesnac.Business.csproj", "{90296C1E-932E-4CD3-9B11-4376746C4C87}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.TouchSocket", "SlnMesnac.TouchSocket\SlnMesnac.TouchSocket.csproj", "{3700E2BB-09C4-43C0-A9DC-C18137B76591}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Mqtt", "SlnMesnac.Mqtt\SlnMesnac.Mqtt.csproj", "{7D908FF5-88AE-42AB-A193-F2896EF44AB1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Rfid", "SlnMesnac.Rfid\SlnMesnac.Rfid.csproj", "{40D23A4B-8372-4145-936C-08AE63C6D1F9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Ioc", "SlnMesnac.Ioc\SlnMesnac.Ioc.csproj", "{30A3F86B-774E-4153-9A00-FD3173C710EB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnMesnac.Generate", "SlnMesnac.Generate\SlnMesnac.Generate.csproj", "{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Extensions", "SlnMesnac.Extensions\SlnMesnac.Extensions.csproj", "{6D929802-24AA-42A7-92C5-303C3D59A990}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.Redis", "SlnMesnac.Redis\SlnMesnac.Redis.csproj", "{0E041719-E755-43CD-8A0E-DF62E0B2E463}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19445879-B3F3-4C76-A670-EFAE9E25BAB4}.Release|Any CPU.Build.0 = Release|Any CPU
{BB71F26A-7007-423E-83E9-7A3BAC25E934}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB71F26A-7007-423E-83E9-7A3BAC25E934}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB71F26A-7007-423E-83E9-7A3BAC25E934}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -63,10 +45,6 @@ Global
{C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C892C06A-496B-43B6-AEC7-AF9D70778C0C}.Release|Any CPU.Build.0 = Release|Any CPU
{12ED397C-951E-411C-9C43-CDABA79CA45B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12ED397C-951E-411C-9C43-CDABA79CA45B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12ED397C-951E-411C-9C43-CDABA79CA45B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12ED397C-951E-411C-9C43-CDABA79CA45B}.Release|Any CPU.Build.0 = Release|Any CPU
{DEE2F305-733C-47C8-891C-502121ABAD00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DEE2F305-733C-47C8-891C-502121ABAD00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEE2F305-733C-47C8-891C-502121ABAD00}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -83,34 +61,14 @@ Global
{90296C1E-932E-4CD3-9B11-4376746C4C87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90296C1E-932E-4CD3-9B11-4376746C4C87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90296C1E-932E-4CD3-9B11-4376746C4C87}.Release|Any CPU.Build.0 = Release|Any CPU
{3700E2BB-09C4-43C0-A9DC-C18137B76591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3700E2BB-09C4-43C0-A9DC-C18137B76591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3700E2BB-09C4-43C0-A9DC-C18137B76591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3700E2BB-09C4-43C0-A9DC-C18137B76591}.Release|Any CPU.Build.0 = Release|Any CPU
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D908FF5-88AE-42AB-A193-F2896EF44AB1}.Release|Any CPU.Build.0 = Release|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40D23A4B-8372-4145-936C-08AE63C6D1F9}.Release|Any CPU.Build.0 = Release|Any CPU
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30A3F86B-774E-4153-9A00-FD3173C710EB}.Release|Any CPU.Build.0 = Release|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00FC9358-2381-4C1B-BD45-6D31DD1DB7D3}.Release|Any CPU.Build.0 = Release|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D929802-24AA-42A7-92C5-303C3D59A990}.Release|Any CPU.Build.0 = Release|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E041719-E755-43CD-8A0E-DF62E0B2E463}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -1,90 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
namespace SlnMesnac.Controllers
{
/// <summary>
/// 物料信息
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class BaseMaterialInfoController
{
private ILogger<BaseMaterialInfoController> _logger;
private IBaseMaterialService _service;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="service"></param>
public BaseMaterialInfoController(ILogger<BaseMaterialInfoController> logger, IBaseMaterialService service)
{
_logger = logger;
_service = service;
}
/// <summary>
/// 获取物料信息
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<BaseMaterialInfo> Get()
{
IEnumerable<BaseMaterialInfo> materialInfos = null;
try
{
materialInfos = _service.GetMaterialInfos();
}
catch (Exception ex)
{
_logger.LogError($"获取物料信息接口调用异常:{ex.Message}");
}
return materialInfos;
}
/// <summary>
/// 根据物料编号获取物料信息
/// </summary>
/// <param name="materialCode">物料编号</param>
/// <returns></returns>
[HttpGet("Get/{materialCode}")]
public BaseMaterialInfo GetMaterialInfoByMaterialCode(string materialCode)
{
BaseMaterialInfo materialInfo = null;
try
{
materialInfo = _service.GetMaterialInfoByMaterialCode(materialCode);
}
catch (Exception ex)
{
_logger.LogError($"根据物料编号获取物料信息接口调用异常:{ex.Message}");
}
return materialInfo;
}
/// <summary>
/// 通过物料类别获取物料信息
/// </summary>
/// <param name="majorTypeId">物料大类</param>
/// <param name="minorTypeId">物料细类</param>
/// <returns></returns>
[HttpGet("Get/{majorTypeId}/{minorTypeId}")]
public IEnumerable<BaseMaterialInfo> GetMaterialInfosByMaterialType(int majorTypeId, string minorTypeId)
{
IEnumerable<BaseMaterialInfo> materialInfos = null;
try
{
materialInfos = _service.GetMaterialInfosByMaterialType(majorTypeId, minorTypeId);
}
catch (Exception ex)
{
_logger.LogError($"通过物料类别获取物料信息接口调用异常:{ex.Message}");
}
return materialInfos;
}
}
}

@ -1,81 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlnMesnac.Model.domain;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
namespace SlnMesnac.Controllers
{
/// <summary>
/// 人员基础信息
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class BaseUserController : ControllerBase
{
private readonly ILogger<BaseUserController> _logger;
private readonly IBaseUserService _service;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
/// <param name="service"></param>
public BaseUserController(ILogger<BaseUserController> logger, IBaseUserService service)
{
_logger = logger;
_service = service;
}
/// <summary>
/// 获取人员基础信息
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<BaseUser> Get()
{
IEnumerable<BaseUser> users = null;
try
{
users = _service.GetUsers();
}
catch (Exception ex)
{
_logger.LogError($"获取用户信息接口调用异常:{ex.Message}");
}
return users;
}
/// <summary>
/// 通过用户名称获取指定用户信息
/// </summary>
/// <param name="userName">用户名称</param>
/// <returns></returns>
[HttpGet("Gets/{userName}")]
public IEnumerable<BaseUser> GetUserByUserName(string userName)
{
IEnumerable<BaseUser> users = null;
try
{
users = _service.GetUsers();
}
catch (Exception ex)
{
_logger.LogError($"获取用户信息接口调用异常:{ex.Message}");
}
return users;
}
/// <summary>
/// 添加用户信息
/// </summary>
/// <param name="users">用户列表</param>
/// <returns></returns>
[HttpPut]
public bool InsertUserInfo(List<BaseUser> users)
{
return _service.InsertUsers(users);
}
}
}

@ -1,61 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Quartz;
namespace SlnMesnac.Controllers
{
/// <summary>
/// 任务调度
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class JobController
{
private readonly IScheduler _scheduler;
/// <summary>
///
/// </summary>
/// <param name="scheduler"></param>
public JobController(IScheduler scheduler)
{
_scheduler = scheduler;
}
/// <summary>
/// 启动任务
/// </summary>
/// <param name="jobName">任务名称</param>
/// <param name="groupName">任务分组</param>
/// <returns></returns>
[HttpPost("start")]
public async Task<string> StartJob(string jobName, string groupName)
{
// 检查调度器是否已经启动
if (!_scheduler.IsStarted)
{
await _scheduler.Start();
}
var myJobKey = new JobKey(jobName, groupName);
await _scheduler.ResumeJob(myJobKey);
return "Job started successfully.";
}
/// <summary>
/// 停止任务
/// </summary>
/// <param name="jobName">任务名称</param>
/// <param name="groupName">任务分组</param>
/// <returns></returns>
[HttpPost("stop")]
public async Task<string> StopJob(string jobName, string groupName)
{
var myJobKey = new JobKey(jobName, groupName);
await _scheduler.PauseJob(myJobKey);
return "Job stopped successfully.";
}
}
}

@ -1,32 +0,0 @@
using Serilog;
namespace SlnMesnac
{
/// <summary>
/// Æô¶¯Àà
/// </summary>
public class Program
{
/// <summary>
/// Main·½·¨
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
/// <summary>
/// CreateHostBuilder
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

@ -1,30 +0,0 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32147",
"sslPort": 44302
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
//"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SlnMesnac": {
"commandName": "Project",
"launchBrowser": true,
//"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Config\SlnMesnac.Config.csproj" />
<ProjectReference Include="..\SlnMesnac.Extensions\SlnMesnac.Extensions.csproj" />
<ProjectReference Include="..\SlnMesnac.Model\SlnMesnac.Model.csproj" />
<ProjectReference Include="..\SlnMesnac.Plc\SlnMesnac.Plc.csproj" />
<ProjectReference Include="..\SlnMesnac.Quartz\SlnMesnac.Quartz.csproj" />
<ProjectReference Include="..\SlnMesnac.Repository\SlnMesnac.Repository.csproj" />
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
</Project>

@ -1,121 +0,0 @@
using Microsoft.OpenApi.Models;
using SlnMesnac.Config;
using SlnMesnac.Quartz;
using SlnMesnac.Serilog;
using SlnMesnac.Extensions;
using System.Runtime.Serialization;
namespace SlnMesnac
{
/// <summary>
///
/// </summary>
public class Startup
{
/// <summary>
///
/// </summary>
/// <param name="configuration"></param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
/// <summary>
///
/// </summary>
public IConfiguration Configuration { get; }
/// <summary>
/// This method gets called by the runtime. Use this method to add services to the container.
/// </summary>
/// <param name="services"></param>
[Obsolete]
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
//配置Swagger
services.AddSwaggerGen(swagger =>
{
//自定义接口信息
swagger.SwaggerDoc("V1.0", new OpenApiInfo
{
Title = "MES Web Api",
Version = "V1.0",
Description = $"API版本V1.0",
Contact = new OpenApiContact
{
Name = "MES Web Api",
Email = "wenjy@mesnac.com"
}
});
//自定义实体别名
swagger.CustomSchemaIds(type => type.GetCustomAttributes(typeof(DataContractAttribute), true)
.Cast<DataContractAttribute>()
.FirstOrDefault()?.Name);
//配置Action名称
var path = Path.Combine(AppContext.BaseDirectory, "SlnMesnac.xml");
swagger.IncludeXmlComments(path, true); // true : 显示控制器层注释
swagger.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序如果有多个就可以看见效果了。
});
//注册配置类
services.AddSingleton<AppConfig>(provider =>
{
var configuration = provider.GetService<IConfiguration>();
return configuration.GetSection("AppConfig").Get<AppConfig>();
});
//注册SqlSugar
services.AddSqlSugarSetup();
//注册服务
//services.AddServices();
//注册任务调度
services.AddQuartzSetUp();
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//启用Swagger中间件
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/V1.0/swagger.json", "MES Web Api V1.0");
c.RoutePrefix = "";
});
//启用Serilog中间件
app.UseSerilogExtensions();
//app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -1,15 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"AppConfig": {
"logPath": "E:\\桌面\\日常代码\\SlnMesnac\\SlnMesnac\\bin\\Debug\\net6.0",
"mesConnStr": "server=.;uid=sa;pwd=123456;database=JiangYinMENS",
"mcsConnStr": "Data Source=175.27.215.92/helowin;User ID=aucma_scada;Password=aucma"
}
}
Loading…
Cancel
Save