You may have a bunch of data items which you need to either store entirely or not at all. NTFS has long supported filesystem transactions and since Windows Vista the transactions are available via Win API.
Repository uses filesystem transactions internally (when available) to prevent data corruption (e.g. data file partially written to disk or old version not deleted after saving file under different name); transaction scope may be extended in the client application as necessary.
You may enlist repository (writer) in distributed transaction using System.Transactions.TransactionScope or use local kernel transactions (faster) via StorageTransactionScope (

	IRepositoryManager repo;
	// ...
	using (var scope = new TransactionScope())
	//or using(StorageTransactionScope.Create(repo))
		const int count = 10000;
		for (int n = 0; n < count; ++n)
			item = Mock.TestDataItem.GetTestItem(n);
			if ((n + 1) % 134 == 0)
		unsavedItems = writer.GetUnsavedItems();
		Assert.AreEqual(count, unsavedItems.Values.Sum((l) => l.Count)
				        , "Total number of unsaved items must equal number of added items if in ambient transaction");

Note that folder metadata modifications participate in the same transaction as the data writer, so you can write a bunch of data items and update some property values in the same transaction.

Last edited Nov 16, 2011 at 11:13 AM by vasokolbaso, version 3


No comments yet.