private void ProcessReport(ISettingsService settings) { _syncInfo.AddSuccess("", "Report was successfully saved"); LogWrite("Process report"); _reportService.ProcessReport(); _syncInfo.SyncEnd(); }
public void ProcessExistingParents(IUnitOfWork db, IMarketApi api, ISyncInformer syncInfo, IList <string> parentASINs, IList <ItemDTO> items) { var parentASINsWithError = new List <string>(); _log.Debug("Begin process existing parents, count=" + parentASINs.Count); var parentsDto = api.GetItems(_log, _time, MarketItemFilters.Build(parentASINs), ItemFillMode.NoAdv, out parentASINsWithError).ToList(); _log.Debug("Error when GetItems, parentASINS: " + String.Join(", ", parentASINsWithError)); //Only update fields foreach (var parent in parentsDto) { //NOTE: in case when parent item has "no-img" using child image if (String.IsNullOrEmpty(parent.ImageSource)) { var childImage = items.FirstOrDefault(i => i.ParentASIN == parent.ASIN && !String.IsNullOrEmpty(i.ImageUrl)); if (childImage != null) { parent.ImageSource = childImage.ImageUrl; } } var dbParent = db.ParentItems.CreateOrUpdateParent(parent, api.Market, api.MarketplaceId, _time.GetAppNowTime()); _log.Warn("Parent item was updated, ParentASIN=" + parent.ASIN); syncInfo.AddSuccess(parent.ASIN, "Parent item was updated"); } _log.Debug("End process existing parents"); }
public void ProcessNewListingsWithItems(IUnitOfWork db, IMarketApi api, ITime time, IList <ItemDTO> items) { _log.Debug("Begin process new items"); foreach (var dtoItem in items) { try { if (dtoItem.IsExistOnAmazon == true) { _syncInfo.AddSuccess(dtoItem.ASIN, "New listing item was filled by Amazon"); if (String.IsNullOrEmpty(dtoItem.ParentASIN)) { _syncInfo.AddWarning(dtoItem.ASIN, "Empty ParentASIN"); } dtoItem.IsAmazonParentASIN = !String.IsNullOrEmpty(dtoItem.ParentASIN); dtoItem.LastUpdateFromAmazon = time.GetUtcTime(); //Add new item, no need to additional check dtoItem.StyleString = SkuHelper.RetrieveStyleIdFromSKU(db, dtoItem.SKU, dtoItem.Name); var dbItem = db.Items.StoreItemIfNotExist(_itemHistoryService, "ListingLineProcessing", dtoItem, api.Market, api.MarketplaceId, _companyId, time.GetAppNowTime()); //NOTE: fresh size (for some reason can start came emtpy) dtoItem.Size = dbItem.Size; if (!dbItem.StyleItemId.HasValue) { //Keep exists styleId dtoItem.StyleId = dbItem.StyleId; var styleItem = FindOrCreateStyleItem(db, dtoItem); if (styleItem != null) { if (styleItem.StyleItemId > 0) { dbItem.StyleId = styleItem.StyleId; dbItem.StyleItemId = styleItem.StyleItemId; } else { if (!dbItem.StyleId.HasValue) { dbItem.StyleId = styleItem.StyleId; } } _log.Debug(String.Format("Set for ASIN={0}, styleId={1}, styleItemId={2}", dtoItem.ASIN, styleItem.StyleId, styleItem.StyleItemId)); } db.Commit(); } if (!String.IsNullOrEmpty(dtoItem.Barcode) && dbItem.StyleItemId.HasValue) { _styleManager.StoreOrUpdateBarcode(db, dbItem.StyleItemId.Value, dtoItem.Barcode); } var dbListing = db.Listings.StoreOrUpdate(dtoItem, dbItem, api.Market, api.MarketplaceId, time.GetAppNowTime()); dtoItem.IsDefault = dbListing.IsDefault; _syncInfo.AddSuccess(dtoItem.ASIN, "New listing item was stored"); _log.Debug("Store item:" + dbItem.ASIN + ", parentASIN=" + dbItem.ParentASIN + ", SKU=" + dtoItem.SKU + ", StyleString=" + dbItem.StyleString + ", quantity=" + dtoItem.RealQuantity); } else { _syncInfo.AddWarning(dtoItem.ASIN, "Item is not filled by Amazon (new listing item)"); _log.Warn("Item is not filled by Amazon (new listing item), item=" + dtoItem.ASIN); } } catch (Exception ex) { _syncInfo.AddError(dtoItem.ASIN, "Error while creating item", ex); _log.Error(string.Format("Error while creating item, asin={0}", dtoItem.ASIN), ex); } } _log.Debug("End process new items"); }