Ejemplo n.º 1
0
        public IActionResult Add([FromForm] AddDeviceRequest request)
        {
            if (request == null)
            {
                return(BadRequest("Unable to locate the body request"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Device device = null;

            try
            {
                device = this.deviceRepository.AddDevice(request.DeviceIdentifier, request.CallerIdentifier);
            }
            catch (ApplicationException ex)
            {
                this.logger.LogWarning(ex.Message);

                return(Conflict(ex.Message));
            }

            return(Created(new Uri($"/api/device/get/{device.Id}", UriKind.Relative), device));
        }
        private static void addDevice(IoTDAClient client)
        {
            AddDeviceRequest req = new AddDeviceRequest
            {
                Body = new AddDevice()
                {
                    NodeId    = "1211211",
                    ProductId = "5e25d39a3b7c24fa3638804b"
                }
            };

            try
            {
                var resp = client.AddDevice(req);
                Console.WriteLine(resp);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
Ejemplo n.º 3
0
        public AddDeviceResponse SetClientDevice(AddDeviceRequest request)
        {
            var result      = new ServerAddDeviceResponse();
            var returnValue = result.ProcessRequest(cnn, request);

            return(returnValue);
        }
Ejemplo n.º 4
0
        private async void RegisterNewDeviceCommandExecute()
        {
            this.IsBusy      = true;
            this.BusyMessage = "Registrazione in corso";

            var request = new AddDeviceRequest();

            request.CallerIdentifier = callerIdentifier;
            request.DeviceIdentifier = deviceIdentifier;

            string url = $"{base.BaseUrl}/Device/Add";

            var response = await base.MakeWebRequestAsync <AddDeviceRequest, AddDeviceResponse>(url, request);

            if (response != null)
            {
                IFile file = await base.RootFolder.CreateFileAsync("profile", PCLStorage.CreationCollisionOption.ReplaceExisting);

                await file.WriteAllTextAsync(string.Empty);

                CrossSettings.Current.AddOrUpdateValue("CallerIdentifier", this.CallerIdentifier);
                CrossSettings.Current.AddOrUpdateValue("DeviceIdentifier", this.DeviceIdentifier);
                Messenger.Default.Send <PromptMessage>(new PromptMessage("OK", "Registrazione completata!"));
                Messenger.Default.Send <NavigateMessage>(new NavigateMessage("MainPage"));
            }
            else
            {
                Messenger.Default.Send <PromptMessage>(new PromptMessage("OOPPSS", "Qualcosa è andato storto!"));
            }

            this.BusyMessage = string.Empty;
            this.IsBusy      = false;
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> SetDevice([FromBody] AddDeviceRequest device)
        {
            var loggedUser = User.GetUserIdFromToken();
            await _deviceService.CreateOrUpdateDeviceAsync(loggedUser, device);

            return(Ok());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建设备
        /// </summary>
        public async Task <AddDeviceResponse> AddDeviceAsync(AddDeviceRequest addDeviceRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/v5/iot/{project_id}/devices", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json", addDeviceRequest);
            HttpResponseMessage response         = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <AddDeviceResponse>(response));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds the device.
 /// </summary>
 public async Task<Device> AddDeviceAsync(byte deviceId, DeviceType deviceType, DeviceSubtype deviceSubtype)
 {
     var request = new AddDeviceRequest
                       {
                           DeviceId = deviceId,
                           DeviceType = deviceType,
                           DeviceSubType = deviceSubtype
                       };
     var response = await this.restClient.PostAsync(request);
     return response.Result;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 提供在指定的产品Id下创建一个设备的能力,生成设备名称与设备秘钥。
        /// </summary>
        /// <param name="req">参考<see cref="AddDeviceRequest"/></param>
        /// <returns>参考<see cref="AddDeviceResponse"/>实例</returns>
        public async Task <AddDeviceResponse> AddDevice(AddDeviceRequest req)
        {
            JsonResponseModel <AddDeviceResponse> rsp = null;

            try
            {
                var strResp = await this.InternalRequest(req, "AddDevice");

                rsp = JsonConvert.DeserializeObject <JsonResponseModel <AddDeviceResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
Ejemplo n.º 9
0
        public async Task <Device> Deploy(AddDeviceRequest request)
        {
            var packetRequest = TinyMapper.Map(request, new PacketAddDeviceRequest());
            var serialized    = JsonConvert.SerializeObject(packetRequest, Formatting.None, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });
            var result = await _client.PostAsync($"/projects/{_config.ProjectId}/devices",
                                                 new StringContent(serialized,
                                                                   Encoding.Default, "application/json"));

            return(await HttpExtensions.SuccessOrThrow(result, data =>
            {
                var device = JsonConvert.DeserializeObject <PacketDevice>(data);
                return TinyMapper.Map <PacketDevice, Device>(device);
            }));
        }
Ejemplo n.º 10
0
 public async Task<IResponse<Device>> Post(AddDeviceRequest request)
 {
     var alreadyExist = await this.deviceRepository
         .ExistAsync(x => x.Id == request.DeviceId);
     if (alreadyExist)
     {
         throw HttpError.Conflict(string.Format("Device with ID {0} already exists",request.DeviceId));
     }
     var device = new Device
                      {
                          Id = request.DeviceId,
                          Type = request.DeviceType,
                          Subtype = request.DeviceSubType
                      };
     await this.deviceRepository.InsertAsync(device);
     return ResponseFactory.CreateResponse<AddDeviceResponse,Device>(device);
 }
Ejemplo n.º 11
0
        private void _sipRegistrarCore_RPCDmsRegisterReceived(SIPTransaction sipTransaction, GB28181.SIPSorcery.SIP.App.SIPAccount sIPAccount)
        {
            try
            {
                Device     _device    = new Device();
                SIPRequest sipRequest = sipTransaction.TransactionRequest;
                _device.Guid = Guid.NewGuid().ToString();
                _device.IP   = sipTransaction.TransactionRequest.RemoteSIPEndPoint.Address.ToString();//IPC
                _device.Name = "gb" + _device.IP;
                _device.LoginUser.Add(new LoginUser()
                {
                    LoginName = sIPAccount.SIPUsername ?? "admin", LoginPwd = sIPAccount.SIPPassword ?? "123456"
                });
                _device.Port         = Convert.ToUInt32(sipTransaction.TransactionRequest.RemoteSIPEndPoint.Port); //5060
                _device.GBID         = sipTransaction.TransactionRequestFrom.URI.User;                             //42010000001180000184
                _device.PtzType      = 0;
                _device.ProtocolType = 0;
                _device.ShapeType    = ShapeType.Dome;
                //var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.MaxMessageLength, int.MaxValue) };
                //  var channel = new Channel(EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080", ChannelCredentials.Insecure);
                var channel = GrpcChannel.ForAddress(EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080");

                logger.Debug("Device Management Service Address: " + (EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080"));
                var client = new Manage.ManageClient(channel);
                AddDeviceRequest _AddDeviceRequest = new AddDeviceRequest();
                _AddDeviceRequest.Device.Add(_device);
                _AddDeviceRequest.LoginRoleId = "XXXX";
                var reply = client.AddDevice(_AddDeviceRequest);
                if (reply.Status == OP_RESULT_STATUS.OpSuccess)
                {
                    logger.Debug("Device[" + sipTransaction.TransactionRequest.RemoteSIPEndPoint + "] have completed registering DMS service.");
                }
                else
                {
                    logger.Error("_sipRegistrarCore_RPCDmsRegisterReceived: " + reply.Status.ToString());
                }
            }
            catch (Exception ex)
            {
                logger.Error("Device[" + sipTransaction.TransactionRequest.RemoteSIPEndPoint + "] register DMS failed: " + ex.Message);
            }
        }
        public async Task<AddDeviceResponse> add([FromBody] AddDeviceRequest request)
        {
            using (var dbContext = new PulseDbContext())
            {
                var account = await dbContext.Accounts
                                        .Include(a => a.Devices)
                                        .Where(a => a.AccountId == request.AccountId)
                                        .FirstOrDefaultAsync();

                if (account == null)
                    return null;

                dbContext.Devices.Add(request.Device);
                account.Devices.Add(request.Device);

                await dbContext.SaveChangesAsync();
            }

            return request.Device.ForceType<AddDeviceResponse>();
        }
Ejemplo n.º 13
0
        public async Task CreateOrUpdateDeviceAsync(int loggedUser, AddDeviceRequest device)
        {
            //var dev = await _uow.DeviceRepository.FindBy(d => d.DeviceId == device.DeviceId && d.UserId == loggedUser).FirstOrDefaultAsync();
            var dev = await _uow.DeviceRepository.FindBy(d => d.UserId == loggedUser).FirstOrDefaultAsync();

            if (dev == null)
            {
                dev        = new Device();
                dev.Token  = device.Token;
                dev.Type   = (DeviceTypeEnum)device.DeviceType;
                dev.UserId = loggedUser;
                await _uow.DeviceRepository.AddAsync(dev);
            }
            else
            {
                dev.Token = device.Token;
                dev.Type  = (DeviceTypeEnum)device.DeviceType;
                await _uow.DeviceRepository.UpdateAsync(dev, dev.Id);
            }
            await _uow.CommitAsync();
        }
Ejemplo n.º 14
0
 public AddDeviceResponse AddDevice(AddDeviceRequest request)
 {
     AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
     return(AddDeviceWithOptions(request, runtime));
 }
Ejemplo n.º 15
0
 public async Task <Device> Deploy(AddDeviceRequest request)
 {
     return(await _accessor(request.Provider).Deploy(request));
 }
Ejemplo n.º 16
0
        private void DeviceDmsRegister(SIPTransaction sipTransaction, string gbname)
        {
            try
            {
                //Device insert into database
                Device     _device    = new Device();
                SIPRequest sipRequest = sipTransaction.TransactionRequest;
                _device.Guid = Guid.NewGuid().ToString();
                _device.IP   = sipTransaction.TransactionRequest.RemoteSIPEndPoint.Address.ToString();//IPC
                _device.Name = gbname;
                _device.LoginUser.Add(new LoginUser()
                {
                    LoginName = _SIPAccount.SIPUsername ?? "admin", LoginPwd = _SIPAccount.SIPPassword ?? "123456"
                });                                                                                                //same to GB config service
                _device.Port         = Convert.ToUInt32(sipTransaction.TransactionRequest.RemoteSIPEndPoint.Port); //5060
                _device.GBID         = sipTransaction.TransactionRequestFrom.URI.User;                             //42010000001180000184
                _device.PtzType      = 0;
                _device.ProtocolType = 0;
                _device.ShapeType    = ShapeType.Dome;
                //var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.MaxMessageLength, int.MaxValue) };
                var channel = GrpcChannel.ForAddress(EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080"); //, ChannelCredentials.Insecure);
                logger.Debug("Device Management Service Address: " + (EnvironmentVariables.DeviceManagementServiceAddress ?? "devicemanagementservice:8080"));
                var client = new Manage.ManageClient(channel);
                //if (!_sipCoreMessageService.NodeMonitorService.ContainsKey(_device.GBID))
                //{
                //    AddDeviceRequest _AddDeviceRequest = new AddDeviceRequest();
                //    _AddDeviceRequest.Device.Add(_device);
                //    _AddDeviceRequest.LoginRoleId = "XXXX";
                //    var reply = client.AddDevice(_AddDeviceRequest);
                //    if (reply.Status == OP_RESULT_STATUS.OpSuccess)
                //    {
                //        logger.Debug("Device[" + sipTransaction.TransactionRequest.RemoteSIPEndPoint + "] have added registering DMS service.");
                //        DeviceEditEvent(_device.GBID, "add");
                //    }
                //    else
                //    {
                //        logger.Error("_sipRegistrarCore_RPCDmsRegisterReceived.AddDevice: " + reply.Status.ToString());
                //    }
                //}
                //else
                //{
                //    UpdateDeviceRequest _UpdateDeviceRequest = new UpdateDeviceRequest();
                //    _UpdateDeviceRequest.DeviceItem.Add(_device);
                //    _UpdateDeviceRequest.LoginRoleId = "XXXX";
                //    var reply = client.UpdateDevice(_UpdateDeviceRequest);
                //    if (reply.Status == OP_RESULT_STATUS.OpSuccess)
                //    {
                //        logger.Debug("Device[" + sipTransaction.TransactionRequest.RemoteSIPEndPoint + "] have updated registering DMS service.");
                //    }
                //    else
                //    {
                //        logger.Error("_sipRegistrarCore_RPCDmsRegisterReceived.UpdateDevice: " + reply.Status.ToString());
                //    }
                //}

                //add & update device
                AddDeviceRequest _AddDeviceRequest = new AddDeviceRequest();
                _AddDeviceRequest.Device.Add(_device);
                _AddDeviceRequest.LoginRoleId = "XXXX";
                var reply = client.AddDevice(_AddDeviceRequest);
                if (reply.Status == OP_RESULT_STATUS.OpSuccess)
                {
                    logger.Debug("Device added into DMS service: " + JsonConvert.SerializeObject(_device));
                }
                else
                {
                    logger.Warn("DeviceDmsRegister.AddDevice: " + reply.Status.ToString());
                }
            }
            catch (Exception ex)
            {
                logger.Error("DeviceDmsRegister Exception: " + ex.Message);
            }
        }
Ejemplo n.º 17
0
 public async Task <AddDeviceResponse> AddDeviceAsync(AddDeviceRequest addDeviceRequest)
 {
     return(await _onenetClient.ExecuteAsync <AddDeviceResponse>(addDeviceRequest));
 }
        public async Task <ActionResult <Device> > Deploy([FromBody] AddDeviceRequest request)
        {
            var device = await _deployment.Deploy(request);

            return(Ok(device));
        }
Ejemplo n.º 19
0
 /// <summary>
 ///  注册单个设备并返回秘钥信息
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public async Task <AddDeviceResponse> AddDevice(AddDeviceRequest request)
 {
     return(await new AddDeviceExecutor().Client(this).Execute <AddDeviceResponse, AddDeviceResult, AddDeviceRequest>(request).ConfigureAwait(false));
 }
Ejemplo n.º 20
0
 /// <summary>
 ///  注册单个设备并返回秘钥信息
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public AddDeviceResponse AddDevice(AddDeviceRequest request)
 {
     return(new AddDeviceExecutor().Client(this).Execute <AddDeviceResponse, AddDeviceResult, AddDeviceRequest>(request));
 }
Ejemplo n.º 21
0
 public Task <Device> Deploy(AddDeviceRequest request)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 22
0
 public async Task <AddDeviceResponse> AddDeviceWithOptionsAsync(AddDeviceRequest request, AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime)
 {
     AlibabaCloud.TeaUtil.Common.ValidateModel(request);
     return(TeaModel.ToObject <AddDeviceResponse>(await DoRequestAsync("AddDevice", "HTTPS", "POST", "2020-05-15", "AK", null, request.ToMap(), runtime)));
 }
Ejemplo n.º 23
0
 public async Task <AddDeviceResponse> AddDeviceAsync(AddDeviceRequest request)
 {
     AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
     return(await AddDeviceWithOptionsAsync(request, runtime));
 }