NTimeline is a library to build a timeline which has several source which deliver points of time or durations.
NTimeline is a library which is designed to be uses in your business layer.
Here some of the key operations of NTimeline:
- Collect points of time
- Collect durations
- Sort all collected data
- Get time slices from the created timeline
- Calculate rates upon time slices
- Calculate a timeline upon points of time or time periods given by time sources
It's quite easy. First you have to create a time source. NTimeline gives you an abstract base class called TimeSourceBase which implements the interface ITimeSource:
public class TestSource : TimeSourceBase
{
public override IList<TimeElement> CreateTimeElements()
{
return new List<TimeElement> {
new TimeElement(new DateTime(2010, 1, 1), true),
new TimeElement(new DateTime(2010, 3, 1), true) };
}
public override bool IsValid(Duration duration)
{
// Dummy implementation
return true;
}
}
Now you can already build a timeline:
TestSource source = new TestSource();
Timeline timeline = new Timeline();
timeline.AddTimeSource(source);
timeline.Build();
That is also quite easy. First you have create your visitor. NTimeline provide the interface ITimelineVisitor, so your class has to implement this interface.
public class ConsoleVisitor : ITimelineVisitor
{
public void Visit(TimePeriod period)
{
Console.WriteLine("Visit period {0}", period);
}
}
Now you have to call the following method on your timeline instance:
ConsoleVisitor visitor = new ConsoleVisitor();
timeline.VisitTimePeriods(visitor);