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.
165 lines
7.1 KiB
165 lines
7.1 KiB
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Linq;
|
|
//using Application.Domain.Entities;
|
|
//using Application.Models;
|
|
//using Application.Services;
|
|
//using Infrastructure.Application;
|
|
//using Infrastructure.Data;
|
|
//using Infrastructure.Extensions;
|
|
//using Infrastructure.Web.Mvc;
|
|
//using IoTShared;
|
|
//using IoTShared.Controllers;
|
|
//using Microsoft.AspNetCore.Authorization;
|
|
//using Microsoft.AspNetCore.Mvc;
|
|
//using Microsoft.AspNetCore.Mvc.Rendering;
|
|
//using Microsoft.AspNetCore.SignalR;
|
|
//using Microsoft.EntityFrameworkCore;
|
|
|
|
//namespace IoTCenter.Areas.Admin.Controllers
|
|
//{
|
|
// [Authorize]
|
|
// [Area(nameof(Admin))]
|
|
// public class CommandController : CrudController<Command, PagedListModel<DisplayCommandModel>, DisplayCommandModel, EditCommandModel>
|
|
// {
|
|
// private readonly IRepository<Node> _nodeRepo;
|
|
// private readonly IRepository<Sence> _senceRepo;
|
|
// private readonly IRepository<Api> _apiRepo;
|
|
// private readonly IRepository<Command> _repo;
|
|
// private readonly AjaxController _ajax;
|
|
// private readonly IHubContext<PageHub> _pageHubContext;
|
|
|
|
// public CommandController(IRepository<Node> nodeRepo, IRepository<Sence> senceRepo, IRepository<Api> apiRepo, IRepository<Command> repo, AjaxController ajax, IHubContext<PageHub> pageHubContext) : base(repo)
|
|
// {
|
|
// this._repo = repo;
|
|
// this._nodeRepo = nodeRepo;
|
|
// this._senceRepo = senceRepo;
|
|
// this._apiRepo = apiRepo;
|
|
// this._ajax = ajax;
|
|
// this._pageHubContext = pageHubContext;
|
|
// }
|
|
|
|
// public override IActionResult Add(EditCommandModel model)
|
|
// {
|
|
// if (ModelState.IsValid)
|
|
// {
|
|
// var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.NodeId).Number;
|
|
// this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.CreateCommand), model);
|
|
// return RedirectTo();
|
|
// }
|
|
// ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
|
// return View(model);
|
|
// }
|
|
|
|
// public override IActionResult Edit(EditCommandModel model)
|
|
// {
|
|
// if (ModelState.IsValid)
|
|
// {
|
|
// var entity = this._repo.Table().FirstOrDefault(o => o.Id == model.Id);
|
|
// var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.NodeId).Number;
|
|
// this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.EditCommand), model);
|
|
// return RedirectTo();
|
|
// }
|
|
|
|
// ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
|
// return View(model);
|
|
// }
|
|
|
|
// public override IActionResult Delete(List<Guid> list)
|
|
// {
|
|
// foreach (var id in list)
|
|
// {
|
|
// try
|
|
// {
|
|
// var entity = this._repo.Table().FirstOrDefault(o => o.Id == id);
|
|
// var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Sences.Any(s => s.Id == entity.SenceId)).Number;
|
|
// this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.DeleteCommand), id);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.PrintStack();
|
|
// return RedirectTo(message: ex.Message);
|
|
// }
|
|
// }
|
|
// return RedirectTo();
|
|
// }
|
|
|
|
// public IActionResult Api(Guid id)
|
|
// {
|
|
// var model = this.GetParameters(id, null);
|
|
// return PartialView("_Api", model);
|
|
// }
|
|
|
|
// public override IQueryable<Command> Include(IQueryable<Command> query)
|
|
// {
|
|
// return query.Include(o => o.Sence).Include(o => o.Api).ThenInclude(o => o.Device).ThenInclude(o => o.Node);
|
|
// }
|
|
|
|
// public override void ToDisplayModel(Command entity, DisplayCommandModel model)
|
|
// {
|
|
// model.NodeId = entity.Api.Device.Node.Name;
|
|
// model.DeviceId = entity.Api.Device.DisplayName;
|
|
// model.ApiId = entity.Api.Name;
|
|
// model.SenceId = entity.Sence.Name;
|
|
// }
|
|
|
|
// public override void ToModel(Command entity, EditCommandModel model)
|
|
// {
|
|
// if (entity != null)
|
|
// {
|
|
// model.NodeId = entity.Api.Device.NodeId;
|
|
// model.DeviceId = entity.Api.DeviceId;
|
|
// }
|
|
// ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
|
|
// ViewData.SelectList(o => model.SenceId, () => this._ajax.GetSenceSelectList(model.NodeId.Value, model.SenceId), model.NodeId.HasValue);
|
|
// ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue);
|
|
// ViewData.SelectList(o => model.ApiId, () => this._ajax.GetApiSelectList(model.DeviceId.Value, model.ApiId), model.DeviceId.HasValue);
|
|
// if (model.ApiId.HasValue)
|
|
// {
|
|
// model.Parameters = this.GetParameters(model.ApiId.Value, entity.QueryString);
|
|
// }
|
|
// }
|
|
|
|
// public override void ToEntity(EditCommandModel model, Command entity)
|
|
// {
|
|
// entity.QueryString = model.GetQueryString();
|
|
// }
|
|
|
|
// private List<EditApiParameterModel> GetParameters(Guid apiId, string queryString)
|
|
// {
|
|
// var api = this._apiRepo.ReadOnlyTable().Include(o => o.Parameters).Include(o => o.Device).ThenInclude(o => o.Data).FirstOrDefault(o => o.Id == apiId);
|
|
// ViewData["Number"] = api.Device.Number;
|
|
// var parameters = api.Parameters.Select(o => o.To<EditApiParameterModel>()).ToList();
|
|
// if (!string.IsNullOrEmpty(queryString))
|
|
// {
|
|
// foreach (var item in queryString.Split('&'))
|
|
// {
|
|
// var array = item.Split('=');
|
|
// var name = array[0];
|
|
// var vlaue = array[1];
|
|
// var param = parameters.FirstOrDefault(o => o.Name == name);
|
|
// if (param != null)
|
|
// {
|
|
// param.Value = vlaue;
|
|
// }
|
|
// }
|
|
// }
|
|
// if (api.Device.Name == "红外转发器")
|
|
// {
|
|
// if (!api.Path.Contains("add") && !api.Path.Contains("get"))
|
|
// {
|
|
// foreach (var item in parameters)
|
|
// {
|
|
// if (item.Name == "code")
|
|
// {
|
|
// var list = api.Device.Data.Where(o => o.Name != "状态").ToList()
|
|
// .Select(o => new SelectListItem { Text = o.Name, Value = o.Value });
|
|
// item.SelectList = new SelectList(list, "Value", "Text", item.Value);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// return parameters;
|
|
// }
|
|
// }
|
|
//} |