Exemplo n.º 1
0
        //查询批量申请设备的处理结果是否完成
        public void TestQueryApplyStatus()
        {
            DefaultAcsClient acsClient = Demo.IotClient.GetClient();

            QueryBatchRegisterDeviceStatusRequest request = new QueryBatchRegisterDeviceStatusRequest();

            //ApplyId来源于ApplyDeviceWithNamesResponse
            request.ApplyId = 11191;

            QueryBatchRegisterDeviceStatusResponse response = acsClient.GetAcsResponse(request);

            Console.WriteLine(response.Success);
            Console.WriteLine(response.ErrorMessage);
            Console.WriteLine("Apply to create device is finish: " + response.Data.Status);
        }
Exemplo n.º 2
0
        //批量注册设备,最多一次创建1000台设备,指定设备名称
        public void TestBatchRegisterDeviceWithNames()
        {
            DefaultAcsClient acsClient = Demo.IotClient.GetClient();

            String productKey = "<productKey>";
            BatchCheckDeviceNamesRequest request1 = new BatchCheckDeviceNamesRequest();

            request1.ProductKey = productKey;

            List <string> DeviceNames = new List <string>();

            for (int i = 100; i < 150; i += 1)
            {
                DeviceNames.Add("device_0821_" + i);
            }
            request1.DeviceNames = DeviceNames;

            //Step1 创建申请单,返回applyId
            BatchCheckDeviceNamesResponse response1 = acsClient.GetAcsResponse(request1);

            Console.WriteLine("Batch Check: " + response1.Success);
            if (!(bool)response1.Success)
            {
                Console.WriteLine(response1.Code + ", " + response1.ErrorMessage);
            }
            long applyId = (long)response1.Data.ApplyId;

            Console.WriteLine("ApplyId: " + applyId);

            String Status = "FAILED";

            while (true)
            {
                //Step2 轮询申请单的检查进度,如果检查正常通过,则可以量产设备
                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 ("CHECK_SUCCESS".Equals(Status))
                {
                    break;
                }
                else
                {
                    if ("CHECK_FAILED".Equals(Status))
                    {
                        List <string> InvalidDevicenameList = response2.Data.InvalidList;
                        for (int j = 0; j < InvalidDevicenameList.Count; j += 1)
                        {
                            String deviceName = InvalidDevicenameList[j];
                            Console.WriteLine("Invalid DeviceName: " + deviceName);
                        }
                        break;
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
            }

            if ("CHECK_SUCCESS".Equals(Status))
            {
                //Step3 开始量产设备,量产设备是异步过程,全部待生产设备完成生产需要一段时间
                BatchRegisterDeviceWithApplyIdRequest request3 = new BatchRegisterDeviceWithApplyIdRequest();
                request3.ProductKey = productKey;
                request3.ApplyId    = applyId;

                BatchRegisterDeviceWithApplyIdResponse response3 = acsClient.GetAcsResponse(request3);
                Console.WriteLine("Batch Register With ApplyId Request: " + response3.Success);
                if (!(bool)response3.Success)
                {
                    Console.WriteLine(response3.Code + ", " + response3.ErrorMessage);
                }
            }

            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);
                }
            }

            //Step5 根据ApplyId,获取这一批次量产的全部设备
            QueryPageByApplyIdRequest request4 = new QueryPageByApplyIdRequest();

            request4.ApplyId     = applyId;
            request4.CurrentPage = 1;
            request4.PageSize    = 10;

            QueryPageByApplyIdResponse response4 = acsClient.GetAcsResponse(request4);

            Console.WriteLine("Query With ApplyId: " + response4.Success);
            if (!(bool)response4.Success)
            {
                Console.WriteLine(response4.Code + ", " + response4.ErrorMessage);
            }
            Console.WriteLine("Page: " + response4.Page);
            Console.WriteLine("PageSize: " + response4.PageSize);
            Console.WriteLine("PageCount: " + response4.PageCount);
            Console.WriteLine("Total: " + response4.Total);
        }
Exemplo n.º 3
0
        //批量注册设备,最多一次创建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);
            }
        }