示例#1
0
        public async Task <HttpResponseMessage> UnregisterDevices([FromBody] IoTHubRegisterWrapper input)
        {
            try
            {
                RegistryManager registryManager = RegistryManager.CreateFromConnectionString(input.ConnectionString);

                List <string> deviceIds = input.DeviceIds.Split(',').Select(x => x.Trim()).ToList();

                IEnumerable <DeviceRegistryOperationError> errors = await UnregisterDevices(registryManager, deviceIds);

                return(Request.CreateResponse(HttpStatusCode.Created, errors));
            }
            catch (NullReferenceException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"The input Received by the API was null. This sometimes happens if the message in the Logic App is malformed. Check the message to make sure there are no escape characters like '\'.", ex));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
示例#2
0
        public async Task <HttpResponseMessage> RegisterDevices([FromBody] IoTHubRegisterWrapper input,
                                                                [Metadata(null, null, VisibilityType.Internal)] bool enable = false)
        {
            try
            {
                RegistryManager registryManager = RegistryManager.CreateFromConnectionString(input.ConnectionString);

                List <string> deviceIds = input.DeviceIds.Split(',').Select(x => x.Trim()).ToList();

                IEnumerable <DeviceRegistryOperationError> errors = await RegisterDevices(registryManager, deviceIds, enable);

                return(Request.CreateResponse(HttpStatusCode.Created, errors));
            }
            // TODO: Move exception handling for all these apis to a common method.
            catch (NullReferenceException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"The input Received by the API was null. This sometimes happens if the message in the Logic App is malformed. Check the message to make sure there are no escape characters like '\'.", ex));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
示例#3
0
 public async Task <HttpResponseMessage> RegisterAndEnableDevices([FromBody] IoTHubRegisterWrapper input)
 {
     return(await RegisterDevices(input, true));
 }