public static List <Device> GetAllDevices() { int num = 0; int num2 = 50; DeviceSearchResultJson deviceSearchResultJson = ShakeAroundApi.SearchDeviceByRange(WXStoreHelper.siteSettings.WeixinAppId, num, num2, 10000); List <Device> devices = new List <Device>(); while (deviceSearchResultJson.data.devices.Count > 0) { deviceSearchResultJson.data.devices.ForEach(delegate(DeviceSearch_Data_Devices c) { devices.Add(c); }); num += num2; deviceSearchResultJson = ShakeAroundApi.SearchDeviceByRange(WXStoreHelper.siteSettings.WeixinAppId, num, num2, 10000); } return(devices); }
private YYDevice GetYYDevice(string token, int Times = 0) { //查询是否有申请未返回状态 YYApply YYApply = Entity.YYApply.FirstOrDefault(n => n.State == 1); if (YYApply == null) { string Reason = "新加商店设备"; DeviceApplyResultJson Device = WXAPI.DeviceApply(token, Reason); if (Device.errcode == ReturnCode.请求成功) { YYApply = new YYApply(); YYApply.AddTime = DateTime.Now; YYApply.Reason = Reason; YYApply.ApplyId = Device.data.apply_id.ToString(); YYApply.Num = 50; YYApply.State = 1; if (Device.data.audit_status == 0) { YYApply.State = 0; } Entity.YYApply.AddObject(YYApply); Entity.SaveChanges(); if (Device.data.audit_status == 2) { YYApply.State = 2; } } } if (YYApply.State == 1) { YYApply = GetYYApply(token, YYApply); } if (YYApply.State == 0) { if (Times < 5) { Thread.Sleep(5000); return(GetYYDevice(token, Times++)); } } if (YYApply.State == 2) { int ApplyId = Int32.Parse(YYApply.ApplyId); DeviceSearchResultJson Devices = WXAPI.SearchDeviceByApplyId(token, ApplyId); if (Devices.errcode == ReturnCode.请求成功) { List <DeviceSearch_Data_Devices> DeviceList = Devices.data.devices; foreach (var p in DeviceList) { var minor = p.minor.ToString(); var savedata = this.Entity.YYDevice.FirstOrDefault(o => o.Minor == minor); if (savedata == null) { //设备入库 YYDevice YY = new YYDevice(); YY.DevId = p.device_id.ToString(); YY.UUID = p.uuid; YY.Major = p.major.ToString(); YY.Minor = p.minor.ToString(); YY.UId = 0; YY.PageId = string.Empty; YY.AddTime = DateTime.Now; YY.ActState = 0; YY.State = 1; Entity.YYDevice.AddObject(YY); } } Entity.SaveChanges(); } } YYDevice YYDevice = Entity.YYDevice.FirstOrDefault(n => n.UId == 0 && n.State == 1); return(YYDevice); }