Repository reader implements IRepositoryReader interface (http://hdrepository.codeplex.com/SourceControl/changeset/view/7087#167433).
It can read from an arbitrary collection of folders. Most convenient way to create a reader may be asking for it from folder from which you want to read. You can also use IRepository.ObjectFactory.GetReader (IRepository is "infrastructural", extended version of the IRepositoryManager interface, see http://hdrepository.codeplex.com/SourceControl/changeset/view/7087#167422).

Here is a quick sample (based on a unit test) with comments:
	IRepositoryFolder targetFolder;
	// ...
	// getting reader from the root folder from which we want to read, recursively reading all descendant folders
	IRepositoryReader reader = targetFolder.GetReader(DateTime.Now.AddDays(-1), true);

	// adding folder from outside the subtree; all the data streams will be merged
	IRepositoryFolder anotherFolder;
	// ...
	reader.AddFolder(anotherFolder);

	IDataItemRead ritem = null;
	int n = 0;

	IRepositoryReader altReader = null;
	SeekStatusListener seekStatusListener = new SeekStatusListener();

	while (reader.HasData)
	{
		// periodically creating new reader from position returned by the first one and checking that they are
		// positioned at exactly the same point
		if (n > 0 && n % 100 == 0)
		{
			// using position of the first reader to re-create another reader instance in exectly the same state
			// the position may be persisted (serializable) and used later to continue [interrupted] reading in the same way
			altReader = Repository.ObjectFactory.GetReader(reader.Position, seekStatusListener.HanldeStatus);
		}
		ritem = reader.Read();

		if (altReader != null)
		{
			// checking that the reader recreated from position is indeed in the same state
			IDataItemRead altItem = altReader.Read();
			Assert.AreEqual(ritem.DataItem.DateTime, altItem.DataItem.DateTime);
			Assert.AreEqual(0, seekStatusListener.Statuses.Count);
		}

		++n;
	}

	// you can start reading again
	reader.Seek(DateTime.Now.AddDays(-1));

	for (n = 0; n < 1000 && reader.HasData; ++n)
	{
		Assert.IsNotNull(reader.Read());
	}

	// you can change reading direction most of the time except sometimes after Seek() due to deferred file loading
	// (until deferred data files are loaded)
	if (reader.CanChangeDirection)
	{
		reader.Direction = bfs.Repository.Util.EnumerationDirection.Backwards;
		// now read the same items in the opposite order
		for (n = 0; n < 1000 && reader.HasData; ++n)
		{
			Assert.IsNotNull(reader.Read());
		}
	}



Last edited Nov 16, 2011 at 9:28 AM by vasokolbaso, version 3

Comments

No comments yet.