Initialization Module for Catalog importer

Vote:
 

I am writing a custom catalog importer for EPI Server that would import catalog data into EPI Server from a non-EPIserver System. I am planning to use the API. I am new to EPI Server. I am trying to execute the statement below in my pilot program but I get the initilization erros. 


int catalogId = 2;

// Get a CatalogDto object.

CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto(catalogId, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogInfo));

Error: The type initializer for 'Mediachase.Commerce.Catalog.CatalogContext' threw an exception. 

I am looking for help to identify the pre-requisits for the above statement to run. I sort of have an idea of having the configuration files in place but that did not help as well. 

Thanks in advance for your hlep.

Syed

 

#80915
Feb 04, 2014 23:49
Vote:
 

To add more information.

I am following this link http://sdk.episerver.com/commerce/1.1/Content/Developers%20Guide/Catalog%20System/Catalog%20How%20To%20Code%20Samples/Creating%20Catalog%20Entries.htm

 

If somebody can provide a working version of this code in a pilot project, that would be great.

Thanks,

Syed

#80916
Feb 05, 2014 0:07
Vote:
 

Had the same exception initialy as you have:

System.TypeInitializationException: The type initializer for 'Mediachase.Commerce.Catalog.CatalogContext' threw an exception. ---> EPiServer.ServiceLocation.ActivationException: Activation error occurred while trying to get instance of type IWarehouseRepository, key "" ---> StructureMap.StructureMapException: StructureMap Exception Code:  202
No Default Instance defined for PluginFamily EPiServer.Framework.Cache.ISynchronizedObjectInstanceCache, EPiServer.Framework, Version=7.6.3.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7
   at StructureMap.BuildSession.<.ctor>b__0(Type t)
   at StructureMap.Util.Cache`2.get_Item(KEY key)
   at StructureMap.BuildSession.CreateInstance(Type pluginType)
   at StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session)
   at StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session)
   at StructureMap.Pipeline.ConstructorInstance.Get[T](String propertyName, BuildSession session)
   at lambda_method(Closure , IArguments )
   at StructureMap.Construction.BuilderCompiler.FuncCompiler`1.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args)
   at StructureMap.Construction.InstanceBuilder.BuildInstance(IArguments args)
   at StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder)
   at StructureMap.Pipeline.SmartInstance`1.build(Type pluginType, BuildSession session)
   at StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session)
   at StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session)
   at StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session)
   at StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance)
   at StructureMap.BuildSession.CreateInstance(Type pluginType)
   at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
   --- End of inner exception stack trace ---
   at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
   at EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
   at Mediachase.Commerce.Catalog.Impl.CatalogContextImpl..ctor(MetaDataContext context)
   at Mediachase.Commerce.Catalog.CatalogContext..cctor()
   --- End of inner exception stack trace ---
   at Mediachase.Commerce.Catalog.CatalogContext.get_Current()

    

 

So to successfully initialize CatalogContext and Dynamic Data Store I have this initialization code:

 

            ...            
            if (DynamicDataStoreFactory.Instance != null)
            {
                return;
            }

            var context = new ServiceConfigurationContext(HostType.Installer, new Container());
            new CommerceInitialization().ConfigureContainer(context);
            new EventsInitialization().ConfigureContainer(context);

            var factory = new SqlDatabaseFactory();
            context.Container.Configure(ce => ce.For<IDatabaseHandler>().Use(factory.CreateDefaultHandler));

            context.Container.Configure(ce => ce.For<IPriceService>().Use<PriceServiceDatabase>());

            context.Container.Configure(ce => ce.For<IObjectInstanceCache>().Use<HttpRuntimeCache>());
            context.Container.Configure(ce => ce.For<ISynchronizedObjectInstanceCache>().Use<RemoteCacheSynchronization>());

            var locator = new StructureMapServiceLocator(context.Container);
            ServiceLocator.SetLocator(locator);
            DataInitialization.InitializeFromCode(context.Container, factory, null);

            DynamicDataStoreFactory.Instance = new EPiServerDynamicDataStoreFactory();
            ...

    

#85022
Edited, Apr 11, 2014 10:39
Vote:
 

I am trying to use your code, but having trouble resolving the following objects / types. Am I missing a reference?

 

DynamicDataStoreFactory

SqlDatabaseFactory

IDatabaseHandler

RemoteCacheSynchronization

DataInitialization

#85635
Apr 30, 2014 20:51
Vote:
 

Finally I got it working, but I had to add a Fake interface implemenation (below) to make it work for me. (Thanks to another community memeber Murtaza's post) 

 

ce.For<ITypeScannerLookup>().HybridHttpOrThreadLocalScoped().Use<FakeTypeScannerLookup>();

 public class FakeTypeScannerLookup : ITypeScannerLookup
    {
        private static object _lock = new object();
        private HashSet<Type> _types = new HashSet<Type>();

        /// <summary>
        /// Gets the scanned types.
        /// 
        /// </summary>
        public IEnumerable<Type> AllTypes
        {
            get
            {
                return (IEnumerable<Type>)this._types;
            }
        }

        static FakeTypeScannerLookup()
        {
        }

        /// <summary>
        /// Adds the specified scanned type.
        /// 
        /// </summary>
        /// <param name="t">The t.</param>
        public void Add(Type t)
        {
            lock (_lock)
                this._types.Add(t);
        }

        /// <summary>
        /// Deletes the specified scanned type.
        /// 
        /// </summary>
        /// <param name="t">The t.</param>
        public void Delete(Type t)
        {
            this._types.Remove(t);
        }
    }
    

    

#85638
Apr 30, 2014 22:14
Vote:
 
DynamicDataStoreFactory -> EPiServer.Data.Dynamic.DynamicDataStoreFactory
SqlDatabaseFactory -> EPiServer.Data.Providers.SqlDatabaseFactory
IDatabaseHandler -> EPiServer.Data.IDatabaseHandler
RemoteCacheSynchronization -> EPiServer.Events.RemoteCacheSynchronization
DataInitialization -> EPiServer.Data.DataInitialization

    maybe this will help someone

#85810
May 06, 2014 10:21
Vote:
 

Could you please explain a bit, where woudl this code go and how.

#85993
May 09, 2014 19:35
Vote:
 

Nevermind got it

#86006
May 10, 2014 18:53
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.