增加try 防止崩溃
This commit is contained in:
1 parent
833c653d3e
commit
912d7f9ca3
1 file changed
+67
-53
@@ -41,37 +41,44 @@ public class ImageCacheService
|
|||||||
public static Dictionary<string, ImageCache> GetImageCaches(PDDProductInfo product)
|
public static Dictionary<string, ImageCache> GetImageCaches(PDDProductInfo product)
|
||||||
{
|
{
|
||||||
Dictionary<string, ImageCache> wxImgMapDic = new Dictionary<string, ImageCache>(StringComparer.OrdinalIgnoreCase);
|
Dictionary<string, ImageCache> wxImgMapDic = new Dictionary<string, ImageCache>(StringComparer.OrdinalIgnoreCase);
|
||||||
//if (EnvironmentHelper.IsProduction)
|
try
|
||||||
//{
|
|
||||||
// return wxImgMapDic;
|
|
||||||
//}
|
|
||||||
List<string> imageUrls = new List<string>();
|
|
||||||
imageUrls.AddRange(product.detail.galleries.Where(g => g.type == 1).Take(9).Select(a => a.url));
|
|
||||||
var temp_detailGalleries = product.detail.galleries.Where(g => g.type == 2).ToList();
|
|
||||||
if (temp_detailGalleries.Count == 0)
|
|
||||||
temp_detailGalleries.Add(new gallery_item() { type = 2, url = product.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
|
|
||||||
imageUrls.AddRange(temp_detailGalleries.Select(a => a.url));
|
|
||||||
|
|
||||||
|
|
||||||
if (product.detail.sku.FirstOrDefault()?.spec?.Count > 0)
|
|
||||||
{
|
{
|
||||||
imageUrls.AddRange(product.detail.sku.Select(a => a.thumb_url));
|
//if (EnvironmentHelper.IsProduction)
|
||||||
}
|
//{
|
||||||
|
// return wxImgMapDic;
|
||||||
|
//}
|
||||||
|
List<string> imageUrls = new List<string>();
|
||||||
|
imageUrls.AddRange(product.detail.galleries.Where(g => g.type == 1).Take(9).Select(a => a.url));
|
||||||
|
var temp_detailGalleries = product.detail.galleries.Where(g => g.type == 2).ToList();
|
||||||
|
if (temp_detailGalleries.Count == 0)
|
||||||
|
temp_detailGalleries.Add(new gallery_item() { type = 2, url = product.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
|
||||||
|
imageUrls.AddRange(temp_detailGalleries.Select(a => a.url));
|
||||||
|
|
||||||
|
|
||||||
|
if (product.detail.sku.FirstOrDefault()?.spec?.Count > 0)
|
||||||
List<string> imageUrlMd5s = imageUrls.Select(a => BaseClass.GetMd5(a)).ToList();
|
|
||||||
|
|
||||||
var url = ServerUrl + "/api/ImageCache/GetImageCache";//获取缓存
|
|
||||||
var html = GetHtml.PostJson(url, new { md5s = imageUrlMd5s });
|
|
||||||
var ret = JsonConvert.DeserializeObject<Result<List<ImageCache>>>(html);
|
|
||||||
if (ret.Code == 200)
|
|
||||||
{
|
|
||||||
foreach (var item in ret.Data)
|
|
||||||
{
|
{
|
||||||
item.IsCache = true;
|
imageUrls.AddRange(product.detail.sku.Select(a => a.thumb_url));
|
||||||
wxImgMapDic[item.Md5] = item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<string> imageUrlMd5s = imageUrls.Select(a => BaseClass.GetMd5(a)).ToList();
|
||||||
|
|
||||||
|
var url = ServerUrl + "/api/ImageCache/GetImageCache";//获取缓存
|
||||||
|
var html = GetHtml.PostJson(url, new { md5s = imageUrlMd5s });
|
||||||
|
var ret = JsonConvert.DeserializeObject<Result<List<ImageCache>>>(html);
|
||||||
|
if (ret.Code == 200)
|
||||||
|
{
|
||||||
|
foreach (var item in ret.Data)
|
||||||
|
{
|
||||||
|
item.IsCache = true;
|
||||||
|
wxImgMapDic[item.Md5] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
return wxImgMapDic;
|
return wxImgMapDic;
|
||||||
}
|
}
|
||||||
@@ -83,40 +90,47 @@ public class ImageCacheService
|
|||||||
/// <param name="images"></param>
|
/// <param name="images"></param>
|
||||||
public static void SaveImageCaches(PlatformType platform, IEnumerable<ImageCache> images)
|
public static void SaveImageCaches(PlatformType platform, IEnumerable<ImageCache> images)
|
||||||
{
|
{
|
||||||
//if (EnvironmentHelper.IsProduction)
|
try
|
||||||
//{
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
var data = "";
|
|
||||||
data = JsonHelper.SerializeObject(images.Where(a => a.IsCache == false).Select(a =>
|
|
||||||
new
|
|
||||||
{
|
|
||||||
md5 = a.Md5,
|
|
||||||
Platform = platform,
|
|
||||||
PlatformUrl = a.PlatformUrl
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
var url = ServerUrl + "/api/ImageCache/AddOrUpdate";
|
|
||||||
var html = GetHtml.PostJson(url, data);
|
|
||||||
|
|
||||||
|
|
||||||
var ret = JsonConvert.DeserializeObject<Result<JToken>>(html);
|
|
||||||
List<string> failed = new List<string>();
|
|
||||||
if (ret.Code == 500)
|
|
||||||
{
|
{
|
||||||
if (ret.Data is JArray jArray)
|
//if (EnvironmentHelper.IsProduction)
|
||||||
|
//{
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
var data = "";
|
||||||
|
data = JsonHelper.SerializeObject(images.Where(a => a.IsCache == false).Select(a =>
|
||||||
|
new
|
||||||
|
{
|
||||||
|
md5 = a.Md5,
|
||||||
|
Platform = platform,
|
||||||
|
PlatformUrl = a.PlatformUrl
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
var url = ServerUrl + "/api/ImageCache/AddOrUpdate";
|
||||||
|
var html = GetHtml.PostJson(url, data);
|
||||||
|
|
||||||
|
|
||||||
|
var ret = JsonConvert.DeserializeObject<Result<JToken>>(html);
|
||||||
|
List<string> failed = new List<string>();
|
||||||
|
if (ret.Code == 500)
|
||||||
{
|
{
|
||||||
failed = jArray.ToObject<List<string>>() ?? new List<string>();
|
if (ret.Data is JArray jArray)
|
||||||
|
{
|
||||||
|
failed = jArray.ToObject<List<string>>() ?? new List<string>();
|
||||||
|
}
|
||||||
|
else if (ret.Data is JValue jValue && jValue.Value is string str)
|
||||||
|
{
|
||||||
|
failed.Add(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (ret.Data is JValue jValue && jValue.Value is string str)
|
foreach (ImageCache item in images)
|
||||||
{
|
{
|
||||||
failed.Add(str);
|
item.IsCache = !failed.Contains(item.Md5, StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (ImageCache item in images)
|
catch
|
||||||
{
|
{
|
||||||
item.IsCache = !failed.Contains(item.Md5, StringComparer.OrdinalIgnoreCase);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user