Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using EPiServer.Find.Cms;
using EPiServer.ServiceLocation;
using Mediachase.Commerce.Catalog.ImportExport;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
public class CatalogImportManager : ICatalogImportManager
{
private readonly ILogManager _logManager;
private StringBuilder _stringBuilderResponse;
public CatalogImportManager(ILogManager logManager)
{
this._logManager = logManager;
this._stringBuilderResponse = new StringBuilder();
}
public string CatalogImport(Stream catalogMemoryStream)
{
// This is how we disable the updates to Find
EventedIndexingSettings.Instance.EventedIndexingEnabled = false;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = false;
try
{
XDocument catalogXml = XDocument.Load(catalogMemoryStream);
CatalogImportExport catalogImportExport = new CatalogImportExport();
catalogImportExport.ImportExportProgressMessage += CatalogImportExport_ImportExportProgressMessage;
catalogImportExport.Import(catalogXml, true);
catalogXml.Dispose();
}
catch (Exception ex)
{
this._logManager.WriteError("Error in ImportWithHandlers", ex);
//In case of any error, we need to remember to enable Find
EventedIndexingSettings.Instance.EventedIndexingEnabled = true;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = true;
throw;
}
//If everything worked fine, we enable Find
EventedIndexingSettings.Instance.EventedIndexingEnabled = true;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = true;
return this._stringBuilderResponse.ToString();
}
private void CatalogImportExport_ImportExportProgressMessage(object source, ImportExportEventArgs args)
{
this._logManager.WriteError(args.Message);
this._stringBuilderResponse.Append(args.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment