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.
138 lines
3.9 KiB
138 lines
3.9 KiB
using Infrastructure.Events;
|
|
using IoT.Shared.Services;
|
|
using IoTNode.DeviceServices.Onvif;
|
|
using Application.Domain.Entities;
|
|
|
|
namespace IoTNode.Services
|
|
{
|
|
public class IoTNodeToServerEventHandler :
|
|
IEventHander<EntityInserted<IoTProduct>>,
|
|
IEventHander<EntityUpdated<IoTProduct>>,
|
|
IEventHander<EntityDeleted<IoTProduct>>,
|
|
IEventHander<EntityInserted<IoTApi>>,
|
|
IEventHander<EntityUpdated<IoTApi>>,
|
|
IEventHander<EntityDeleted<IoTApi>>,
|
|
IEventHander<EntityInserted<IoTParameter>>,
|
|
IEventHander<EntityUpdated<IoTParameter>>,
|
|
IEventHander<EntityDeleted<IoTParameter>>,
|
|
IEventHander<EntityUpdated<IoTGateway>>,
|
|
IEventHander<EntityInserted<IoTDevice>>,
|
|
IEventHander<EntityUpdated<IoTDevice>>,
|
|
IEventHander<EntityDeleted<IoTDevice>>,
|
|
IEventHander<EntityInserted<IoTData>>,
|
|
IEventHander<EntityUpdated<IoTData>>,
|
|
IEventHander<EntityDeleted<IoTData>>
|
|
{
|
|
private readonly OnvifService _onvifService;
|
|
private readonly IoTNodeClient _iotNodeClient;
|
|
|
|
public IoTNodeToServerEventHandler(
|
|
OnvifService onvifService, IoTNodeClient iotNodeClient)
|
|
{
|
|
this._onvifService = onvifService;
|
|
this._iotNodeClient = iotNodeClient;
|
|
}
|
|
|
|
private void ClientToServer<T>(BaseEvent<T> message)
|
|
{
|
|
if (message is EntityInserted<T> || message is EntityUpdated<T>)
|
|
{
|
|
_iotNodeClient.ClientToServer($"Edit{typeof(T).Name}", message.Data, null);
|
|
}
|
|
else if (message is EntityDeleted<T>)
|
|
{
|
|
_iotNodeClient.ClientToServer($"Delete{typeof(T).Name}", message.Data, null);
|
|
}
|
|
}
|
|
|
|
public void Handle(EntityInserted<IoTProduct> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityUpdated<IoTProduct> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityDeleted<IoTProduct> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityInserted<IoTApi> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityUpdated<IoTApi> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityDeleted<IoTApi> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityInserted<IoTParameter> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityUpdated<IoTParameter> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityDeleted<IoTParameter> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityUpdated<IoTGateway> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityInserted<IoTDevice> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityUpdated<IoTDevice> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityDeleted<IoTDevice> message)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
|
|
public void Handle(EntityInserted<IoTData> message)
|
|
{
|
|
if (!message.Data.Hidden)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
}
|
|
|
|
public void Handle(EntityUpdated<IoTData> message)
|
|
{
|
|
if (!message.Data.Hidden)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
}
|
|
|
|
public void Handle(EntityDeleted<IoTData> message)
|
|
{
|
|
if (!message.Data.Hidden)
|
|
{
|
|
this.ClientToServer(message);
|
|
}
|
|
}
|
|
}
|
|
}
|