public override void ExecuteTask() { foreach (ServiceTaskProviderElement provider in ServiceTaskProviderConfiguration.ProviderConfiguration) { ecomDataProvider = new EcomDataProvider(provider.ConnectionString); if (!ecomDataProvider.EagleExistsAsExternalSupplier()) { Log.LogInfo( "Eagle doesn't exist in Ecom as an external supply partner. None of the businesses will be synced"); } else { // Get the last updated timestamp from ECOM for Eagle businesses DateTime mostRecentUpdateTime = ecomDataProvider.GetMostRecentBusinessUpdateTime(); Log.LogInfo(string.Format("Getting businesses updated from {0}", mostRecentUpdateTime.ToString(CultureInfo.InvariantCulture))); // Get all businesses in Eagle modified since this date and are associated to countries for this provider (Eagle.Business.Updated >=) - if first run assume 2013-01-01 List<Model.Business.Business> businesses = businessManager.GetLastModifiedBusinesses(mostRecentUpdateTime) .Where(c => provider.ContainsCountry(c.Country.IsoChar2Code)) .ToList(); Log.LogInfo(string.Format("{0} {1} Businesses have been modified on Eagle", businesses.Count, provider.ProviderSet)); int numberOfBusinessesSynced = 0; // Insert/Update records in the ECOM database if (Log.IsDebugEnabled) { Log.LogDebug(string.Format("Synchronizing {0} businesses to Ecom:", provider.ProviderSet)); } Guid updatedByUserId; if (!Guid.TryParse(identity.Name, out updatedByUserId)) { Log.LogError("Couldn't get the user identity from the current thread"); Log.LogInfo("Synchronizing task finished executing"); return; } foreach (Model.Business.Business business in businesses) { if (State == TaskState.Stopping) { Log.LogInfo("Aborting SyncBusinessesToEcom task due to the service being stopped."); return; } List<string> missedChannels; var businessAccount = EcomConverter.EagleBusinessToEcom(business, provider.ChannelSyncCode, out missedChannels); businessAccount.ModifiedByUserId = updatedByUserId; businessAccount.ModifiedDate = DateTime.UtcNow; businessAccount.BusinessAccountStatusTypeId = EcomConverter.ACTIVE_CODE; bool synced = true; EcomBusinessInfo ecomBusinessInfo = null; try { ecomBusinessInfo = ecomDataProvider.SaveBusinessAccount(businessAccount); Log.LogDebug(string.Format("businessId = {0} synced", business.Id)); } catch (SqlException ex) { Log.LogError( string.Format("businessId = {0} was not synced because of SQL error.", business.Id), ex: ex); synced = false; } if (Log.IsDebugEnabled && synced) { numberOfBusinessesSynced++; if (ecomBusinessInfo != null) { Log.LogDebug(string.Format("businessId = {0} Channels synced : {1}", business.Id, ecomBusinessInfo.AddedChannels.ToArray().Serialize())); Log.LogDebug(string.Format("businessId = {0} Channels missed : {1}{2}", business.Id, ecomBusinessInfo.MissingChannels.ToArray().Serialize(), missedChannels.ToArray().Serialize())); } Log.LogDebug(string.Format("businessId = {0} synced", business.Id)); } } Log.LogInfo(string.Format("{0} {1} Businesses have been synced to Ecom", numberOfBusinessesSynced, provider.ProviderSet)); } } }
private void SynToEcom(Model.Payment.SyncPayment payment) { foreach (ServiceTaskProviderElement provider in serviceTaskProviderConfiguration.ProviderConfiguration) { var ecomDataProvider = new EcomDataProvider(provider.ConnectionString); if (!ecomDataProvider.EagleExistsAsExternalSupplier()) { Logger.LogInfo("Eagle doesn't exist in Ecom as an external supply partner. Merchant Status will not be synced"); } else { ecomDataProvider.UpdateBusinessMerchantStatus(payment.MerchantStatus == SynMerchantStatus.OwnMerchant, payment.BusinessShortName); } } }