Much of what I’m going to show today has been borrowed from Alex Henderson on the storage facility.
This post continues the hosting base4 inside your web application post
To integrate base4 in castle you can register either components or create a facility which allows it to hook into some bits of the castle life-cycle.
It doesn’t make such a big difference when actually writing code except for the fact that you have transactions managed by castle, caching etc practically for free.
The ObjectTransaction that is available in base4 is built on the transaction scope and uses TransactionOptions.Required. Translated freely this means it will attach itself to an existing transaction if one exists if not it will create one.
So below I’ll first put the code for the storage facility and the base4TransactionManager and the configuration in the config files. The full version of these files and the classes can be found in the source control repository of NBlogr
The storage facility
namespace NBlogr.Common.Base4Integration
{
public class Base4StorageFacility : AbstractFacility
{
protected override void Init()
{
// If no context has been set yet (but should be done in application_start) set the default context.
if (StorageContext.Default == null)
{
string base4Context = FacilityConfig.Attributes["base4Context"];
if (string.IsNullOrEmpty(base4Context))
{
throw new StorageException(“The Base4StorageFacility requires a \”base4Context\” attribute to be set”);
}
StorageContext.SetDefault(base4Context);
}
// Add the transactionmanager to the registered components
Kernel.AddComponent(“base4.transactionManager”, typeof(ITransactionManager), typeof(Base4TransactionManager));
// Add the IItemcontext to the registered components
Kernel.AddComponentInstance(“base4.defaultContext”, typeof(IItemContext), StorageContext.Default);
// Add the base4Dataobject
Kernel.AddComponent(“base4.dataObject”, typeof(IDataObject<>), typeof(BaseDataObject<>));
}
}
}
The transaction manager
namespace NBlogr.Common.Base4Integration
{
[PerThread]
public class Base4TransactionManager : DefaultTransactionManager
{
}
}
The IDataObject interface
public interface IDataObject : IBaseDataObject
where T : class, IItem, new()
{
void Delete(T item);
Base4.Storage.IItemList Find(ObjectPath oPath, string sortExpression);
Base4.Storage.IItemList Find(string oPath, string sortExpression, int pageNumber, int pageSize, out int pageCount);
Base4.Storage.IItemList Find(ObjectPath oPath, string sortExpression, int pageNumber, int pageSize, out int pageCount);
Base4.Storage.IItemList Find(string oPath);
Base4.Storage.IItemList Find(ObjectPath oPath);
Base4.Storage.IItemList Find(string oPath, string sortExpression);
Base4.Storage.IItemList FindAll(string sortExpression, int pageNumber, int pageSize, out int pageCount);
Base4.Storage.IItemList FindAll(string sortExpression);
Base4.Storage.IItemList FindAll();
Base4.Storage.IItemList FindById(Guid Id);
T GetById(Guid Id);
T GetOne(string oPath, params object[] parameters);
T GetOne(string oPath);
T GetOne(ObjectPath oPath);
T GetOneUsingSQL(string SQL);
T GetOneUsingSQL(string SQL, ObjectScope scope);
T GetOne(string opath, ObjectScope scope);
T GetOne(ObjectPath path, ObjectScope scope);
T Save(T item);
string SortExpression { get; set; }
void DeleteAll();
void Delete(ObjectPath path);
void Delete(string path);
void Delete(string path, params string[] replaces);
IItemList Find(ObjectPath path, ObjectScope scope);
IItemList FindUsingSQL(string SQL);
IItemList FindUsingSQL(string SQL, ObjectScope scope);
IItemList Find(ObjectPath path, ObjectScope scope, string sortExpression, int pageNumber, int pageSize, out int pageCount);
IItemList FindAll(ObjectScope scope, string sortExpression, int pageNumber, int pageSize, out int pageCount);
}
The facilities.config file
<configuration>
<facilities>
NBlogr isn’t dead.. It just underwent a transformation for the better.
I also changed the title of the application from NBlogr – An atlas blogging engine to NBlogr – a blogging engine built on simplicity
The reason for this change is the fact that it is currently built using jquery as javascript library. I will look at atlas again when it releases.
I moved NBlogr to run on castle. During the course of the next week I’ll complete my posts on how to do Castle development with base4
If you’re interested in how it looks or you want a preview the last source in the repository builds and you should be able to run it in the development server of visual studio
I had a chat with JD a while ago and he asked me about plugins. At that time I knew already I wanted to provide something for users to be able to add plugin’s to the database. But I hadn’t really given it much thought on how I would do that.
My reasoning on this subject is :
I want users to be able to add a plug in at runtime. Plugin’s for a blog are lately both server related client side. So I will create a plugin factory with a couple of providers like a google video provider, grouper video, flickr, bookmark services. And you can write a plugin using javascript and ironpython code. The engine will evaluate that code at runtime and there has been no application restarting etc. If somebody has a better plan for doing a plugin infrastructure please let me know I haven’t done any of the ground work for this yet but create a schema in base4 so now would be the best time to stop me from making big mistakes.
Another improvement is the fact that when nblogr reaches release it will come with a couple of templates for you to chose from. I’ll try to include one that is built on the css scheme of csszengarden that way you’ll have an infinite repository of css to make your blog look differently instantaneously.
The next improvement is that a user is now able to mimic wildcard requests and nblogr will handle those. So there is no need for appending aspx to pages for rewriting (routing it is called in monorail) You get the choice in the config file to have your webserver handle the wild card mapping or nblogr. When you choose for nblogr nblogr will need write access to 2 folders in your website and create a shadow folder structure to represent the rewrite tree structure. There is weaker point here and that is that the first default document in IIS must be set to Default.aspx If you can map an extension to aspnet_isapi.dll at your webserver then you can also have the urls rewritten using a branded extension.
I think that this are the 3 major changes for the moment to the engine. This did set me back for the next release with a couple of weeks but in the end the final release can be done much more quickly than it would have been possible using the code I had before.
I also promise that this time things mostly stay as they are. There will be no more experimenting but just getting Nblogr to a proper release state and shipped.
Today I put a preview release of NBlogr online.
I still have to change the online site but will do so very shortly.
This release has very basic functionality and is not yet feature complete so a lot may change later on.
If anybody feels like joining the project do not hesitate
All help I get is extremely welcome.
http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=Nblogr
I’m heading into a very busy week/couple of weeks so I’m not sure if I will be able to spend as much time as I’ve been spending lately on the project. But I think every week I will be able to show some progress at least.
If you feel like it go ahead and give it a try but don’t upgrade your blog just yet
.
I’d be keen to know what your thoughts are on the subject.
To upload files in nblogr. I wanted the user to have the possibility to upload as many files as they wanted but only show one file element.
The upload procedure has to work without reloading the page entirely but there is no way of getting the size or the bytes of a file through the html input file control from clientscript without popping up a security warning.
And what do I personally think about security warnings : they are a necessary evil but limit you a lot in the development of contemporary sites with rich client interaction.
If I am to present a site to my parents and they have to figure stuff out themselves I’m pretty sure that once the read the words : Security warning, Potential risk etc… they will click no ==> site doesn’t work ==> site == crap
I wanted to include an upload with progress bar but decided to let that idea go and just give an implementation of a multiple file upload with a single inputelement. Maybe I will put this in during the next iteration. That way I can probably release a ctp this weekend and start thinking about a plugin architecture (thanks for the idea JD)
Because of the file issues i have to run it in an iframe :-s and have the page and the frame talk to eachother.