添加远程锁机功能
This commit is contained in:
parent
2bdf58a0c8
commit
14b49d38a2
|
@ -0,0 +1,13 @@
|
|||
namespace MasstransferCommon.Model.Enum;
|
||||
|
||||
/// <summary>
|
||||
/// 防止注册表被恶意篡改,这里的注册许可类型需要做一些混淆
|
||||
/// </summary>
|
||||
public enum LicenseTypeEnum
|
||||
{
|
||||
// 临时许可
|
||||
Temporary = unchecked(int.MaxValue - 123456),
|
||||
|
||||
// 正式许可
|
||||
Formal = unchecked(int.MaxValue - 123457)
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
namespace MasstransferCommon.Model.Enum;
|
||||
|
||||
/// <summary>
|
||||
/// 锁定状态
|
||||
/// </summary>
|
||||
public enum LockStateEnum
|
||||
{
|
||||
// 锁定状态
|
||||
LockedState = int.MaxValue / 3,
|
||||
|
||||
// 等待锁定状态
|
||||
WaitToLockedState = int.MaxValue / 4,
|
||||
|
||||
// 解锁状态
|
||||
UnLockedState = int.MaxValue / 5,
|
||||
|
||||
// 等待解锁状态
|
||||
WaitToUnLockedState = int.MaxValue / 6
|
||||
}
|
|
@ -1,7 +1,22 @@
|
|||
class Program
|
||||
using MasstransferExporter.RemoteControl;
|
||||
using MasstransferExporter.RemoteControl.Model;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
|
||||
var cmd = new LockCmd
|
||||
{
|
||||
Action = 1,
|
||||
ExpiryTime = 0,
|
||||
LockType = 0
|
||||
};
|
||||
|
||||
RemoteLockService.HandleLockCmd(cmd);
|
||||
|
||||
|
||||
Console.WriteLine("按任意键退出");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
namespace MasstransferExporter.RemoteControl.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 锁机指令
|
||||
/// </summary>
|
||||
public class LockCmd
|
||||
{
|
||||
/// <summary>
|
||||
/// 0 锁机 1 解锁
|
||||
/// </summary>
|
||||
public int Action { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0 立即执行
|
||||
/// 1 到期执行
|
||||
/// </summary>
|
||||
public int LockType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 到期时间
|
||||
/// </summary>
|
||||
public long ExpiryTime { get; set; }
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using MasstransferCommon.Model.Enum;
|
||||
using MasstransferCommon.Utils;
|
||||
using MasstransferExporter.RemoteControl.Model;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace MasstransferExporter.RemoteControl;
|
||||
|
||||
/// <summary>
|
||||
/// 远程锁定服务
|
||||
/// </summary>
|
||||
public class RemoteLockService
|
||||
{
|
||||
private const string KeyPath = @"Software\Masstransfer\Security";
|
||||
|
||||
/// <summary>
|
||||
/// 处理接收到锁机业务指令
|
||||
/// </summary>
|
||||
public static void HandleLockCmd(LockCmd cmd)
|
||||
{
|
||||
var action = cmd.Action;
|
||||
|
||||
if (action == 0)
|
||||
{
|
||||
// 更新注册表锁机状态
|
||||
var lockType = cmd.LockType;
|
||||
if (lockType == 0)
|
||||
{
|
||||
RegistryHelper.WriteValue(KeyPath, "LockState", LockStateEnum.LockedState, RegistryValueKind.DWord);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegistryHelper.WriteValue(KeyPath, "LockState", LockStateEnum.WaitToLockedState,
|
||||
RegistryValueKind.DWord);
|
||||
// 写入超时的时间
|
||||
RegistryHelper.WriteValue(KeyPath, "ExpireTime", cmd.ExpiryTime, RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 解锁
|
||||
var lockType = cmd.LockType;
|
||||
if (lockType == 0)
|
||||
{
|
||||
RegistryHelper.WriteValue(KeyPath, "LockState", LockStateEnum.UnLockedState,
|
||||
RegistryValueKind.DWord);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegistryHelper.WriteValue(KeyPath, "LockState", LockStateEnum.WaitToUnLockedState,
|
||||
RegistryValueKind.DWord);
|
||||
// 写入等待解锁超时的时间
|
||||
RegistryHelper.WriteValue(KeyPath, "ExpireTime", cmd.ExpiryTime, RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue