|
|
|
@ -27,6 +27,9 @@ namespace IoTCenter.Services
|
|
|
|
|
private readonly IRepository<Category> _categoryRepo;
|
|
|
|
|
private readonly IRepository<Product> _productRepo;
|
|
|
|
|
private readonly IRepository<Scene> _sceneRepo;
|
|
|
|
|
private readonly IRepository<SceneCommand> _sceneCommandRepo;
|
|
|
|
|
private readonly IRepository<Timer> _timerRepo;
|
|
|
|
|
private readonly IRepository<Tigger> _tiggerRepo;
|
|
|
|
|
|
|
|
|
|
public PageHub(IConfiguration cfg,
|
|
|
|
|
IRepository<Node> nodeRepo,
|
|
|
|
@ -36,7 +39,10 @@ namespace IoTCenter.Services
|
|
|
|
|
IRepository<Command> commandRepo,
|
|
|
|
|
IRepository<Category> categoryRepo,
|
|
|
|
|
IRepository<Product> productRepo,
|
|
|
|
|
IRepository<Scene> sceneRepo)
|
|
|
|
|
IRepository<Scene> sceneRepo,
|
|
|
|
|
IRepository<SceneCommand> sceneCommandRepo,
|
|
|
|
|
IRepository<Timer> timerRepo,
|
|
|
|
|
IRepository<Tigger> tiggerRepo)
|
|
|
|
|
{
|
|
|
|
|
this._cfg = cfg;
|
|
|
|
|
this._nodeRepo = nodeRepo;
|
|
|
|
@ -47,6 +53,9 @@ namespace IoTCenter.Services
|
|
|
|
|
this._categoryRepo = categoryRepo;
|
|
|
|
|
this._productRepo = productRepo;
|
|
|
|
|
this._sceneRepo = sceneRepo;
|
|
|
|
|
this._sceneCommandRepo = sceneCommandRepo;
|
|
|
|
|
this._timerRepo = timerRepo;
|
|
|
|
|
this._tiggerRepo = tiggerRepo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ClientToServer(string method, string message, string connectionId)
|
|
|
|
@ -115,6 +124,14 @@ namespace IoTCenter.Services
|
|
|
|
|
{
|
|
|
|
|
this.DeleteCommand(message);
|
|
|
|
|
}
|
|
|
|
|
else if (method == Methods.EditSceneCommandResponse)
|
|
|
|
|
{
|
|
|
|
|
this.UpdateSceneCommand(message);
|
|
|
|
|
}
|
|
|
|
|
else if (method == Methods.DeleteSceneCommandResponse)
|
|
|
|
|
{
|
|
|
|
|
this.DeleteSceneCommand(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshDeviceList(string message, string connectionId)
|
|
|
|
@ -409,6 +426,52 @@ namespace IoTCenter.Services
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
|
|
|
|
|
private void UpdateSceneCommand(string message)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("iot center> receive edit scene command message");
|
|
|
|
|
var model = message.FromJson<EditSceneCommandModel>();
|
|
|
|
|
var sceneCommand = _sceneCommandRepo.Table().FirstOrDefault(o => o.Id == model.Id);
|
|
|
|
|
if (sceneCommand == null)
|
|
|
|
|
{
|
|
|
|
|
sceneCommand = new SceneCommand
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id
|
|
|
|
|
};
|
|
|
|
|
_sceneCommandRepo.Add(sceneCommand);
|
|
|
|
|
}
|
|
|
|
|
sceneCommand.SceneId = model.SceneId.Value;
|
|
|
|
|
sceneCommand.CommandId = model.CommandId.Value;
|
|
|
|
|
_sceneCommandRepo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
|
|
|
|
|
private void DeleteSceneCommand(string message)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("iot center> receive delete scene command message");
|
|
|
|
|
var model = message.FromJson<EditSceneCommandModel>();
|
|
|
|
|
var sceneCommand = _sceneCommandRepo.Table().FirstOrDefault(o => o.Id == model.Id);
|
|
|
|
|
if (sceneCommand != null)
|
|
|
|
|
{
|
|
|
|
|
_sceneCommandRepo.Delete(sceneCommand);
|
|
|
|
|
_sceneCommandRepo.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ApiCallback(string message, string connectionId)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(connectionId))
|
|
|
|
|