84 lines
2.9 KiB
C#
84 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using PartSource.Data.Contexts;
|
|
using PartSource.Data.Models;
|
|
using PartSource.Data.Nexpart;
|
|
using PartSource.Services;
|
|
using Ratermania.Automation.Interfaces;
|
|
using Ratermania.Shopify;
|
|
using Ratermania.Shopify.Resources;
|
|
|
|
namespace PartSource.Automation.Jobs.POC
|
|
{
|
|
public class GetImageUrls : IAutomationJob
|
|
{
|
|
private readonly NexpartService _nexpartService;
|
|
private readonly PartSourceContext _partSourceContext;
|
|
|
|
public GetImageUrls(NexpartService nexpartService, PartSourceContext partSourceContext)
|
|
{
|
|
_nexpartService = nexpartService;
|
|
_partSourceContext = partSourceContext;
|
|
}
|
|
|
|
public async Task Run(CancellationToken token, params string[] arguments)
|
|
{
|
|
IList<string> rows = new List<string> {
|
|
"\"Line Code\", \"Part Number\", \"Image URL(s)\""
|
|
};
|
|
|
|
IList<ImportData> importData = await _partSourceContext.ImportData
|
|
//.Take(5000)
|
|
.ToListAsync();
|
|
|
|
foreach (ImportData item in importData)
|
|
{
|
|
SmartPageDataSearch dataSearch = new SmartPageDataSearch
|
|
{
|
|
Items = new Item[]
|
|
{
|
|
new Item
|
|
{
|
|
MfrCode = item.LineCode,
|
|
PartNumber = item.PartNumber
|
|
}
|
|
},
|
|
DataOption = new[] { "DIST_LINE", "ALL" }
|
|
};
|
|
|
|
SmartPageDataSearchResponse response = await _nexpartService.SendRequest<SmartPageDataSearch, SmartPageDataSearchResponse>(dataSearch);
|
|
|
|
if (response.ResponseBody.Item?.Length > 0)
|
|
{
|
|
List<string> urls = new List<string>();
|
|
|
|
if (!string.IsNullOrEmpty(response.ResponseBody.Item[0].PrimaryImg?.ImgUrl))
|
|
{
|
|
urls.Add(response.ResponseBody.Item[0].PrimaryImg?.ImgUrl);
|
|
};
|
|
|
|
if (response.ResponseBody.Item[0].AddImgs?.AddImg?.Length > 0)
|
|
{
|
|
urls.AddRange(response.ResponseBody.Item[0].AddImgs.AddImg.Select(i => i.AddImgUrl));
|
|
}
|
|
|
|
if (urls.Count > 0)
|
|
{
|
|
rows.Add($"\"{item.LineCode}\", \"{item.PartNumber}\", \"{string.Join(";", urls)}\"");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
await File.WriteAllLinesAsync("C:\\users\\Tommy\\desktop\\WHI Images.csv", rows);
|
|
}
|
|
}
|
|
} |