Tuesday, October 9, 2007

How to build a document plugin system

Currently we are building a documnt plugin system for our app.

Which way do you prefer to specify documents:
Example number 1:


[DocumentRepository]
public class DocumentRepository
{
[Documents]
public void RegisterSheets()
{
m_documents.Add(typeof(Client[]), "ClientBook.odt", "Books/second level book", "Client book", "Print client book");

m_documents.Add(typeof(Contact), "ClientSheet.odt", "Sheets", "Contact sheet", "Print contact sheet");
}
}



Or number two:

[DocumentAttribute(typeof(Client[]), "ClientBook.odt", "Books/second level book")]
public class PrintClientBookClone2 : BasePrintingCommand
{
public PrintClientBookClone2() : base("Client book", "Print client book")
{
}

protected override void Invoke(object sender, EventArgs e)
{
WindowOpener.Default.OpenDocument(new DLC.Core.UI.Documents.GenericBookDocument(this, DataRoot));
}
}

[DocumentAttribute(typeof(Contact), "ClientSheet.odt", "Sheets")]
public class PrintContactSheetClone2 : BasePrintingCommand
{
public PrintContactSheetClone2()
: base("Client sheet", "print client sheet")
{
}

protected override void Invoke(object sender, EventArgs e)
{
WindowOpener.Default.OpenDocument(new GenericDocumentForm(this, DataRoot));
}
}



Both examples achieve the same functionality: two print buttons are created. One is placed under menu "Books/second level book/Client book", the other under "Sheets/Client sheet". Slash here denotes that the menu is composed of some sub-menus.

So which do you choose?

I choose both cases, since the first one is extremely short, and allows you to add documents very quickly. However, the other, while being cumbersome and ugly, allows you to achieve maximum flexibility in case you need it. And we know bussiness people need it alot.

No comments: