|
|
|
@ -255,6 +255,11 @@ namespace SparkClient.Model.Services |
|
|
|
int imageTotal = ConfigurationHelper.ReadConfigValueToInteger("DetectImageTotal", 100); |
|
|
|
int imageTotal = ConfigurationHelper.ReadConfigValueToInteger("DetectImageTotal", 100); |
|
|
|
while (true) |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (imageIndex >= imageTotal) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return imageNames; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string url = $"{_baseUrl}/retrieve_image/{imageIndex}"; |
|
|
|
string url = $"{_baseUrl}/retrieve_image/{imageIndex}"; |
|
|
|
string sendCode = url.GenerateSign(); |
|
|
|
string sendCode = url.GenerateSign(); |
|
|
|
try |
|
|
|
try |
|
|
|
@ -290,7 +295,7 @@ namespace SparkClient.Model.Services |
|
|
|
|
|
|
|
|
|
|
|
case 404: |
|
|
|
case 404: |
|
|
|
// 资源未找到,结束循环 |
|
|
|
// 资源未找到,结束循环 |
|
|
|
Logger.Info($"[SendCode={sendCode}] Image Not Found]"); |
|
|
|
Logger.Info($"[SendCode={sendCode}] Image Not Found."); |
|
|
|
break; |
|
|
|
break; |
|
|
|
// return imageNames; |
|
|
|
// return imageNames; |
|
|
|
default: |
|
|
|
default: |
|
|
|
@ -370,45 +375,45 @@ namespace SparkClient.Model.Services |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 启动任务接口 |
|
|
|
// 启动任务接口 |
|
|
|
// SocResultEntity entity = await CollectImagesAsync(); |
|
|
|
SocResultEntity entity = await CollectImagesAsync(); |
|
|
|
//成功 |
|
|
|
//成功 |
|
|
|
// Logger.Debug($"entity :{entity.Status} {entity.ToString()} "); |
|
|
|
Logger.Debug($"entity :{entity.Status} {entity.ToString()} "); |
|
|
|
// if (entity.Status != StatusCodes.Success) |
|
|
|
if (entity.Status != StatusCodes.Success) |
|
|
|
// { |
|
|
|
|
|
|
|
// // 启动任务失败 |
|
|
|
|
|
|
|
// return new SocResultEntity { Status = entity.Status, Images = new List<string>() }; |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 读取图片接口 |
|
|
|
|
|
|
|
// List<string> imageNames = await RetrieveImageAsync(savePath); |
|
|
|
|
|
|
|
var cts = new CancellationTokenSource(); |
|
|
|
|
|
|
|
Task<HttpSendResult> startImage = CollectImagesAsyncNotAwait(); |
|
|
|
|
|
|
|
Task<List<string>> downloadImage = RetrieveImageAsync(savePath, cts.Token); |
|
|
|
|
|
|
|
await startImage; |
|
|
|
|
|
|
|
var entity = startImage.Result; |
|
|
|
|
|
|
|
if (entity.StatusCode != 200) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//downloadImage怎么取消并终止 |
|
|
|
|
|
|
|
cts.Cancel(); |
|
|
|
|
|
|
|
return new SocResultEntity { Status = StatusCodes.DeviceNotFound, Images = new List<string>() }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (entity.Content == null) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
//downloadImage怎么取消并终止 |
|
|
|
// 启动任务失败 |
|
|
|
cts.Cancel(); |
|
|
|
return new SocResultEntity { Status = entity.Status, Images = new List<string>() }; |
|
|
|
return new SocResultEntity { Status = StatusCodes.DeviceNotFound, Images = new List<string>() }; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<string> imageNames = await RetrieveImageAsync(savePath); |
|
|
|
|
|
|
|
// 读取图片接口 |
|
|
|
|
|
|
|
|
|
|
|
List<string> imageNames = new List<string>(); |
|
|
|
// var cts = new CancellationTokenSource(); |
|
|
|
try |
|
|
|
// Task<HttpSendResult> startImage = CollectImagesAsyncNotAwait(); |
|
|
|
{ |
|
|
|
// Task<List<string>> downloadImage = RetrieveImageAsync(savePath, cts.Token); |
|
|
|
await downloadImage; |
|
|
|
// await startImage; |
|
|
|
imageNames = downloadImage.Result; |
|
|
|
// var entity = startImage.Result; |
|
|
|
} |
|
|
|
// if (entity.StatusCode != 200) |
|
|
|
catch (Exception e) |
|
|
|
// { |
|
|
|
{ |
|
|
|
// //downloadImage怎么取消并终止 |
|
|
|
Logger.Error($"Error in Await downloadImage: {e.Message}"); |
|
|
|
// cts.Cancel(); |
|
|
|
} |
|
|
|
// return new SocResultEntity { Status = StatusCodes.DeviceNotFound, Images = new List<string>() }; |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// if (entity.Content == null) |
|
|
|
|
|
|
|
// { |
|
|
|
|
|
|
|
// //downloadImage怎么取消并终止 |
|
|
|
|
|
|
|
// cts.Cancel(); |
|
|
|
|
|
|
|
// return new SocResultEntity { Status = StatusCodes.DeviceNotFound, Images = new List<string>() }; |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// List<string> imageNames = new List<string>(); |
|
|
|
|
|
|
|
// try |
|
|
|
|
|
|
|
// { |
|
|
|
|
|
|
|
// await downloadImage; |
|
|
|
|
|
|
|
// imageNames = downloadImage.Result; |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// catch (Exception e) |
|
|
|
|
|
|
|
// { |
|
|
|
|
|
|
|
// Logger.Error($"Error in Await downloadImage: {e.Message}"); |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 采集状态接口 |
|
|
|
// 采集状态接口 |
|
|
|
string acquisitionStatus = await CollectStatusAsync(); |
|
|
|
string acquisitionStatus = await CollectStatusAsync(); |
|
|
|
@ -425,7 +430,7 @@ namespace SparkClient.Model.Services |
|
|
|
// 图片文件读取失败 |
|
|
|
// 图片文件读取失败 |
|
|
|
return new SocResultEntity { Status = StatusCodes.ImageFileReadFailure, Images = new List<string>() }; |
|
|
|
return new SocResultEntity { Status = StatusCodes.ImageFileReadFailure, Images = new List<string>() }; |
|
|
|
} |
|
|
|
} |
|
|
|
return new SocResultEntity { Status = acquisitionStatus, Images = imageNames, DeviceId = entity.Content.device_id}; |
|
|
|
return new SocResultEntity { Status = "S000", Images = imageNames, DeviceId = entity.DeviceId}; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|