Using the Community Server API from a stand-alone application

Vote:
 

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?

#34800
Nov 16, 2009 22:48
Vote:
 

Hi Glenn!

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);
            
Settings.LoadSettings();
For that to work you'll also need to copy some config files and folders from a real community website project.

#34830
Nov 18, 2009 0:07
Vote:
 

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! :)

 

#34891
Nov 19, 2009 14:00
Vote:
 

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!

#35506
Dec 14, 2009 13:12
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* 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.