Exemplo n.º 1
0
        public CallEBayProcessing(ILogService log,
                                  ITime time,
                                  ICacheService cacheService,
                                  IDbFactory dbFactory,
                                  IStyleManager styleManager,
                                  eBayApi eBayApi,
                                  IEmailService emailService,
                                  CompanyDTO company)
        {
            _log                                 = log;
            _time                                = time;
            _dbFactory                           = dbFactory;
            _cacheService                        = cacheService;
            _styleManager                        = styleManager;
            _descriptionTemplatePath             = Path.Combine(AppSettings.TemplateDirectory, TemplateHelper.EBayDescriptionTemplateName);
            _descriptionMultiListingTemplatePath = Path.Combine(AppSettings.TemplateDirectory, TemplateHelper.EBayDescriptionMultiListingTemplateName);

            _eBayApi      = eBayApi;
            _company      = company;
            _emailService = emailService;

            _actionService = new SystemActionService(_log, _time);
            _htmlScraper   = new HtmlScraperService(log, time, dbFactory);

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _barcodeService           = new BarcodeService(log, time, dbFactory);
            _autoCreateListingService = new AutoCreateEBayListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 2
0
        public CallSupplieroasisProcessing(ILogService log,
                                           ITime time,
                                           ICacheService cacheService,
                                           IEmailService emailService,
                                           IDbFactory dbFactory,
                                           CompanyDTO company)
        {
            _dbFactory             = dbFactory;
            _cacheService          = cacheService;
            _barcodeService        = new BarcodeService(log, time, dbFactory);
            _trackingNumberService = new TrackingNumberService(log, time, dbFactory);
            _log          = log;
            _time         = time;
            _emailService = emailService;
            _company      = company;

            _weightService  = new WeightService();
            _messageService = new SystemMessageService(_log, _time, dbFactory);
            _actionService  = new SystemActionService(_log, _time);
            _htmlScraper    = new HtmlScraperService(log, time, dbFactory);

            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
        protected override void RunCallback()
        {
            var dbFactory          = new DbFactory();
            var time               = new TimeService(dbFactory);
            var log                = GetLogger();
            var settings           = new SettingsService(dbFactory);
            var systemAction       = new SystemActionService(log, time);
            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);
            var lastSyncDate       = settings.GetListingsReadDate(_api.Market, _api.MarketplaceId);

            LogWrite("Last sync date=" + lastSyncDate);

            var walmartReader = new WalmartListingInfoReader(GetLogger(),
                                                             time,
                                                             _api,
                                                             dbFactory,
                                                             systemAction,
                                                             itemHistoryService,
                                                             AppSettings.WalmartReportBaseDirectory,
                                                             AppSettings.WalmartFeedBaseDirectory);

            if (!lastSyncDate.HasValue ||
                (time.GetUtcTime() - lastSyncDate) > _betweenProcessingInverval)
            {
                walmartReader.UpdateListingInfo();
                walmartReader.ReadListingInventory();

                walmartReader.ResetQtyForNotExistListings();
                walmartReader.RetireNotExistListings();

                settings.SetListingsReadDate(time.GetUtcTime(), _api.Market, _api.MarketplaceId);
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        time      = new TimeService(dbFactory);
            var        log       = GetLogger();

            var now = time.GetAppNowTime();

            if (!time.IsBusinessDay(now))
            {
                return;
            }

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }

            var companyAddress     = new CompanyAddressService(company);
            var quantityManager    = new QuantityManager(log, time);
            var actionService      = new SystemActionService(log, time);
            var addressService     = new AddressService(null, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));
            var emailSmtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailService       = new EmailService(GetLogger(), emailSmtpSettings, addressService);
            var cacheService       = new CacheService(log, time, actionService, quantityManager);
            var barcodeService     = new BarcodeService(log, time, dbFactory);
            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            var autoCreateWMListingService = new AutoCreateWalmartListingService(log,
                                                                                 time,
                                                                                 dbFactory,
                                                                                 cacheService,
                                                                                 barcodeService,
                                                                                 emailService,
                                                                                 null,
                                                                                 itemHistoryService,
                                                                                 AppSettings.IsDebug);
            var autoCreateEBayListingService = new AutoCreateEBayListingService(log,
                                                                                time,
                                                                                dbFactory,
                                                                                cacheService,
                                                                                barcodeService,
                                                                                emailService,
                                                                                itemHistoryService,
                                                                                AppSettings.IsDebug);
            var autoCreateAmazonUSPrimeService = new AutoCreateAmazonUSPrimeListingService(log,
                                                                                           time,
                                                                                           dbFactory,
                                                                                           itemHistoryService);

            //autoCreateWMListingService.CreateListings();
            //log.Info("Walmart listings were created");

            //autoCreateEBayListingService.CreateListings();
            //log.Info("eBay listings were created");

            autoCreateAmazonUSPrimeService.CreateListings();
            log.Info("Amazon US Prime listings were created");
        }
        public void CreateListings()
        {
            var cacheService         = new CacheService(_log, _time, _actionService, _quantityManager);
            var barcodeService       = new BarcodeService(_log, _time, _dbFactory);
            var itemHistoryService   = new ItemHistoryService(_log, _time, _dbFactory);
            var listingCreateService = new AutoCreateFtpMarketListingService(_log, _time, _dbFactory, cacheService, barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);

            listingCreateService.CreateListings();
        }
Exemplo n.º 6
0
        public CallGrouponProcessing(IDbFactory dbFactory,
                                     ICacheService cacheService,
                                     IEmailService emailService,
                                     ILogService log,
                                     ITime time)
        {
            _dbFactory     = dbFactory;
            _log           = log;
            _time          = time;
            _weightService = new WeightService();
            var barcodeService     = new BarcodeService(log, time, dbFactory);
            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, barcodeService, emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 7
0
        public CallMagentoProcessing(ILogService log,
                                     ITime time,
                                     IEmailService emailService,
                                     ICacheService cacheService,
                                     IDbFactory dbFactory)
        {
            _log          = log;
            _time         = time;
            _dbFactory    = dbFactory;
            _cacheService = cacheService;
            _emailService = emailService;

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _barcodeService           = new BarcodeService(log, time, dbFactory);
            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 8
0
        public ImportRelist(ILogService log,
                            ITime time,
                            IDbFactory dbFactory,
                            ICacheService cacheService,
                            IEmailService emailService,
                            ISystemActionService actionService)
        {
            _log           = log;
            _time          = time;
            _dbFactory     = dbFactory;
            _cacheService  = cacheService;
            _emailService  = emailService;
            _actionService = actionService;

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _barcodeService           = new BarcodeService(_log, _time, _dbFactory);
            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, _dbFactory, _cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
        public CallDsApiProcessing(ILogService log,
                                   ITime time,
                                   ICacheService cacheService,
                                   IQuantityManager quantityManager,
                                   ISystemActionService actionService,
                                   IEmailService emailService,
                                   IDbFactory dbFactory)
        {
            _dbFactory       = dbFactory;
            _cacheService    = cacheService;
            _quantityManager = quantityManager;
            _actionService   = actionService;
            _barcodeService  = new BarcodeService(log, time, dbFactory);
            _log             = log;
            _time            = time;
            _emailService    = emailService;

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);
            var barcodeService     = new BarcodeService(log, time, dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, barcodeService, emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 10
0
        public CallWalmartCAProcessing(ILogService log,
                                       ITime time,
                                       ICacheService cacheService,
                                       IDbFactory dbFactory,
                                       IEmailService emailService,
                                       WalmartCAApi walmartCAApi,
                                       CompanyDTO company)
        {
            _log          = log;
            _time         = time;
            _dbFactory    = dbFactory;
            _cacheService = cacheService;
            _walmartCAApi = walmartCAApi;
            _company      = company;
            _emailService = emailService;

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _actionService            = new SystemActionService(_log, _time);
            _htmlScraper              = new HtmlScraperService(log, time, dbFactory);
            _barcodeService           = new BarcodeService(log, time, dbFactory);
            _autoCreateListingService = new AutoCreateWalmartCAListingService(log, time, dbFactory, _cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
        protected override void RunCallback()
        {
            var dbFactory          = new DbFactory();
            var log                = GetLogger();
            var time               = new TimeService(dbFactory);
            var settings           = new SettingsService(dbFactory);
            var actionService      = new SystemActionService(log, time);
            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            //var itemFixupService = new ItemAutoFixIssueService(log, time, dbFactory, actionService, itemHistoryService);

            //using (var db = dbFactory.GetRWDb())
            //{
            //    db.DisableValidation();

            //    itemFixupService.RequestUpdatesForUngroupedListings();

            //    //itemFixupService.RequestUpdatesForPublishingInProgressListings();

            //    itemFixupService.RequestUnpublishWithUPCIssueListings();

            //    itemFixupService.ProcessDefectsRules();
            //}
        }
        protected override void RunCallback()
        {
            var dbFactory = new DbFactory();
            var time      = new TimeService(dbFactory);
            var log       = GetLogger();

            var settings = new SettingsService(dbFactory);

            var styleHistoryService = new StyleHistoryService(log, time, dbFactory);
            var itemHistoryService  = new ItemHistoryService(log, time, dbFactory);
            var styleManager        = new StyleManager(log, time, styleHistoryService);
            var notificationService = new NotificationService(log, time, dbFactory);
            var actionService       = new SystemActionService(log, time);

            var lastSyncDate          = _reportSettings.GetLastSyncDate(settings, _api.Market, _api.MarketplaceId);
            var isManualSyncRequested = _reportSettings.IsManualSyncRequested(settings, _api.Market, _api.MarketplaceId);

            LogWrite("Market=" + _api.Market + ", marketplaceId=" + _api.MarketplaceId);
            LogWrite("Last sync date=" + lastSyncDate.ToString() + ", isManualSyncRequested=" + isManualSyncRequested);

            if (!lastSyncDate.HasValue ||
                (DateTime.UtcNow - lastSyncDate) > _reportSettings.RequestInterval ||
                isManualSyncRequested == true)
            {
                if (_reportSettings.RequestMode == ReportRequestMode.Sheduled)
                {
                    //TODO: add
                    //http://docs.developer.amazonservices.com/en_US/reports/Reports_Overview.html
                    //NOTE: Trying to get last existing report from Amazon

                    LogWrite("Check Sheduled");
                    _reportService = new AmazonReportService(_reportSettings.ReportType,
                                                             CompanyId,
                                                             _api,
                                                             log,
                                                             time,
                                                             dbFactory,
                                                             _syncInfo,
                                                             styleManager,
                                                             notificationService,
                                                             styleHistoryService,
                                                             itemHistoryService,
                                                             actionService,
                                                             _reportSettings.GetParser(),
                                                             _reportSettings.ReportDirectory);

                    var lastReports = _reportService.GetReportList();
                    if (lastReports.Any())
                    {
                        var reportId = lastReports[0].ReportId;

                        LogWrite("Getting last exist report, ReportId=" + reportId);
                        if (_reportService.SaveScheduledReport(reportId))
                        {
                            using (var db = dbFactory.GetRWDb())
                            {
                                LogWrite("Add sheduled report");
                                db.InventoryReports.AddSheduledReport(reportId, (int)_reportSettings.ReportType, _api.MarketplaceId, _reportService.ReportFileName);

                                ProcessReport(settings);

                                _reportSettings.SetLastSyncDate(settings, _api.Market, _api.MarketplaceId, DateTime.UtcNow);
                                db.InventoryReports.MarkProcessedByReportId(_reportService.ReportId, ReportProcessingResultType.Success);
                                _reportService = null;
                            }
                        }
                    }
                    else
                    {
                        LogWrite("Do not have any reports of type=" + _reportService.ReportType.ToString());
                        _reportSettings.SetLastSyncDate(settings, _api.Market, _api.MarketplaceId, DateTime.UtcNow);
                        _reportService = null;
                    }
                }

                if (_reportSettings.RequestMode == ReportRequestMode.Requested)
                {
                    if (_reportService == null)
                    {
                        LogWrite("Create reportService");
                        _syncInfo = new DbSyncInformer(dbFactory,
                                                       log,
                                                       time,
                                                       SyncType.Listings,
                                                       _api.MarketplaceId,
                                                       _api.Market,
                                                       String.Empty);

                        _reportService = new AmazonReportService(_reportSettings.ReportType,
                                                                 CompanyId,
                                                                 _api,
                                                                 log,
                                                                 time,
                                                                 dbFactory,
                                                                 _syncInfo,
                                                                 styleManager,
                                                                 notificationService,
                                                                 styleHistoryService,
                                                                 itemHistoryService,
                                                                 actionService,
                                                                 _reportSettings.GetParser(),
                                                                 _reportSettings.ReportDirectory);

                        using (var db = dbFactory.GetRWDb())
                        {
                            var lastUnsavedReport = db.InventoryReports.GetLastUnsaved((int)_reportService.ReportType, _api.MarketplaceId);
                            if (lastUnsavedReport == null ||
                                (time.GetUtcTime() - lastUnsavedReport.RequestDate) > _reportSettings.AwaitInterval)
                            {
                                LogWrite("Request report");
                                _syncInfo.SyncBegin(null);
                                _syncInfo.AddInfo("", "Request report from Amazon");

                                _reportService.RequestReport();
                                db.InventoryReports.AddRequestedReport(_reportService.ReportRequestId, (int)_reportService.ReportType, _api.MarketplaceId);
                            }
                            else
                            {
                                LogWrite("Use last report request, id=" + lastUnsavedReport.Id + ", marketplaceId=" + lastUnsavedReport.MarketplaceId);
                                _syncInfo.OpenLastSync();
                                _syncInfo.AddInfo("", "Use last Amazon report request");

                                _reportService.UseReportRequestId(lastUnsavedReport.RequestIdentifier);
                            }
                        }
                    }
                    else
                    {
                        using (var db = dbFactory.GetRWDb())
                        {
                            LogWrite("Save report");
                            if (_reportService.SaveRequestedReport())
                            {
                                LogWrite("Save success, reportId=" + _reportService.ReportId + ", reportName=" + _reportService.ReportFileName);
                                db.InventoryReports.Update(_reportService.ReportRequestId, _reportService.ReportFileName, _reportService.ReportId);

                                ProcessReport(settings);

                                db.InventoryReports.MarkProcessedByReportId(_reportService.ReportId, ReportProcessingResultType.Success);
                                _reportSettings.SetLastSyncDate(settings, _api.Market, _api.MarketplaceId, time.GetUtcTime());
                                _reportService = null;
                            }
                            else
                            {
                                LogWrite("Could not save report");

                                var requestStatus = _reportService.GetRequestStatus();
                                if (requestStatus == null)
                                {
                                    LogWrite("Request status empty, reportId=" + _reportService);

                                    db.InventoryReports.MarkProcessedByRequestId(_reportService.ReportRequestId, ReportProcessingResultType.Cancelled);
                                    _reportSettings.SetLastSyncDate(settings, _api.Market, _api.MarketplaceId, time.GetUtcTime());
                                    _reportService = null;
                                }
                                else
                                {
                                    if (requestStatus.Status == "_CANCELLED_")
                                    {
                                        LogWrite("Mark as cancelled (requestStatus = _CANCELLED_");

                                        db.InventoryReports.MarkProcessedByRequestId(_reportService.ReportRequestId, ReportProcessingResultType.Cancelled);
                                        _reportSettings.SetLastSyncDate(settings, _api.Market, _api.MarketplaceId, DateTime.UtcNow);
                                        _reportService = null;
                                    }
                                    else
                                    {
                                        if (_reportService.SaveReportAttempts > _reportSettings.MaxRequestAttempt)
                                        {
                                            LogWrite("Mark as failed (MaxAttampts), saveReportAttempts > maxRequestAttempt");

                                            db.InventoryReports.MarkProcessedByRequestId(_reportService.ReportRequestId, ReportProcessingResultType.MaxAttampts);
                                            _reportSettings.SetLastSyncDate(settings, _api.Market, _api.MarketplaceId, DateTime.UtcNow);
                                            _reportService = null;
                                        }
                                        else
                                        {
                                            Thread.Sleep(TimeSpan.FromMinutes(Int32.Parse(AppSettings.ReportRequestAttemptIntervalMinutes)));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void RelistSKUsIfNeed(IList <string> relistSkuList)
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var listingsWithIssues =
                    db.Items.GetAllViewActual()
                    .Where(l => relistSkuList.Contains(l.SKU) && l.Market == (int)MarketType.Walmart)
                    .ToList();
                var styleItemIds = listingsWithIssues.Select(l => l.StyleItemId).Distinct().ToList();
                var allListings  =
                    db.Items.GetAllViewActual()
                    .Where(l => styleItemIds.Contains(l.StyleItemId) && l.Market == (int)MarketType.Walmart)
                    .ToList();

                foreach (var issueListing in listingsWithIssues)
                {
                    var styleItemListings = allListings.Where(l => l.StyleItemId == issueListing.StyleItemId).ToList();
                    if (styleItemListings.Count != 1)
                    {
                        _log.Info("Skipped. Style size has more than 1 or 0 market listings = " + styleItemListings.Count);
                        continue;
                    }
                    if (styleItemListings.Sum(l => l.RealQuantity) <= 5)
                    {
                        _log.Info("Skipped. Listing with low qty, qty < 5");
                        continue;
                    }

                    _log.Info("Create clone with our barcodes, for=" + issueListing.SKU);

                    var parentASIN = issueListing.ParentASIN;
                    //Clone it, with comment
                    var parentItem = db.ParentItems.GetByASIN(parentASIN, MarketType.Walmart, null);
                    IList <MessageString> messages;
                    var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);
                    var result             = ItemEditViewModel.Clone(db,
                                                                     _cacheService,
                                                                     _barcodeService,
                                                                     _actionService,
                                                                     _autoCreateListingService,
                                                                     itemHistoryService,
                                                                     parentItem.Id,
                                                                     _time.GetAppNowTime(),
                                                                     null,
                                                                     "[system] Copy created due the original barcodes are non-competitive",
                                                                     out messages);

                    if (messages.Any())
                    {
                        _log.Info("ASIN=" + issueListing.ASIN + " has clone issues");
                        foreach (var msg in messages)
                        {
                            _log.Info("ASIN: " + issueListing.ASIN + ", issue: " + msg);
                        }
                    }
                    else
                    {
                        _log.Info("ASIN=" + issueListing.ASIN + " was cloned");
                    }

                    allListings.AddRange(db.Items.GetAllViewActual()
                                         .Where(i => i.ParentASIN == result.ASIN && i.Market == (int)MarketType.Walmart)
                                         .ToList());
                }
            }
        }