EcoBlogEngineProvider - Data Provider for BlogEngine.Net - Part 1

by John 5/26/2008 4:02:00 AM

One of the reasons I like Blackfish is that its just so easy to deploy as part of a ASP.Net hosted solution. I had been exploring BlogEngine.Net as an alternative to Community Server and discovered that it comes with a couple of data providers, xml and Sql Server. Since it comes with source code I was able to determine that it should be possible to write my own data provider talking to Blackfish.

I thought it would be a really interesting project to try and get BlogEngine.Net running against Blackfish. This blog post will document how I built the data provider and how you can get  BlogEngine.Net running against it.

The first step was to download the web application  from here. If your just interested in deployment "BlogEngine.NET 1.3 (website)" is sufficient.

I'm running with version 1.3

I'm also a fan of Eco so I decided I would implement my data access layer using that. Once downloaded I got the blog running using the Ms Sql data provider, I was then able to reverse engineer the resulting database into a model.

The resulting model is shown below.

The  source code I will provide is broken down into three projects:-

EcoBlogEngineProvider: This is the BlogEngine data provider.

EcoBlogEngineProvider.MetaData : Rather than create a sql script to generate the Blackfish database, I used the DbxExpress metadata  API to code the database schema creation in Delphi.

Moshine.Eco.Persistance: This assembly contains a component . Since the Eco model is reverse engineered, Eco needs an xml file which maps the model to the database. TResourceMappingProvider is a component I created using a similiar component to one that ships with ECO, this allows me to embed the xml mapping information in the assembly that contains the Eco model.

A word of warning, if you do decide to download the code your going to need the Architect edition of RAD Studio 2007.

Once downloaded you need to build the projects, I have supplied a projectgroup for that. EcoBlogEngineProvider is dependant on BlogEngine.Core, this assembly can be found in the BlogEngine.Web bin directory which comes as part of the BlogEngine.Net download. Your probably going to have to modify the assembly reference in the EcoBlogEngineProvider project before you can build.

Inside the project EcoBlogEngineProvider.MetaData is a file called Target1.target. This is a MSBuild file which allows you to create Blackfish databases populated with the BlogEngine schema.

I have a custom MSBuild task which I run from the IDE which uses the classes inside  EcoBlogEngineProvider.MetaData to create the database schema. It used some code I uploaded to codecentral. You can read my blog post about it here

Assuming that you want to use the CodeGear ASP.Net 2.0 providers for login and membership services, the best way to start the database creation process is to create a new ASP.Net Web Application. Before running the application I would modify the Membership provider settings in web.config to look this 

 

       <membership defaultProvider="AspNetAdoMembershipProvider">
            <providers>
                <remove name="AspNetAdoMembershipProvider"/>
                <add name="AspNetAdoMembershipProvider"
                     type="Borland.Web.Security.AdoMembershipProvider, Borland.Web.Provider, Version=11.0.5000.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b"
                     connectionStringName="BlackfishSQLAspNet"
                     applicationName="/"
                     enablePasswordRetrieval="false"
                     enablePasswordReset="true"
                     requiresQuestionAndAnswer="false"
                     requiresUniqueEmail="false"
                     passwordFormat="Hashed"
                     maxInvalidPasswordAttempts="50"
                     minRequiredPasswordLength="8"
                     minRequiredNonalphanumericCharacters="0"
                     passwordAttemptWindow="10"
                     passwordStrengthRegularExpression=""/>
            </providers>
        </membership>

 

I turned off requiresQuestionAndAnswer and set  minRequiredNonalphanumericCharacters to 0. You can now run ASP.Net configuration from the project manager.

I used the configuration manager to create 2 roles Adminstrator and Editor . I then created a user that was a member of the Adminstrator role.

Following that I closed the project in the IDE and went to the App_Data directory in the project directory. This contains three files which is my Blackfish database and these are

bsql_aspnetdb.jds
bsql_aspnetdb_LOGA_ANCHOR
bsql_aspnetdb_LOGA_0000000000

I renamed them to

BlogEngine.jds
BlogEngine_LOGA_ANCHOR
BlogEngine_LOGA_0000000000

and saved them in a safe place for later use.

So lets recap. If I downloaded the CodeCentral project to a directory called c:\develop\BlogEngine it would contain the following directories.

EcoBlogEngineProvider
EcoBlogEngineProvider.MetaData
lib
Moshine.Eco.Persistence

If you attempted to build the projectgroup you will notice that a BlogEngine.Web directory is created. This is where you can copy your BlogEngine.Net installation. The final step to deploy your blog is to copy the BlogEngine.Web directory to your hosting service.

If you go into the bin subdirectory of BlogEngine.Web you should find EcoBlogEngineProvider.dll

The next step is to copy your Blackfish database into the App_Data sudirectory of BlogEngine.Web.

You are now going to create the BlogEngine schema in that database. The first thing you need to do is to open  app.config in the EcoBlogEngineProvider.MetaData directory.

You need to modify the database connection string to point to your database in the App_Data directory. For example

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

    <connectionStrings>
        <add name="SomeConnectionString" connectionString="database=C:\develop\BlogEngine\BlogEngine.Web\App_Data\BlogEngine.jds;user=SYSDBA;password=masterkey;host=localhost;protocol=TCP;create=false" providerName="Borland.Data.BlackfishSQL.RemoteClient"/>
    </connectionStrings>


</configuration>

You can then save the file and rebuild the project.  You can now use the IDE to create the database schema by right clicking on Targets1.target and executing the migration task as can be seen in the picture below.

 

  Assuming everything is correct this should result in a successful build with 0 errors. If you use the IDE data explorer on that database it should look like the following picture.

  We should now have a empty database for our blog.

The final step before running the Blog web application is to configure web.config to use the Blackfish database, the Eco BlogEngine Provider and the CodeGear ASP.Net Providers.

web.config can be found in c:\develop\blogengine\blogengine.web\web.config 

The relevant parts are as follows:-

1) Configure the application to use the EcoBlogProvider

  <BlogEngine>
    <blogProvider defaultProvider="EcoBlogProvider">
      <providers>
        <add name="XmlBlogProvider" type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
        <add name="MSSQLBlogProvider" type="BlogEngine.Core.Providers.MSSQLBlogProvider, BlogEngine.Core"/>

        <add name="EcoBlogProvider" type="Moshine.BlogProvider.TEcoBlogProvider,EcoBlogEngineProvider"/>

      </providers>
    </blogProvider>
  </BlogEngine>


2) Add the Blackfish database connection string

  <connectionStrings>
    <clear/>

    <add name="BlackfishBlogEngine" connectionString="database=|DataDirectory|BlogEngine.jds;user=SYSDBA;password=masterkey;" providerName="Borland.Data.BlackfishSQL.LocalClient"/>
</connectionstring>

The EcoBlogEngineProvider is using the inprocess LocalClient so you need to specify the provider name as Borland.Data.BlackfishSQL.LocalClient. Its probably best to change the user and password for deployment. The connectionname must be BlackfishBlogEngine because that is the one the data provider is configured to use.

3) Comment out the membership and roleManager sections and replace them with the CodeGear ones from the web.config of the application you used to create the initial Blackfish database.

    <roleManager enabled="true" cacheRolesInCookie="true" defaultProvider="AspNetAdoRoleProvider" createPersistentCookie="true">
        <providers>
            <remove name="AspNetAdoRoleProvider" />
            <add name="AspNetAdoRoleProvider" connectionStringName="BlackfishBlogEngine" applicationName="/" type="Borland.Web.Security.AdoRoleProvider, Borland.Web.Provider, Version=11.0.5000.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b"/>
        </providers>
    </roleManager>

    <membership defaultProvider="AspNetAdoMembershipProvider">
      <providers>
        <remove name="AspNetAdoMembershipProvider" />
        <add name="AspNetAdoMembershipProvider" type="Borland.Web.Security.AdoMembershipProvider, Borland.Web.Provider, Version=11.0.5000.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b" connectionStringName="BlackfishBlogEngine" enablePasswordRetrieval="false"
            enablePasswordReset="true"
            requiresQuestionAndAnswer="true"
            applicationName="/"
            requiresUniqueEmail="false"
            passwordFormat="Hashed"
            maxInvalidPasswordAttempts="50"
            minRequiredPasswordLength="2"
            minRequiredNonalphanumericCharacters="0"
            passwordAttemptWindow="10"
            passwordStrengthRegularExpression=""/>
      </providers>
    </membership>
 

4) Unfortunately Blackfish and the CodeGear providers do not run under medium trust so its very important to comment out

<!--   
    <trust level="High" />
--> 


the above section.

 

Now that the database is in place and the web.config is configured its time to verify that everything is in place. I use the Cassini webserver for this and it can be found in the RAD Studio bin directory. From the RAD Studio command prompt change to the bin directory.

 i.e C:\Program Files\CodeGear\RAD Studio\5.0\bin

You can now run Cassini using this commandline

cassiniwebserver.exe g:\develop\blogengine\blogengine.web 8080

 As soon as Cassini is up and running you can run a browser and browse to this url http://localhost:8080/default.aspx. The web page should look something like this

 

You should also be able to login using the user you setup at the begining.

 

In part 2 I aim to talk the code inside the data provider, how I imported my existing blog into BlogEngine and deploying BlogEngine to a hosting provider.

 

I hope this was useful. I have more than likely glossed over something and probably missed stuff out. Any feedback is welcome.

 

The source code for the article can be found here.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Blackfish | ECO | Delphi | BlogEngine.Net

Related posts

Comments

6/17/2008 5:04:57 PM

Jose Castillo

Hi, this is Great Article!! Congratulations!!

Jose Castillo pe

6/18/2008 3:07:15 AM

Jonas Hogstrom

Nice work! Just a short comment... the standard FileMappingProvider has a property called "ResourceName". It can be used to load a named resource from the current assembly.

Jonas Hogstrom se

Comments are closed

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author John Moshakis
I'm a software developer living in Toronto..

E-mail me Send mail

Calendar

<<  November 2017  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Authors

    Tags

    Don't show

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2017

      Sign in