You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.7 KiB
144 lines
3.7 KiB
using JiLinApp.Biz.TransmitAlarm;
|
|
using JiLinApp.Core;
|
|
using JiLinApp.Docking.FenceAlarm;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace JiLinApp.Pages.FenceServerManage;
|
|
|
|
/// <summary>
|
|
/// Main.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class Main : UserControl
|
|
{
|
|
#region Fields
|
|
|
|
private UdpManager Manager { get; } = new();
|
|
|
|
private IAlarmService AlarmService { get; set; }
|
|
|
|
#endregion Fields
|
|
|
|
public Main()
|
|
{
|
|
InitializeComponent();
|
|
Init();
|
|
}
|
|
|
|
#region Init
|
|
|
|
private void Init()
|
|
{
|
|
if (DataContext != null)
|
|
{
|
|
MainViewModel vm = DataContext as MainViewModel;
|
|
vm.SetView(this);
|
|
Manager.OnFenceUdpDeviceState += vm.OnFenceUdpDeviceState;
|
|
Manager.OnFenceUdpSectorState += vm.OnFenceUdpSensorState;
|
|
Manager.OnFenceUdpAlarm += vm.OnFenceUdpAlarm;
|
|
}
|
|
AlarmService = Global.AlarmService;
|
|
if (AlarmService != null)
|
|
{
|
|
AlarmService.OnFenceUdpSendDevices += AlarmService_OnFenceUdpSendDevices;
|
|
AlarmService.OnFenceUdpSendSensors += AlarmService_OnFenceUdpSendSensors;
|
|
}
|
|
}
|
|
|
|
private void ChangeState(bool openState)
|
|
{
|
|
if (openState)
|
|
{
|
|
OpenBtn.IsEnabled = false;
|
|
StopBtn.IsEnabled = true;
|
|
}
|
|
else
|
|
{
|
|
OpenBtn.IsEnabled = true;
|
|
StopBtn.IsEnabled = false;
|
|
}
|
|
}
|
|
|
|
#endregion Init
|
|
|
|
#region ElementEvent
|
|
|
|
private void OpenBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
UdpManagerConfig config = new()
|
|
{
|
|
ServerPort = int.Parse(ServerPort.Text),
|
|
DeviceHeartKeep = int.Parse(DeviceHeartKeep.Text)
|
|
};
|
|
Manager.Start(config);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString());
|
|
return;
|
|
}
|
|
ChangeState(true);
|
|
}
|
|
|
|
private void StopBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Manager.Stop();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
ChangeState(false);
|
|
}
|
|
|
|
#endregion ElementEvent
|
|
|
|
#region Event
|
|
|
|
private void AlarmService_OnFenceUdpSendDevices(JObject reqObj)
|
|
{
|
|
List<object> respDeviceList = new();
|
|
List<UdpAlarmHost> deviceList = Manager.GetDeviceList();
|
|
foreach (var item in deviceList)
|
|
{
|
|
if (item.DeviceId <= 0) continue;
|
|
respDeviceList.Add(new
|
|
{
|
|
id = item.DeviceId,
|
|
//groupId = item.GroupId,
|
|
//userId = item.UserId,
|
|
onlineState = item.OnlineState,
|
|
defenceState = item.DefenceState
|
|
});
|
|
}
|
|
AlarmService.SendDevices(DeviceType.Fence, respDeviceList);
|
|
}
|
|
|
|
private void AlarmService_OnFenceUdpSendSensors(JObject reqObj)
|
|
{
|
|
int deviceId = reqObj.GetValue("deviceId", StringComparison.OrdinalIgnoreCase).ToInt();
|
|
List<SectorState> sectorList = Manager.TryGetDevice(deviceId, out UdpAlarmHost device) ? device.SectorDict.Values.ToList() : new();
|
|
List<object> respSensorList = new();
|
|
foreach (var item in sectorList)
|
|
{
|
|
respSensorList.Add(new
|
|
{
|
|
id = item.Id,
|
|
deviceId = item.DeviceId,
|
|
state = item.State,
|
|
type = item.Type,
|
|
});
|
|
}
|
|
AlarmService.SendSensors(DeviceType.Fence, deviceId, respSensorList);
|
|
}
|
|
|
|
#endregion Event
|
|
}
|