Before reading this page please read Creating repository structure first.

Folders have a number of properties affecting writers
- Compressor - reference to a compressor
- EnableEncryption - whether encrypt data under this folder
- Encryptor - reference to an encryptor
- DesiredItemsPerFile - desired number of data items per data file
Please refer to xml doc for more detailed explanation (http://hdrepository.codeplex.com/SourceControl/changeset/view/7087#167407.
If not specified, they are inherited from the first ancestor defining them. If never specified default values are used. Currently only one compressor is available out of the box, based on the .NET Framework DeflateStream gzip implementation. No encryptor is provided out of the box in the current version. You can inject your own compressors and encryptors via object factory (IRepository.ObjectFactory), see IObjectFactory.AddEncryptor(ICoder, bool), IObjectFactory.AddEncryptor(ICoder, bool)
Here's an example:
public class MyEncryptor : ICoder
{
	public const string CODE = "rjd"
	#region ICoder implementation
	public Stream WrapInEncodingStream (Stream output)
	{
		...
	}

	public Stream WrapInDecodingStream (Stream encodedDataStream)
	{
		...
	}

	public string KeyCode
	{ get { return CODE; } }
	#endregion
}
public class MyCompressor : ICoder
{
	public const string CODE = "lzma"
		...
}
...
using(IRepository repository = new RepositoryManager(@"c:\data\repositories\test"))
{
	// injecting our implementations; the default (gzip) compressor is registered and used by default
	repository.ObjectFactory.AddEncryptor(new MyEncryptor(), false);
	repository.ObjectFactory.AddCompressor(new MyCompressor(), false);
				
	IRepositoryFolder folder = repository.RootFolder.CreateSubfolder("MyFolder");
	// configure parameters of the folder and its descendants
	folder.Properties.DesiredItemsPerFile = 500; // will write very big items
	folder.Properties.EnableEncryption = true;
	folder.Properties.Encryptor = MyEncryptor.CODE; // writer will grab our registered encryptor from the object factory
	folder.Properties.Compressor = MyCompressor.CODE; // writer will grab our registered compressor from the object factory
	
	using (IRepositoryWriter writer = folder.GetWriter())
	{
		// writing some data
		for (int n = 0; n < 100; ++n)
		{
			Mock.TestDataItem item = Mock.TestDataItem.GetTestItem(n);
			item.DateTime = DateTime.UtcNow;
			writer.Write(item);
		}
		// flushing buffers to disk
		writer.Flush();
	}
	// now read something written 10 milliseconds back or later, only from the target folder (not reading descendants)
	using (IRepositoryReader reader = folder.GetReader(DateTime.UtcNow.AddMilliseconds(-10), false))
	{
		IDataItemRead dataItem = reader.Read();
	}
}



Last edited Nov 16, 2011 at 11:14 AM by vasokolbaso, version 2

Comments

No comments yet.