first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using JSMachine.WMS.Common.Cache.Model;
|
||||
using JSMachine.WMS.Common.Cache;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using JSMachine.WMS.Netty.NettyAsClient.Command;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
|
||||
namespace JSMachine.WMS.Netty.NettyAsClient.CommandHandler
|
||||
{
|
||||
public class BarCodeCmdHandlerL : BaseCmdhandler
|
||||
{
|
||||
public async override Task<bool> Handle(BaseCmd msg)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
if (msg is BarCodeUploadCmd barCodeUploadCmd)
|
||||
{
|
||||
GlobalMemoryCache.AddCach(
|
||||
RemoteIPInfo.IP,
|
||||
new BarCodeInfo
|
||||
{
|
||||
AddTime = DateTime.Now,
|
||||
BarCode = barCodeUploadCmd.Msg,
|
||||
IP = RemoteIPInfo.IP
|
||||
},
|
||||
new MemoryCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(30),
|
||||
});
|
||||
|
||||
LogHelper.Info($"收到条码信息({RemoteIPInfo.IP}): 【{barCodeUploadCmd.Msg}】");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
using JSMachine.WMS.Netty.NettyAsClient.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using static System.Console;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Netty.NettyAsClient.CommandHandler
|
||||
{
|
||||
public class BarCodeReadExceptionCmdHandler : BaseCmdhandler
|
||||
{
|
||||
public async override Task<bool> Handle(BaseCmd msg)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
if (msg is BarCodeReadExceptionCmd barCodeReadExceptionCmd)
|
||||
{
|
||||
LogHelper.Warn($"相机【{base.RemoteIPInfo.IP}】条码读取失败,返回信息 {barCodeReadExceptionCmd.Msg}");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using DotNetty.Transport.Channels;
|
||||
using JSMachine.WMS.Netty.Common.Util;
|
||||
using JSMachine.WMS.Netty.NettyAsClient.Command;
|
||||
using Prism.Events;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Netty.NettyAsClient.CommandHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Netty 客户端命令处理器基类,提供通道上下文及收发端地址信息。
|
||||
/// </summary>
|
||||
[InheritedExport("NettyAsClient")]
|
||||
public abstract class BaseCmdhandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前命令所属的 Netty 通道上下文。
|
||||
/// </summary>
|
||||
public IChannelHandlerContext Channel { get; set; }
|
||||
/// <summary>
|
||||
/// 远端地址信息。
|
||||
/// </summary>
|
||||
public IPInfo RemoteIPInfo => Channel.ToIPInfo(AddressOnwer.Remote);
|
||||
/// <summary>
|
||||
/// 本地地址信息。
|
||||
/// </summary>
|
||||
public IPInfo LocalIPInfo=> Channel.ToIPInfo(AddressOnwer.Local);
|
||||
/// <summary>
|
||||
/// 处理一条客户端命令。
|
||||
/// </summary>
|
||||
/// <param name="msg">待处理的命令。</param>
|
||||
/// <returns>处理成功返回 <see langword="true"/>。</returns>
|
||||
public abstract Task<bool> Handle(BaseCmd msg);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user