static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; Console.CancelKeyPress += Console_CancelKeyPress; log4net.Config.XmlConfigurator.Configure(); var log = LogManager.GetLogger(typeof(Program)); var config = new Config(); var affiliatePager = new ListManagementAffiliatePager(config); var whiteDelivery = new WhiteDeliveryRepository(config); var importType = GetImportTypeFromArgs(args); int APICallCount = 0; while (affiliatePager.HasMore) { log.InfoFormat("------- Starting Page ---------"); var affiliates = affiliatePager.Next(); var allAffiliateIDs = affiliates.Select(x => x.id).Except(config.ExcludedAffiliateIds); var newAffiliateIDs = whiteDelivery.FilterOutExistingMarketAffiliateIDs(allAffiliateIDs); APICallCount++; if (importType == ImportType.both || importType == ImportType.import) { Logger.InfoFormat("Creating {0} clients (API Call {1})", newAffiliateIDs.Count(), APICallCount); // Create new clients foreach (var affiliate in affiliates.Where(x => newAffiliateIDs.Contains(x.id) && EnabledStatuses.Contains(x.status))) { whiteDelivery.CreateClient(affiliate); UpdateCache(affiliate); } } if (importType == ImportType.both || importType == ImportType.update) { // Update old clients var existingAffiliateIDs = allAffiliateIDs.Except(newAffiliateIDs); int updated = 0; int disabled = 0; Logger.InfoFormat("Processing {0} client updates (API Call {1})", existingAffiliateIDs.Count(), APICallCount); foreach (var affiliate in affiliates.Where(x => existingAffiliateIDs.Contains(x.id))) { if (!affiliateDataCache.ContainsKey(affiliate.id) || affiliateDataCache[affiliate.id] != affiliate.Hash) { if (EnabledStatuses.Contains(affiliate.status)) { whiteDelivery.UpdateClient(affiliate); UpdateCache(affiliate); updated++; } else { whiteDelivery.DisableAffiliate(affiliate); UpdateCache(affiliate); disabled++; } } } Logger.InfoFormat("Updated {0} clients and disabled {1} (API Call {2})", updated, disabled, APICallCount); } } //SaveAffiliateDataCache(affiliateDataCache); }
private void Setup(Config config) { client = new RestClient(config.MarketAPI_URL); client.AddDefaultParameter("uid", config.MarketAPI_UserID); client.AddDefaultParameter("key", config.MarketAPI_Key); }
public WhiteDeliveryRepository(Config config) { this.config = config; this.log = LogManager.GetLogger(GetType()); }
public MarketAPI(Config config) { this.config = config; Setup(config); }
public ListManagementAffiliatePager(Config config) { this.api = new MarketAPI(config); this.config = config; this.HasMore = true; }