您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

106 行
4.2 KiB

  1. using DataVAPI.ModelDataBus;
  2. using DataVAPI.Tool.IOT;
  3. using System.Collections.Generic;
  4. using Tea;
  5. using static AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileResponseBody;
  6. namespace DataVAPI.UpAndDown
  7. {
  8. public class Sample
  9. {
  10. /**
  11. * 使用AK&SK初始化账号Client
  12. * @param accessKeyId
  13. * @param accessKeySecret
  14. * @return Client
  15. * @throws Exception
  16. */
  17. public static AlibabaCloud.SDK.Iot20180120.Client CreateClient(string accessKeyId, string accessKeySecret)
  18. {
  19. AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
  20. {
  21. // 您的AccessKey ID
  22. AccessKeyId = accessKeyId,
  23. // 您的AccessKey Secret
  24. AccessKeySecret = accessKeySecret,
  25. };
  26. // 访问的域名
  27. config.Endpoint = "iot.cn-shanghai.aliyuncs.com";
  28. return new AlibabaCloud.SDK.Iot20180120.Client(config);
  29. }
  30. public static List<QueryDeviceFileResponseBodyData> FileQueryALL(string DeviceName)
  31. {
  32. List<QueryDeviceFileResponseBodyData> retdata=new List<QueryDeviceFileResponseBodyData>();
  33. AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi");
  34. AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListRequest queryDeviceFileListRequest = new AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListRequest
  35. {
  36. IotInstanceId = "iot-06z00g9pf3kwtxp",
  37. ProductKey = DataBus.ProductKey,
  38. DeviceName = DeviceName,
  39. };
  40. AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
  41. AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileListResponse resp = client.QueryDeviceFileListWithOptions(queryDeviceFileListRequest, runtime);
  42. //AlibabaCloud.TeaConsole.Client.Log();
  43. //;
  44. AlibabaCloudRes cloudRes= Tools.JsonToObjectTools<AlibabaCloudRes>(AlibabaCloud.TeaUtil.Common.ToJSONString(resp.ToMap()));
  45. cloudRes?.body?.Data?.FileSummary?.ForEach(fileSummary =>
  46. {
  47. QueryDeviceFileResponseBodyData _data= FileQuery(DeviceName,fileSummary.FileId);
  48. if (_data != null)
  49. {
  50. retdata.Add(_data);
  51. }
  52. });
  53. return retdata;
  54. }
  55. public static QueryDeviceFileResponseBodyData FileQuery(string DeviceName,string FileId)
  56. {
  57. AlibabaCloud.SDK.Iot20180120.Client client = CreateClient("LTAI5tDbUDuCvqU5hP8ZpHHV", "SvNIRQuz3BQFEaC3PFSJdgpeOKWFRi");
  58. AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileRequest queryDeviceFileRequest = new AlibabaCloud.SDK.Iot20180120.Models.QueryDeviceFileRequest
  59. {
  60. IotInstanceId = "iot-06z00g9pf3kwtxp",
  61. DeviceName = DeviceName,
  62. ProductKey = DataBus.ProductKey,
  63. FileId = FileId,
  64. };
  65. AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
  66. // 复制代码运行请自行打印 API 的返回值
  67. QueryDeviceFileResponseBodyData queryDeviceFile= client.QueryDeviceFileWithOptions(queryDeviceFileRequest, runtime).Body.Data;
  68. return queryDeviceFile;
  69. }
  70. }
  71. public class AlibabaCloudRes
  72. {
  73. public object headers { get; set; }
  74. public StrRes body { get; set; }
  75. }
  76. public class StrRes
  77. {
  78. public string code { get; set; }
  79. public string CurrentPage { get; set; }
  80. public ResData Data { get; set; }
  81. public string ErrorMessage { get; set; }
  82. public int PageCount { get; set; }
  83. public int PageSize { get; set; }
  84. public string RequestId { get; set; }
  85. public bool Success { get; set; }
  86. public int Total { get; set; }
  87. }
  88. public class ResData
  89. {
  90. public List<summary> FileSummary { get; set; }
  91. }
  92. public class summary
  93. {
  94. public string UtcCreatedOn { get; set; }
  95. public string Size { get; set; }
  96. public string FileId { get; set; }
  97. public string Name { get; set; }
  98. }
  99. }