You start by creating the root folder, then instantiate RepositoryManager pointing it to that folder.
	IRepositoryManager repo = new RepositoryManager(@"c:\data\repositories\test");

After that you have access to the root folder via IRepositoryManager.RootFolder and from there you can proceed creating descendant folders.
	var myFolder = repo.RootFolder.CreateSubfolder("MySubfolder");

An alternative is creating the folders on the fly. Say, your data items have one or more attributes which identify the source of the data (e.g. some sort of address) and you want to structure the data by address (this will allow to quickly access data associated with required address/location; you may represent address by hierarchy Country-State-Suburb-Street for example). Writer has root target folder and it can write to any descendant of that root. There are 2 options of how to specify relative path from root target folder and destination folder - you can put the logic in either IDataItem.RelativePath implementation or implement IDataRouter and give it to the writer, see IRepositoryWriter.DataRouter. In both cases you will need to allow the writer to create missing subfolders on the fly:

see RepositoryWriterTest.GetUnsavedItemsWithFlushTest (

	IRepositoryWriter writer = myFolder.GetWriter();
	writer.DataRouter = new Mock.NumberedDataRouter(subfolderCount);
	writer.AllowSubfoldersCreation = true;

You may implement router this way:

	interface IMyDataItem : IDataItem
		string Country { get; }
		string State { get; }
		String Suburb { get; }
	class MyLocationRouter : IDataRouter
		public string GetRelativePath(IDataItem dataItem)
			IMyDataItem myItem = dataItem as IMyDataItem;
			if (myItem != null)
				return string.Join(RepositoryFolder.logicalPathSeparator, myItem.Country, myItem.State, myItem.Suburb);
			return "SomeOtherSubfolder";


Note that if you set a router on the writer the IDataItem.RelativePath is ignored, i.e. the router takes precedence.

Every folder can have some metadata accessible through IRepositoryFolder.Properties, see In addition to a number of predefined strongly typed properties you can set a number of arbitrary custom properties (named string values). Note that some of the properties are inherited by all descendants unless overridden.

Last edited Nov 16, 2011 at 9:11 AM by vasokolbaso, version 4


No comments yet.