private void PreDownloadItemImages(List<string> imageURLs, D_Item newItem) { #region Pre-Download and Save Images grouped by SKU DirectoryInfo di = new DirectoryInfo(@"C:\Users\gdutj\Downloads\3rdStockSystem\DSImages20200615\" + newItem.SKU + "\\"); if (!di.Exists) { di.Create(); } using (var wc = new ThirdStoreWebClient()) { int i = 1; foreach (var imageURL in imageURLs) { try { var imageFileName = newItem.SKU + "-" + i.ToString().PadLeft(2, '0') + ".jpg"; var saveImageFileFullName = Path.Combine(di.FullName, imageFileName); wc.DownloadFile(imageURL, saveImageFileFullName); } catch (Exception ex) { LogManager.Instance.Error(imageURL + " download failed. " + ex.Message); } i++; } } #endregion }
public IList <D_Item> GetDSData() { var retItems = new List <D_Item>(); try { IList <SelloDSModel> dsDatas = null; using (var webClient = new ThirdStoreWebClient()) { if (!Directory.Exists(this.DSDataPath)) { Directory.CreateDirectory(this.DSDataPath); } var fileName = this.DSDataPath + "\\" + CommonFunc.ToCSVFileName("SelloDSData"); webClient.DownloadFile(DSDataURL, fileName); dsDatas = _csvContext.Read <SelloDSModel>(fileName, _csvFileDescription).ToList(); if (dsDatas != null) { foreach (var dsData in dsDatas) { var newItem = new D_Item(); if (dsData.sku.Length > 23) { LogManager.Instance.Info($"SKU {dsData.sku} length is larger than 23."); } newItem.SKU = dsData.sku; newItem.Name = dsData.name; newItem.Description = dsData.description; newItem.Cost = dsData.special_price; newItem.Price = (newItem.Cost) * _commonSetting.DropshipMarkupRate; newItem.Type = ThirdStoreItemType.SINGLE.ToValue(); newItem.SupplierID = ThirdStoreSupplier.S.ToValue(); newItem.GrossWeight = (!string.IsNullOrWhiteSpace(dsData.weight) ? Convert.ToDecimal(dsData.weight) : 0); newItem.NetWeight = (!string.IsNullOrWhiteSpace(dsData.weight) ? Convert.ToDecimal(dsData.weight) : 0); newItem.Length = (!string.IsNullOrWhiteSpace(dsData.length) ? Convert.ToDecimal(dsData.length) / 100 : 0); newItem.Width = (!string.IsNullOrWhiteSpace(dsData.width) ? Convert.ToDecimal(dsData.width) / 100 : 0); newItem.Height = (!string.IsNullOrWhiteSpace(dsData.height) ? Convert.ToDecimal(dsData.height) / 100 : 0); newItem.Ref3 = dsData.UPC?.Trim(); newItem.IsReadyForList = (dsData.sku.Length <= 23 && dsData.special_price > Convert.ToDecimal(ThirdStoreConfig.Instance.SyncDSPriceAbove) ? true : false); newItem.IsActive = true; var imagesURL = GetImageURLList(dsData); if (imagesURL.Count > 0) { newItem.Ref5 = imagesURL.Aggregate((current, next) => current + ";" + next); } retItems.Add(newItem); } } } return(retItems); } catch (Exception ex) { LogManager.Instance.Error(ex.Message); throw ex; } }