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> parts = new List>(); parts.Add(new KeyValuePair("DAY", "89310")); parts.Add(new KeyValuePair("CNI", "141.40113")); parts.Add(new KeyValuePair("PRF", "MU19631")); parts.Add(new KeyValuePair("TRK", "SB8100")); parts.Add(new KeyValuePair("MON", "906970")); parts.Add(new KeyValuePair("FEL", "70804")); parts.Add(new KeyValuePair("FEL", "SS71198")); parts.Add(new KeyValuePair("CFP", "STS314")); parts.Add(new KeyValuePair("NGK", "21517")); parts.Add(new KeyValuePair("NGK", "RC-XX89")); parts.Add(new KeyValuePair("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 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(dataSearch); if (response.ResponseBody.Item?.Length > 0) { List urls = new List(); 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}"); } } } } } } } } }