Esempio n. 1
0
        public async Task <NorthApiResult <CommandModel> > CommandCreate(CommandCreateModel model)
        {
            var result = new NorthApiResult <CommandModel>();

            #region ==参数验证==

            if (model == null || model.DeviceId.IsNull())
            {
                result.Msg = "设备编号不能为空";
                return(result);
            }

            if (model.Command == null)
            {
                result.Msg = "下发命令的信息不能为空";
                return(result);
            }

            if (model.Command.ServiceId.IsNull())
            {
                result.Msg = "命令对应的服务ID不能为空";
                return(result);
            }


            if (model.Command.Method.IsNull())
            {
                result.Msg = "命令服务下具体的命令名称不能为空";
                return(result);
            }


            if (model.Command.Paras == null)
            {
                result.Msg = "命令参数不能为空";
                return(result);
            }

            #endregion

            var httpResult = await _httpHandler.PostJson(_urls.CommandCreate, model);

            result.StatusCode = httpResult.StatusCode;

            if (result.StatusCode == HttpStatusCode.Created)
            {
                result.Success = true;
                result.Data    = JsonConvert.DeserializeObject <CommandModel>(httpResult.Content);
                _logger?.LogDebug("CommandCreate:{@Result}", result.Data);
            }
            else
            {
                result.Error = JsonConvert.DeserializeObject <HttpError>(httpResult.Content);
                _logger?.LogDebug("CommandCreate:{@Error}", result.Error);
            }

            return(result);
        }
        public ActionResult <CommandReadModel> AddCommand(CommandCreateModel command)
        {
            //Basic Validatation happens through Annotations on Create Command Model

            if (!_service.Add(command, out var createdCommand))
            {
                //TODO: Wouldnt do this for real in production environment, but, until we get round to it
                return(new NoContentResult());
            }

            //TODO: Don't leak the database Id, rather use the restful entity id
            return(CreatedAtRoute(nameof(LookupCommand), new { Id = createdCommand.Id }, createdCommand));
        }
        /// <summary>
        /// 创建命令
        /// </summary>
        /// <returns></returns>
        private async Task CommandCreate()
        {
            var model = new CommandCreateModel
            {
                DeviceId = _deviceId,
                Command  = new CommandBody
                {
                    ServiceId = "DTU",
                    Method    = "SETCommand",
                    Paras     = new
                    {
                        Value = "1111"
                    }
                }
            };

            await _client.CommandCreate(model);
        }
Esempio n. 4
0
        public bool Add(CommandCreateModel createModel, out CommandReadModel createdCommand)
        {
            var commandDatabaseModel = _mapper.Map <Database.CommandModel>(createModel);

            try
            {
                _dataAccessLayer.Create(commandDatabaseModel);
                _dataAccessLayer.Save();
            }
            catch (Exception exception)
            {
                //TODO: Beef this up for real production environment
                //Poor Man's Logging until full logging implemented
                _logger.LogError("Something went Boom", exception);
                createdCommand = null;
                return(false);
            }

            createdCommand = _mapper.Map <CommandReadModel>(commandDatabaseModel);
            return(true);
        }
Esempio n. 5
0
 private static async void CreateUserTable()
 {
     await Database.CreateTable(CommandCreateModel.CreateUserTable());
 }
Esempio n. 6
0
 private static async void CreateCertifiedPackageTable()
 {
     await Database.CreateTable(CommandCreateModel.CreateCertifiedPackageTable());
 }