public static BatchRegisterDeviceResponse Unmarshall(UnmarshallerContext context) { BatchRegisterDeviceResponse batchRegisterDeviceResponse = new BatchRegisterDeviceResponse(); batchRegisterDeviceResponse.HttpResponse = context.HttpResponse; batchRegisterDeviceResponse.RequestId = context.StringValue("BatchRegisterDevice.RequestId"); batchRegisterDeviceResponse.Success = context.BooleanValue("BatchRegisterDevice.Success"); batchRegisterDeviceResponse.ErrorMessage = context.StringValue("BatchRegisterDevice.ErrorMessage"); BatchRegisterDeviceResponse.BatchRegisterDevice_Data data = new BatchRegisterDeviceResponse.BatchRegisterDevice_Data(); data.ApplyId = context.LongValue("BatchRegisterDevice.Data.ApplyId"); batchRegisterDeviceResponse.Data = data; return(batchRegisterDeviceResponse); }
//批量注册设备,最多一次创建1000台设备,设备名称随机生成 public void TestBatchRegisterDevice() { DefaultAcsClient acsClient = Demo.IotClient.GetClient(); String productKey = "<productKey>"; BatchRegisterDeviceRequest request1 = new BatchRegisterDeviceRequest(); request1.ProductKey = productKey; request1.Count = 10; //Step1 创建申请单,返回applyId BatchRegisterDeviceResponse response1 = acsClient.GetAcsResponse(request1); Console.WriteLine("Batch Register: " + response1.Success); if (!(bool)response1.Success) { Console.WriteLine(response1.Code + ", " + response1.ErrorMessage); } long applyId = (long)response1.Data.ApplyId; Console.WriteLine("ApplyId: " + applyId); String Status = "CHECK_FAILED"; while (true) { //轮询申请单的检查进度,如果检查正常通过,则可以量产设备 QueryBatchRegisterDeviceStatusRequest request2 = new QueryBatchRegisterDeviceStatusRequest(); request2.ApplyId = applyId; request2.ProductKey = productKey; QueryBatchRegisterDeviceStatusResponse response2 = acsClient.GetAcsResponse(request2); if (!(bool)response2.Success) { Console.WriteLine(response2.Code + ", " + response2.ErrorMessage); break; } QueryBatchRegisterDeviceStatusResponse.QueryBatchRegisterDeviceStatus_Data data = response2.Data; Status = data.Status; Console.WriteLine("Query Status: " + response2.Success + ", " + Status); if ("CREATE_SUCCESS".Equals(Status)) { break; } else { Thread.Sleep(1000); } } if ("CREATE_SUCCESS".Equals(Status)) { QueryPageByApplyIdRequest request3 = new QueryPageByApplyIdRequest(); request3.ApplyId = applyId; request3.CurrentPage = 1; request3.PageSize = 10; QueryPageByApplyIdResponse response3 = acsClient.GetAcsResponse(request3); Console.WriteLine("Query With ApplyId: " + response3.Success); if (!(bool)response3.Success) { Console.WriteLine(response3.Code + ", " + response3.ErrorMessage); } Console.WriteLine("Page: " + response3.Page); Console.WriteLine("PageSize: " + response3.PageSize); Console.WriteLine("PageCount: " + response3.PageCount); Console.WriteLine("Total: " + response3.Total); } }