Skip to content
Paolo Innocenti edited this page Nov 19, 2018 · 4 revisions

Configure Utility

Basic Configuration

The code above create a new simple week-configuration: mon-fri from 9AM to 01PM and from 2PM to 6PM

week configuration starting on monday

//this is the configuration of a work-week: 8h/day from monday to friday
var wts1 = new WorkTimeSpan() 
	{ Start = new TimeSpan(9, 0, 0), End = new TimeSpan(13, 0, 0) };
var wts2 = new WorkTimeSpan() 
	{ Start = new TimeSpan(14, 0, 0), End = new TimeSpan(18, 0, 0) };
var wts = new List<WorkTimeSpan>() { wts1, wts2 };

var week = new WeekDaySpan()
{
	WorkDays = new Dictionary<DayOfWeek, WorkDaySpan>()
	{
		{DayOfWeek.Monday, new WorkDaySpan() {TimeSpans = wts}}
		,
		{DayOfWeek.Tuesday, new WorkDaySpan() {TimeSpans = wts}}
		,
		{DayOfWeek.Wednesday, new WorkDaySpan() {TimeSpans = wts}}
		,
		{DayOfWeek.Thursday, new WorkDaySpan() {TimeSpans = wts}}
		,
		{DayOfWeek.Friday, new WorkDaySpan() {TimeSpans = wts}}
	}
};

Fluent-Config

Fluent config example, the same simple week from mon to fri:

Map-Config Style

var cfg = new WorkingDaysConfig()
.Week(new WeekDaySpan().Day(DayOfWeek.Monday,
    new WorkDaySpan()
        .Time(new TimeSpan(9, 0, 0), new TimeSpan(13, 0, 0))
        .Time(new TimeSpan(14, 0, 0), new TimeSpan(18, 0, 0)))
.Day(DayOfWeek.Tuesday,
    new WorkDaySpan()
        .Time(new TimeSpan(9, 0, 0), new TimeSpan(13, 0, 0))
        .Time(new TimeSpan(14, 0, 0), new TimeSpan(18, 0, 0)))
    )
.Holiday(new AHolyDay(15, 8))
.Holiday(2, 6)
.Holiday(new EasterMonday());

var cfg2 = new WorkingDaysConfig()
.Week(WeekDaySpan.CreateSymmetricalConfig(
    new WorkDaySpan()
    .Time(new TimeSpan(9, 0, 0),
            new TimeSpan(13, 0, 0))
    .Time(new TimeSpan(14, 0, 0),
            new TimeSpan(18, 0, 0)),
    new DayOfWeek[]
    {
        DayOfWeek.Monday,
        DayOfWeek.Tuesday,
        DayOfWeek.Wednesday,
        DayOfWeek.Thursday,
        DayOfWeek.Friday
    }));
Clone this wiki locally