.
This commit is contained in:
106
PartSource.Automation/Jobs/POC/GetImageUrlsTemp.cs
Normal file
106
PartSource.Automation/Jobs/POC/GetImageUrlsTemp.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
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 GetImageUrlsTemp : IAutomationJob
|
||||
{
|
||||
private readonly NexpartService _nexpartService;
|
||||
private readonly FitmentContext _fitmentContext;
|
||||
private readonly PartService _partService;
|
||||
private readonly ShopifyClient _shopifyClient;
|
||||
|
||||
private readonly string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
public GetImageUrlsTemp(NexpartService nexpartService, PartService partService, FitmentContext fitmentContext, ShopifyClient shopifyClient)
|
||||
{
|
||||
_nexpartService = nexpartService;
|
||||
_fitmentContext = fitmentContext;
|
||||
_partService = partService;
|
||||
_shopifyClient = shopifyClient;
|
||||
}
|
||||
|
||||
public async Task Run(CancellationToken token, params string[] arguments)
|
||||
{
|
||||
IList<KeyValuePair<string, string>> parts = new List<KeyValuePair<string, string>>();
|
||||
parts.Add(new KeyValuePair<string, string>("DAY", "89310"));
|
||||
parts.Add(new KeyValuePair<string, string>("CNI", "141.40113"));
|
||||
parts.Add(new KeyValuePair<string, string>("PRF", "MU19631"));
|
||||
parts.Add(new KeyValuePair<string, string>("TRK", "SB8100"));
|
||||
parts.Add(new KeyValuePair<string, string>("MON", "906970"));
|
||||
parts.Add(new KeyValuePair<string, string>("FEL", "70804"));
|
||||
parts.Add(new KeyValuePair<string, string>("FEL", "SS71198"));
|
||||
parts.Add(new KeyValuePair<string, string>("CFP", "STS314"));
|
||||
parts.Add(new KeyValuePair<string, string>("NGK", "21517"));
|
||||
parts.Add(new KeyValuePair<string, string>("NGK", "RC-XX89"));
|
||||
parts.Add(new KeyValuePair<string, string>("FRA", "CA176"));
|
||||
|
||||
for (int i = 0; i < chars.Length; i++)
|
||||
{
|
||||
for (int j = 0; j < chars.Length; j++)
|
||||
{
|
||||
for (int k = 0; k < chars.Length; k++)
|
||||
{
|
||||
string actualLineCode = $"{chars[i]}{chars[j]}{chars[k]}";
|
||||
System.Diagnostics.Debug.WriteLine(actualLineCode);
|
||||
|
||||
foreach (KeyValuePair<string, string> part in parts)
|
||||
{
|
||||
|
||||
|
||||
SmartPageDataSearch dataSearch = new SmartPageDataSearch
|
||||
{
|
||||
Items = new Item[]
|
||||
{
|
||||
new Item
|
||||
{
|
||||
MfrCode = actualLineCode,
|
||||
PartNumber = part.Value
|
||||
}
|
||||
},
|
||||
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)
|
||||
{
|
||||
Console.WriteLine($"Image {urls[0]} found for {part.Value}. Expected: {part.Key}, Actual: {actualLineCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user