public void ReProcessTrackNotifications(IDbFactory dbFactory) { var from = _time.GetAppNowTime().AddDays(-42); //NOTE: Possible/not sure: After 42 days USPS not update/keep info var orderFrom = _time.GetAppNowTime().AddDays(-90); using (var db = dbFactory.GetRWDb()) { var shippings = db.Orders.GetUnDeliveredShippingInfoes(_time.GetUtcTime(), false, null) .Where(o => (!o.TrackingStateDate.HasValue || o.TrackingStateDate.Value > from) && o.OrderDate > orderFrom) .OrderBy(o => o.OrderDate) .ToList(); shippings.AddRange(db.Orders.GetUnDeliveredMailInfoes(_time.GetUtcTime(), false, null) .Where(o => (!o.TrackingStateDate.HasValue || o.TrackingStateDate.Value > from) && o.OrderDate > orderFrom) .OrderBy(o => o.OrderDate) .ToList()); var actionService = new SystemActionService(_log, _time); var companyAddress = new CompanyAddressService(_company); var addressService = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty())); var notificationService = new NotificationService(_log, _time, dbFactory); var ruleList = new List <ITrackingRule>() { //new NeverShippedTrackingRule(_log, notificationService, _time), //new GetStuckTrackingRule(_log, notificationService, _time), //new NoticeLeftTrackingRule(actionService, _log) }; var trackingService = new TrackingManager(_log, actionService, addressService, _emailService, _time, ruleList); foreach (var shipping in shippings) { trackingService.CheckRules(db, shipping, shipping.TrackingStateEvent, shipping.TrackingStateDate, new List <TrackingRecord>() { new TrackingRecord() { Date = shipping.TrackingStateDate, Message = shipping.TrackingStateEvent, } }, ruleList); } } }