public void ProcessSystemAction(ISystemActionService actionService, string feedDirectory) { using (var db = _dbFactory.GetRWDb()) { var toProcessActions = actionService.GetUnprocessedByType(db, SystemActionType.ProcessUploadOrderFeed, null, null); foreach (var action in toProcessActions) { _log.Info("Find action: " + action.Id); var actionStatus = SystemActionStatus.None; var output = new PublishFeedOutput(); try { var inputData = SystemActionHelper.FromStr <PublishFeedInput>(action.InputData); var filepath = Path.Combine(feedDirectory, inputData.FileName); var uploadResult = UploadFeed(filepath, (MarketType)(inputData.Market ?? (int)MarketType.OfflineOrders), inputData.MarketplaceId, (PublishFeedModes)(inputData.Mode ?? (int)PublishFeedModes.Publish), inputData.IsPrime); output.ProgressPercent = 100; output.IsSuccess = true; if (uploadResult != null) { output.MatchedCount = uploadResult.MatchedCount; output.ParsedCount = uploadResult.ParsedCount; output.Processed1OperationCount = uploadResult.Processed1Count; output.Processed2OperationCount = uploadResult.Processed2Count; } actionStatus = SystemActionStatus.Done; _log.Info("Sale feed processed: " + filepath + ", actionId=" + action.Id); } catch (Exception ex) { actionStatus = SystemActionStatus.Fail; _log.Error("Fail quantity distributed, actionId=" + action.Id + ", status=" + actionStatus, ex); } actionService.SetResult(db, action.Id, actionStatus, output, null); } db.Commit(); } }
public virtual ActionResult GetFeed(long id) { LogI("GetLabelPrintFile, id=" + id); var uploadAction = Db.SystemActions.Get(id); if (uploadAction != null) { var inputModel = SystemActionHelper.FromStr <PublishFeedInput>(uploadAction.InputData); var filepath = Path.Combine(Models.UrlHelper.GetUploadOrderFeedPath(), inputModel.FileName); var filename = inputModel.FileName; return(File(filepath, FileHelper.GetMimeTypeByExt(Path.GetExtension(filepath)), filename)); } return(new HttpNotFoundResult()); }
public UploadOrderFeedViewModel(SystemActionDTO action) { Id = action.Id; Status = action.Status; var inputModel = SystemActionHelper.FromStr <PublishFeedInput>(action.InputData); var outputModel = SystemActionHelper.FromStr <PublishFeedOutput>(action.OutputData); FileName = inputModel.FileName; FieldMappingsId = inputModel.FieldMappingsId; ProgressPercent = outputModel?.ProgressPercent ?? 0; CreateDate = action.CreateDate; ParsedCount = outputModel?.ParsedCount; MatchedCount = outputModel?.MatchedCount; Valid1OperationCount = outputModel?.Valid1OperationCount; Valid2OperationCount = outputModel?.Valid2OperationCount; Processed1OperationCount = outputModel?.Processed1OperationCount; Processed2OperationCount = outputModel?.Processed2OperationCount; }
protected override void UpdateEntitiesAfterResponse(long feedId, IList <FeedResultMessage> errorList) { using (var db = DbFactory.GetRWDb()) { var groupId = feedId.ToString(); var groupActions = _actionService.GetByTypeAndGroupId(db, SystemActionType.UpdateOnMarketReturnOrder, groupId); foreach (var action in groupActions) { var input = SystemActionHelper.FromStr <ReturnOrderInput>(action.InputData); var output = SystemActionHelper.FromStr <ReturnOrderOutput>(action.OutputData); var error = errorList.FirstOrDefault(e => e.MessageId == output.Identifier); if (error == null) { output.IsProcessed = true; _actionService.SetResult(db, action.Id, SystemActionStatus.Done, output); } else { output.ResultMessage = error.ResultCode + ": " + error.MessageCode + ": " + error.Message; _actionService.SetResult(db, action.Id, SystemActionStatus.Fail, output); _emailService.SendSystemEmail( "System can't process refund, order #" + input.OrderNumber, "Details: " + output.ResultMessage, EmailHelper.RafiEmail + ";" + EmailHelper.RaananEmail, EmailHelper.SupportDgtexEmail); Log.Warn("Order not adjustment, orderId=" + input.OrderNumber); } } db.Commit(); } }
protected override void UpdateEntitiesAfterResponse(long feedId, IList <FeedResultMessage> errorList) { using (var db = DbFactory.GetRWDb()) { var groupId = feedId.ToString(); var groupActions = _actionService.GetByTypeAndGroupId(db, SystemActionType.UpdateOnMarketCancelOrder, groupId); foreach (var action in groupActions) { var input = SystemActionHelper.FromStr <CancelOrderInput>(action.InputData); var output = SystemActionHelper.FromStr <CancelOrderOutput>(action.OutputData); if (errorList.All(e => e.MessageId != output.Identifier)) { output.IsProcessed = true; _actionService.SetResult(db, action.Id, SystemActionStatus.Done, output); } else { if (action.AttemptNumber > 10) { _actionService.SetResult(db, action.Id, SystemActionStatus.Fail, output); } else { _actionService.SetResult(db, action.Id, SystemActionStatus.None, output); } Log.Warn("Order not acknowledgement, orderId=" + input.OrderNumber + ", attemptNumber=" + action.AttemptNumber); } } db.Commit(); } }
public void ProcessSystemAction(CancellationToken cancelToken) { var syncInfo = new EmptySyncInformer(_log, SyncType.Orders); using (var db = _dbFactory.GetRWDb()) { var updateRateActions = _actionService.GetUnprocessedByType(db, SystemActionType.UpdateRates, null, null); foreach (var action in updateRateActions) { if (cancelToken.IsCancellationRequested) { return; } var actionStatus = SystemActionStatus.None; try { var inputData = SystemActionHelper.FromStr <UpdateRatesInput>(action.InputData); var orderId = inputData.OrderId; if (!orderId.HasValue && !String.IsNullOrEmpty(inputData.OrderNumber)) { var order = db.Orders.GetByOrderNumber(inputData.OrderNumber); orderId = order.Id; } if (orderId.HasValue) { var orderIdList = new long[] { orderId.Value }; IList <DTOOrder> dtoOrders = db.ItemOrderMappings.GetSelectedOrdersWithItems(_weightService, orderIdList, includeSourceItems: true).ToList(); foreach (var dtoOrder in dtoOrders) { //Ignore shipped orders if ((dtoOrder.Market != (int)MarketType.eBay && ShippingUtils.IsOrderShipped(dtoOrder.OrderStatus)) || dtoOrder.ShippingInfos.Any(s => !String.IsNullOrEmpty(s.LabelPath)) || dtoOrder.BatchId.HasValue) //NOTE: SKip orders in batch { actionStatus = SystemActionStatus.Skipped; } else { var markets = new MarketplaceKeeper(_dbFactory, false); markets.Init(); var companyAddress = new CompanyAddressService(_company, markets.GetAll()); var synchronizer = new AmazonOrdersSynchronizer(_log, _company, syncInfo, _rateProviders, companyAddress, _time, _weightService, _messageService); if (!synchronizer.UIUpdate(db, dtoOrder, false, false, keepCustomShipping: false, switchToMethodId: null)) { actionStatus = SystemActionStatus.Fail; } else { actionStatus = SystemActionStatus.Done; } } } _log.Info("Order rates was recalculated, actionId=" + action.Id + ", status=" + actionStatus); } else { actionStatus = SystemActionStatus.NotFoundEntity; _log.Info("Can't find order, actionId=" + action.Id + ", orderId=" + inputData.OrderId + ", orderNumber=" + inputData.OrderNumber); } } catch (Exception ex) { _log.Error("Fail recalculate order rates action, actionId=" + action.Id, ex); actionStatus = SystemActionStatus.Fail; } _actionService.SetResult(db, action.Id, actionStatus, null, null); } db.Commit(); } }
protected override DocumentInfo ComposeDocument(IUnitOfWork db, long companyId, MarketType market, string marketplaceId, IList <string> asinList) { Dictionary <string, int> _quantityToSend = new Dictionary <string, int>(); Log.Info("Get listings for quantity update"); var requestInfoes = db.SystemActions.GetAllAsDto() .Where(a => a.Type == (int)SystemActionType.UpdateOnMarketProductQuantity && a.Status != (int)SystemActionStatus.Done) .ToList(); var requestedSKUs = requestInfoes.Select(i => i.Tag).ToList(); var dtoItems = (from i in db.Items.GetAllViewAsDto() where requestedSKUs.Contains(i.SKU) && i.PublishedStatus == (int)PublishedStatuses.Published && i.Market == (int)market && (String.IsNullOrEmpty(marketplaceId) || i.MarketplaceId == marketplaceId) select i).ToList(); foreach (var dtoItem in dtoItems) { var requestInfo = requestInfoes.FirstOrDefault(i => i.Tag == dtoItem.SKU); var info = SystemActionHelper.FromStr <UpdateQtyInput>(requestInfo.InputData); dtoItem.Id = (int)(requestInfo?.Id ?? 0); dtoItem.RealQuantity = info.NewQty; } _quantityToSend = new Dictionary <string, int>(); if (dtoItems.Any()) { var quantMessages = new List <XmlElement>(); var index = 0; foreach (var listing in dtoItems) { //Skip processing duplicate SKU if (_quantityToSend.ContainsKey(listing.SKU)) { continue; } index++; var quantity = listing.RealQuantity; Log.Info("add listing " + index + ", listingId=" + listing.Id + ", SKU=" + listing.SKU + ", quantity=" + quantity); quantMessages.Add(FeedHelper.ComposeInventoryMessage(index, listing.SKU, quantity, null, _fulfillmentLatency)); _quantityToSend.Add(listing.SKU, quantity); } Log.Info("Compose feed"); var merchant = db.Companies.Get(companyId).AmazonFeedMerchantIdentifier; var document = FeedHelper.ComposeFeed(quantMessages, merchant, Type.ToString()); return(new DocumentInfo { XmlDocument = document, NodesCount = index }); } return(null); }
public void ProcessSystemAction() { using (var db = _dbFactory.GetRWDb()) { var commentActions = _actionService.GetUnprocessedByType(db, SystemActionType.AddComment, null, null); foreach (var action in commentActions) { var actionStatus = SystemActionStatus.None; try { var inputData = SystemActionHelper.FromStr <AddCommentInput>(action.InputData); var orderId = inputData.OrderId; if (!orderId.HasValue && !String.IsNullOrEmpty(inputData.OrderNumber)) { var order = db.Orders.GetByCustomerOrderNumber(inputData.OrderNumber); if (order == null) { throw new ArgumentException("Can't find order", "OrderNumber"); } orderId = order.Id; } if (orderId.HasValue) { db.OrderComments.Add(new OrderComment() { OrderId = orderId.Value, Message = inputData.Message, Type = inputData.Type, LinkedEmailId = inputData.LinkedEmailId, CreateDate = _time.GetAppNowTime(), CreatedBy = inputData.By, }); db.Commit(); actionStatus = SystemActionStatus.Done; _log.Info("Comment was added, actionId=" + action.Id); } else { actionStatus = SystemActionStatus.NotFoundEntity; _log.Info("Can't find order, orderId=" + inputData.OrderId + ", orderNumber=" + inputData.OrderNumber); } } catch (Exception ex) { actionStatus = SystemActionStatus.Fail; if (action.CreateDate > _time.GetUtcTime().AddHours(-6)) { actionStatus = SystemActionStatus.None; } _log.Error("Fail add comment action, actionId=" + action.Id + ", status=" + actionStatus, ex); } _actionService.SetResult(db, action.Id, actionStatus, null, null); } db.Commit(); } }