Skip to content

Commit 3805fb1

Browse files
committed
Minor improvement
1 parent ca4fc51 commit 3805fb1

File tree

4 files changed

+57
-44
lines changed

4 files changed

+57
-44
lines changed

src/Libraries/SmartStore.Services/Catalog/Importer/CategoryImporter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ protected virtual int ProcessPictures(ImportExecuteContext context, IEnumerable<
199199
}
200200

201201
var image = CreateDownloadImage(context, imageUrl, 1);
202+
if (image == null)
203+
{
204+
continue;
205+
}
206+
202207
if (image.Url.HasValue() && !image.Success.HasValue)
203208
{
204209
AsyncRunner.RunSync(() => _fileDownloadManager.DownloadAsync(DownloaderContext, new FileDownloadManagerItem[] { image }));

src/Libraries/SmartStore.Services/Catalog/Importer/ProductImporter.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -886,20 +886,14 @@ protected virtual void ProcessProductPictures(ImportExecuteContext context, IEnu
886886
// Collect required image file infos.
887887
foreach (var urlOrPath in imageUrls)
888888
{
889-
try
889+
var image = CreateDownloadImage(context, urlOrPath, ++imageNumber);
890+
if (image != null)
890891
{
891-
var image = CreateDownloadImage(context, urlOrPath, ++imageNumber);
892+
imageFiles.Add(image);
892893

893-
if (image != null)
894-
imageFiles.Add(image);
895-
}
896-
catch
897-
{
898-
context.Result.AddWarning($"Failed to prepare image download for '{urlOrPath.NaIfEmpty()}'. Skipping file.", row.GetRowInfo(), "ImageUrls");
894+
if (imageFiles.Count >= numberOfPictures)
895+
break;
899896
}
900-
901-
if (imageFiles.Count >= numberOfPictures)
902-
break;
903897
}
904898

905899
// Download images.

src/Libraries/SmartStore.Services/Customers/Importer/CustomerImporter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ protected virtual int ProcessAvatars(
606606
}
607607

608608
var image = CreateDownloadImage(context, urlOrPath, 1);
609+
if (image == null)
610+
{
611+
continue;
612+
}
613+
609614
if (image.Url.HasValue() && !image.Success.HasValue)
610615
{
611616
AsyncRunner.RunSync(() => _fileDownloadManager.DownloadAsync(DownloaderContext, new FileDownloadManagerItem[] { image }));

src/Libraries/SmartStore.Services/DataExchange/Import/EntityImporterBase.cs

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,52 +91,61 @@ protected void Initialize(ImportExecuteContext context)
9191

9292
public FileDownloadManagerItem CreateDownloadImage(ImportExecuteContext context, string urlOrPath, int displayOrder)
9393
{
94-
var item = new FileDownloadManagerItem
94+
try
9595
{
96-
Id = displayOrder,
97-
DisplayOrder = displayOrder
98-
};
99-
100-
if (urlOrPath.IsWebUrl())
101-
{
102-
// We append quality to avoid importing of image duplicates.
103-
item.Url = context.Services.WebHelper.ModifyQueryString(urlOrPath, "q=100", null);
104-
105-
if (DownloadedItems.ContainsKey(urlOrPath))
96+
var item = new FileDownloadManagerItem
10697
{
107-
// URL has already been downloaded.
108-
item.Success = true;
109-
item.FileName = DownloadedItems[urlOrPath];
110-
}
111-
else
98+
Id = displayOrder,
99+
DisplayOrder = displayOrder
100+
};
101+
102+
if (urlOrPath.IsWebUrl())
112103
{
113-
var localPath = string.Empty;
104+
// We append quality to avoid importing of image duplicates.
105+
item.Url = context.Services.WebHelper.ModifyQueryString(urlOrPath, "q=100", null);
114106

115-
try
107+
if (DownloadedItems.ContainsKey(urlOrPath))
116108
{
117-
// Exclude query string parts!
118-
localPath = new Uri(urlOrPath).LocalPath;
109+
// URL has already been downloaded.
110+
item.Success = true;
111+
item.FileName = DownloadedItems[urlOrPath];
112+
}
113+
else
114+
{
115+
var localPath = string.Empty;
116+
117+
try
118+
{
119+
// Exclude query string parts!
120+
localPath = new Uri(urlOrPath).LocalPath;
121+
}
122+
catch { }
123+
124+
item.FileName = Path.GetFileName(localPath).ToValidFileName().NullEmpty() ?? Path.GetRandomFileName();
119125
}
120-
catch { }
121126

122-
item.FileName = Path.GetFileName(localPath).ToValidFileName().NullEmpty() ?? Path.GetRandomFileName();
127+
item.Path = Path.Combine(ImageDownloadFolder, item.FileName);
123128
}
129+
else
130+
{
131+
item.Success = true;
132+
item.FileName = Path.GetFileName(urlOrPath).ToValidFileName().NullEmpty() ?? Path.GetRandomFileName();
124133

125-
item.Path = Path.Combine(ImageDownloadFolder, item.FileName);
134+
item.Path = Path.IsPathRooted(urlOrPath)
135+
? urlOrPath
136+
: Path.Combine(ImageFolder, urlOrPath);
137+
}
138+
139+
item.MimeType = MimeTypes.MapNameToMimeType(item.FileName);
140+
141+
return item;
126142
}
127-
else
143+
catch
128144
{
129-
item.Success = true;
130-
item.FileName = Path.GetFileName(urlOrPath).ToValidFileName().NullEmpty() ?? Path.GetRandomFileName();
145+
context.Result.AddWarning($"Failed to prepare image download for '{urlOrPath.NaIfEmpty()}'. Skipping file.");
131146

132-
item.Path = Path.IsPathRooted(urlOrPath)
133-
? urlOrPath
134-
: Path.Combine(ImageFolder, urlOrPath);
147+
return null;
135148
}
136-
137-
item.MimeType = MimeTypes.MapNameToMimeType(item.FileName);
138-
139-
return item;
140149
}
141150

142151
public void Succeeded(FileDownloadManagerItem item)

0 commit comments

Comments
 (0)