So last night I downloaded the new Preview 3 release of MEF and incorporated into Comicster (you can read the posts leading up to this here and here). Right now I can run Comicster and see “.cmxx” files and “.xml” files in the Open File dialog. if I then close the program and drop a DLL into the “My Documents\Comicster” folder, the next time I run Comicster I see “.cmx” files in the dialog as well. It works a treat and I’ll devote a post to the implementation soon (I don’t have the source handy here at work).

As you saw in my previous posts on the topic, I have defined the “file format plug-in” system using two interfaces, ICollectionReader and ICollectionWriter. That lets me create a “read-only” format to provide migration paths from earlier versions of Comicster or from other programs. The problem, though, is that it also lets people create “write-only” formats. For example, someone might define a “.csv” writer but not an equivalent reader.

Why is this a problem? I’m worried that Joe User might download Comicster for the first time, along with some file-format plug-ins, and spend a few hours creating his collection only to save it as “joe.csv”. He knows he has saved it, but doesn’t realise that he can’t re-open the file, and has essentially lost his work.

The way I’ll address this is slightly rearrange my interfaces so that ICollectionWriter descends from ICollectionReader. That means that if you want to implement a read-only file format you can just implement ICollectionReader, but if you want to implement a format that you can save to, you have to provide a way to read the collection back from that file. I might end up having to rename the ICollectionWriter interface to be more explicit in the fact that it’s both a writer and a reader.

But what, you ask, about exporting a collection to a file format that you don’t plan on reading from? A CSV export, for example, would be quite handy. I’ve got that base covered (at least in my head). I’ll be defining an ICollectionExporter interface, like this:

public interface ICollectionExporter
{
    public void ExportCollection(Collection collection, DirectoryInfo folder);
}
Notice that this interface accepts a DirectoryInfo parameter rather than a Stream to write to. That’s because I want to be able to export into a folder and let the plug-in writer decide whether it’s a single-file export (like CSV) or a multiple-file export (like a series of HTML files). Heck, I might even define two different interfaces so that there’s a choice of exporting to a file or a folder, depending on the plug-in. Then I can surface these exporters under an “Export” button, which will make it much more obvious to Joe User that he’s writing his collection to a format that Comicster may not be able to read.