Exemplo n.º 1
0
        /// <summary>
        /// 创建批量任务
        /// </summary>
        public async Task <CreateBatchTaskResponse> CreateBatchTaskAsync(CreateBatchTaskRequest createBatchTaskRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/v5/iot/{project_id}/batchtasks", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json", createBatchTaskRequest);
            HttpResponseMessage response         = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <CreateBatchTaskResponse>(response));
        }
        private static void createBatchTask(IoTDAClient client)
        {
            CreateBatchTaskRequest req = new CreateBatchTaskRequest
            {
                InstanceId = "1a7ffc5c-d89c-44dd-8265-b1653d951ce0",
                Body       = new CreateBatchTask()
                {
                    Document = new Hashtable()
                    {
                        { "package_id", "24381244be486f8b3a89ad07" }
                    },
                    Targets = new List <String>()
                    {
                        "5e19ca2b16b09003ca4dbd98_ggghg"
                    },
                    TaskName = "BatchCommandTask_test1",
                    TaskType = "softwareUpgrade",
                    AppId    = "vWT2abBX135ioL_D028b7NRYJfYa"
                }
            };

            try
            {
                var resp = client.CreateBatchTask(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);
            }
        }