/// <summary> /// Retrieves order for export and calls the IExportOrderService for each one /// </summary> /// <returns>A status message to be stored in the database log and visible from admin mode</returns> public override string Execute() { PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("admin"); //Call OnStatusChanged to periodically notify progress of job for manually started jobs OnStatusChanged("Starting looking for orders to export."); Stopwatch tmr = Stopwatch.StartNew(); List <ExportOrderInformation> results = new List <ExportOrderInformation>(); List <PurchaseOrder> orders = GetOrdersToExport(); tmr.Stop(); _log.Debug("Found {0} orders to export in {1}ms", orders.Count, tmr.ElapsedMilliseconds); if (_stopSignaled) { return("Job was stopped"); } IExportOrderService service = ServiceLocator.Current.GetInstance <IExportOrderService>(); foreach (PurchaseOrder purchaseOrder in orders) { if (_stopSignaled) { return("Job was stopped"); } OnStatusChanged(string.Format("Exporting order: {0}", purchaseOrder.TrackingNumber)); results.Add(ExportOrder(purchaseOrder, service)); } return(string.Format("Exported {0} orders", results.Count)); }
private ExportOrderInformation ExportOrder(PurchaseOrder purchaseOrder, IExportOrderService service) { // Export to back-end system, and retrieves an external id that is stored on the order string externalOrderNumber = service.ExportOrder(purchaseOrder); _log.Debug("Exported {0} to external system, got {1} back", purchaseOrder.TrackingNumber, externalOrderNumber); // TODO: This design could be better // It might take days to get a status update from a backend system. We // cannot export the same order many times, that would be a problem. // Instead, we should add a flag to indicate the order has been exported, // save it on order and reserve the BackendOrderNumber field to the // actual order id in the back-end. This will allow us to track that // an order has been exported, but not completed yet. // We could also use a custom Order Status for this ExportOrderInformation result = new ExportOrderInformation { ExternalOrderId = externalOrderNumber, PurchaseOrderNumber = purchaseOrder.TrackingNumber }; return(result); }
private ExportOrderInformation ExportOrder(PurchaseOrder purchaseOrder, IExportOrderService service) { // Export to back-end system, and retrieves an external id that is stored on the order string externalOrderNumber = service.ExportOrder(purchaseOrder); _log.Debug("Exported {0} to external system, got {1} back", purchaseOrder.TrackingNumber, externalOrderNumber); // TODO: This design could be better // It might take days to get a status update from a backend system. We // cannot export the same order many times, that would be a problem. // Instead, we should add a flag to indicate the order has been exported, // save it on order and reserve the BackendOrderNumber field to the // actual order id in the back-end. This will allow us to track that // an order has been exported, but not completed yet. // We could also use a custom Order Status for this ExportOrderInformation result = new ExportOrderInformation { ExternalOrderId = externalOrderNumber, PurchaseOrderNumber = purchaseOrder.TrackingNumber }; return result; }