|
|
|
@ -6,10 +6,13 @@ using Infrastructure.Extensions;
|
|
|
|
|
using Infrastructure.Web.SignalR;
|
|
|
|
|
using IoT.Shared.Services;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Vibrant.InfluxDB.Client;
|
|
|
|
|
using Vibrant.InfluxDB.Client.Rows;
|
|
|
|
@ -32,6 +35,7 @@ namespace IoTCenter.Services
|
|
|
|
|
private readonly IRepository<IoTTimer> _iotTimerRepo;
|
|
|
|
|
private readonly IRepository<IoTTigger> _iotTiggerRepo;
|
|
|
|
|
private readonly DataService _dataService;
|
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
|
|
|
|
|
|
|
|
public IoTCenterHub(IConfiguration cfg,
|
|
|
|
|
IEventPublisher eventPublisher,
|
|
|
|
@ -46,7 +50,8 @@ namespace IoTCenter.Services
|
|
|
|
|
IRepository<SceneCommand> sceneCommandRepo,
|
|
|
|
|
IRepository<IoTTimer> iotTimerRepo,
|
|
|
|
|
IRepository<IoTTigger> iotTiggerRepo,
|
|
|
|
|
DataService dataService)
|
|
|
|
|
DataService dataService,
|
|
|
|
|
IHttpClientFactory httpClientFactory)
|
|
|
|
|
{
|
|
|
|
|
this._cfg = cfg;
|
|
|
|
|
this._eventPublisher = eventPublisher;
|
|
|
|
@ -62,6 +67,7 @@ namespace IoTCenter.Services
|
|
|
|
|
this._iotTimerRepo = iotTimerRepo;
|
|
|
|
|
this._iotTiggerRepo = iotTiggerRepo;
|
|
|
|
|
this._dataService = dataService;
|
|
|
|
|
this._httpClientFactory = httpClientFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ServerToClient(string method, string message, string toClient, string fromClient = null)
|
|
|
|
@ -272,11 +278,78 @@ namespace IoTCenter.Services
|
|
|
|
|
{
|
|
|
|
|
this.ServerToClient(method, message, to, from);
|
|
|
|
|
}
|
|
|
|
|
else if (method == Methods.UpdateDvr)
|
|
|
|
|
{
|
|
|
|
|
var model = message.FromJson<Data>();
|
|
|
|
|
this.UpdateDvr(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateDvr(Data model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).FirstOrDefault(o => o.Id == model.DeviceId);
|
|
|
|
|
var number = device.Node.Number;
|
|
|
|
|
var url = this._cfg.GetValue<string>("srs", "http://localhost:1985");
|
|
|
|
|
var result = "";
|
|
|
|
|
var method = Methods.UpdateCamera;
|
|
|
|
|
if (model.Value == "是")
|
|
|
|
|
{
|
|
|
|
|
var url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__¶m=enable&data=live/main{device.Number}";
|
|
|
|
|
if (CallSrs(url2))
|
|
|
|
|
{
|
|
|
|
|
this.ServerToClient(method, model.ToJson(), number);
|
|
|
|
|
}
|
|
|
|
|
url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__¶m=enable&data=live/sub{device.Number}";
|
|
|
|
|
if (CallSrs(url2))
|
|
|
|
|
{
|
|
|
|
|
this.ServerToClient(method, model.ToJson(), number);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__¶m=disable&data=live/main{device.Number}";
|
|
|
|
|
if (CallSrs(url2))
|
|
|
|
|
{
|
|
|
|
|
this.ServerToClient(method, model.ToJson(), number);
|
|
|
|
|
}
|
|
|
|
|
url2 = url + $"/api/v1/raw?rpc=update&scope=dvr&value=__defaultVhost__¶m=disable&data=live/sub{device.Number}";
|
|
|
|
|
if (CallSrs(url2))
|
|
|
|
|
{
|
|
|
|
|
this.ServerToClient(method, model.ToJson(), number);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CallSrs(string url)
|
|
|
|
|
{
|
|
|
|
|
var result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var httpClient = this._httpClientFactory.CreateClient();
|
|
|
|
|
var response = httpClient.GetStringAsync(url).Result;
|
|
|
|
|
var json = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
|
|
|
|
|
if (json["code"] == "0")
|
|
|
|
|
{
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
|
|
|
|
|