Read my blog here
Created
August 2, 2022 09:20
-
-
Save jstemerdink/654cbf8ac836d72981c0609a4b6d079c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomCatalogItemChangeManager : CatalogItemChangeManager | |
{ | |
private readonly IScheduledJobRepository scheduledJobRepository; | |
public CustomCatalogItemChangeManager( | |
IChangeNotificationManager changeNotificationManager, | |
EntryIdentityResolver entryIdentityResolver, | |
IScheduledJobRepository scheduledJobRepository) | |
: base(changeNotificationManager: changeNotificationManager, entryIdentityResolver: entryIdentityResolver) | |
{ | |
this.scheduledJobRepository = scheduledJobRepository; | |
} | |
public override void InsertChanges(IEnumerable<int> entryIds) | |
{ | |
ScheduledJob job = this.scheduledJobRepository.Get(new Guid("guid-of-import-job")); | |
if (job != null && job.IsRunning) | |
{ | |
return; | |
} | |
base.InsertChanges(entryIds: entryIds); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using EPiServer.Events.ChangeNotification; | |
using Mediachase.Commerce; | |
using Mediachase.Commerce.Catalog; | |
public class CustomCatalogItemChangeManager : CatalogItemChangeManager | |
{ | |
public CustomCatalogItemChangeManager( | |
IChangeNotificationManager changeNotificationManager, | |
EntryIdentityResolver entryIdentityResolver) | |
: base(changeNotificationManager: changeNotificationManager, entryIdentityResolver: entryIdentityResolver) | |
{ | |
this.SavingChangesEnabled = true; | |
} | |
public bool SavingChangesEnabled { get; set; } | |
public override void InsertChanges(IEnumerable<int> entryIds) | |
{ | |
if (!this.SavingChangesEnabled) | |
{ | |
return; | |
} | |
base.InsertChanges(entryIds: entryIds); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
container.Configure(x => x.For<CatalogItemChangeHandlerBase>().Use<CustomCatalogItemChangeManager>()); | |
container.Configure(x => x.For<CatalogItemChangeManager>().Use<CustomCatalogItemChangeManager>()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override string Execute() | |
{ | |
CustomCatalogItemChangeManager customCatalogItemChangeManager = null; | |
try | |
{ | |
customCatalogItemChangeManager = this.catalogItemChangeHandler as CustomCatalogItemChangeManager; | |
if (customCatalogItemChangeManager != null) | |
{ | |
customCatalogItemChangeManager.SavingChangesEnabled = false; | |
} | |
// Do your magic | |
} | |
finally | |
{ | |
if (customCatalogItemChangeManager != null) | |
{ | |
customCatalogItemChangeManager.SavingChangesEnabled = true; | |
} | |
} | |
return "Job done" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment