I'd like to write a console or winforms application that will interact with the EPiServer database. Since I don't want to muck about in the deep inards of the database I'd like to use the Community Server API.
However, all the examples I can find are using the "CommunitySystem.CurrentContext" which is null when running outside the website.
Now, I'm going to transfer a large amount of data from a legacy system to EpiServer Community and I really don't want to do that from a web page but from an application I have a little more control of.
Is there any way I can use the API from outside the web context? Anyone have a pointer on where I should start looking?
You will need a HTTP context to run the current version of Community. With that said, there is nothing stoppin you from creating that context yourself. You will also need to call the LoadSetting method in the EPiServer.Common.Settings class.
Somethin like this should do the trick:
TextWriter tw = new StringWriter();
HttpWorkerRequest wr = new SimpleWorkerRequest("/", @"C:\", "default.aspx", "", tw);
HttpContext.Current = new HttpContext(wr);
Thanks for the reply! I got a bit further, but now the LoadSettings() is throwing an exception: "System.ArgumentException : The application relative virtual path '~/' is not allowed here.".
I've narrowed it down to a call to "WebConfigurationManager.OpenWebConfiguration("~/");" originating from the EPiServer.Common.Settings.LoadEntityProviders(). See the graph below:
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(String) : Configuration Used By EPiServer.Common.Configuration.ConfigurationSectionBase<T>.GetConfigurationFromFile() : Configuration Used By EPiServer.Common.Configuration.ConfigurationSectionBase<T>.get_CurrentConfiguration() : Configuration Used By EPiServer.Common.Configuration.EPiServerCommonSection.get_Instance() : EPiServerCommonSection Used By EPiServer.Common.Cache.CacheHandler.InitializeCache() : Void EPiServer.Common.Data.DatabaseHandler.GetConnectionString() : String EPiServer.Common.ImplementationModule.LoadCoreConfiguration() : Void EPiServer.Common.Settings.LoadEntityProviders() : Void
I'm continuing to investigate but if you have any pointers I'd be more than happy! :)
My colleague Jarle figured out the last bits and blogged the whole process here: http://jarlef.wordpress.com/2009/12/11/using-the-episerver-community-framework-outside-iis/ So if you want to run the EPiServer API outside of IIS, that's the place to start. Works like a charm!