} // AddAll // ---------------------------------------------------------------------- public virtual void Insert(int index, ITimePeriod period) { if (index < 0 || index > Count) { throw new ArgumentOutOfRangeException("index"); } if (period == null) { throw new ArgumentNullException("period"); } CheckReadOnlyItem(period); TimeSpan itemDuration = period.Duration; ITimePeriod previous = null; ITimePeriod next = null; if (Count > 0) { if (index > 0) { previous = this [index - 1]; CheckSpaceAfter(End, itemDuration); } if (index < Count - 1) { next = this [index]; CheckSpaceBefore(Start, itemDuration); } } periods.Insert(index, period); // adjust time periods after the inserted item if (previous != null) { period.Setup(previous.End, previous.End + period.Duration); foreach (var i in Enumerable.Range(index, Count)) { DateTime previousStart = this [i].Start.Add(itemDuration); this [i].Setup(previousStart, previousStart.Add(this [i].Duration)); } } // adjust time periods before the inserted item if (next == null) { return; } DateTime nextStart = next.Start.Subtract(itemDuration); period.Setup(nextStart, nextStart.Add(period.Duration)); foreach (var i in Enumerable.Range(index, 0 - index)) { nextStart = this [i].Start.Subtract(itemDuration); this [i].Setup(nextStart, nextStart.Add(this [i].Duration)); } } // Insert
} // Move // ---------------------------------------------------------------------- public virtual void Add(ITimePeriod item) { if (item == null) { throw new ArgumentNullException("item"); } CheckReadOnlyItem(item); ITimePeriod last = Last; if (last != null) { CheckSpaceAfter(last.End, item.Duration); item.Setup(last.End, last.End.Add(item.Duration)); } periods.Add(item); } // Add
/// <summary> /// 새로운 <paramref name="item"/>을 Chain의 제일 끝에 붙여 넣습니다. <paramref name="item"/>의 기간이 변경됩니다. /// </summary> /// <param name="item"></param> public override void Add(ITimePeriod item) { item.ShouldNotBeNull("item"); item.AssertMutable(); ITimePeriod last = Last; if (last != null) { AssertSpaceAfter(last.End, item.Duration); item.Setup(last.End, last.End.Add(item.Duration)); } if (IsDebugEnabled) { log.Debug("Period를 Chain의 끝에 추가합니다. item=[{0}]", item); } _periods.Add(item); }
/// <summary> /// Roughly converts sequence, date and time components into a single time period /// </summary> /// <param name="sequenceComponent"></param> /// <param name="dateComponent"></param> /// <param name="timeComponent"></param> /// <returns></returns> private ITimePeriod TransformSequenceDateTime(ProcessedComponent sequenceComponent, ProcessedComponent dateComponent = null, ProcessedComponent timeComponent = null) { ITimePeriod sequencePeriod = sequenceComponent.TimePeriod; DateTime sequenceStart = sequenceComponent.TimePeriod.Start; DateTime sequenceEnd = sequenceComponent.TimePeriod.End; if (dateComponent != null) { if ((dateComponent.Component as DateComponent).IsUntil) { sequenceEnd = dateComponent.TimePeriod.Start; } else if (dateComponent.TimePeriod.HasStart && !dateComponent.TimePeriod.HasEnd) { //aka. after [Date] sequencePeriod = sequenceComponent.Component.GetTimePeriod(dateComponent.TimePeriod.Start); sequenceStart = sequencePeriod.Start; } } if (timeComponent != null) { if ((timeComponent.Component as TimeComponent).IsUntil) { sequenceEnd = sequenceEnd + timeComponent.TimePeriod.Duration; } else { sequenceStart = sequenceStart + timeComponent.TimePeriod.Start.TimeOfDay; } } sequencePeriod.Setup(sequenceStart, sequenceEnd); return(sequencePeriod); }
/// <summary> /// 새로운 <paramref name="item"/>을 Chain의 제일 끝에 붙여 넣습니다. <paramref name="item"/>의 기간이 변경됩니다. /// </summary> /// <param name="item"></param> public override void Add(ITimePeriod item) { item.ShouldNotBeNull("item"); item.AssertMutable(); ITimePeriod last = Last; if(last != null) { AssertSpaceAfter(last.End, item.Duration); item.Setup(last.End, last.End.Add(item.Duration)); } if(IsDebugEnabled) log.Debug("Period를 Chain의 끝에 추가합니다. item=[{0}]", item); _periods.Add(item); }
/// <summary> /// <see cref="ITimePeriod"/>의 Chain의 <paramref name="index"/>번째에 <paramref name="item"/>을 삽입합니다. 선행 Period와 후행 Period의 기간 값이 조정됩니다. /// </summary> /// <param name="index">추가할 위치</param> /// <param name="item">추가할 기간</param> public override void Insert(int index, ITimePeriod item) { item.ShouldNotBeNull("item"); Guard.Assert<ArgumentOutOfRangeException>(index >= 0 && index <= Count, "인덱스 범위가 잘못되었습니다. Count=[{0}], index=[{1}]", Count, index); item.AssertMutable(); if(IsDebugEnabled) log.Debug("Chain의 인덱스[{0}]에 새로운 요소[{1}]를 삽입합니다...", index, item); var itemDuration = item.Duration; ITimePeriod previousItem = null; ITimePeriod nextItem = null; if(Count > 0) { if(index > 0) { previousItem = this[index - 1]; AssertSpaceAfter(End, itemDuration); } if(index < Count - 1) { nextItem = this[index]; AssertSpaceBefore(Start, itemDuration); } } _periods.Insert(index, item); if(previousItem != null) { if(IsDebugEnabled) log.Debug("선행 Period에 기초하여 삽입한 Period와 후행 Period들의 시간을 조정합니다..."); item.Setup(previousItem.End, previousItem.End.Add(itemDuration)); for(int i = index + 1; i < Count; i++) { var startTime = this[i].Start.Add(itemDuration); this[i].Setup(startTime, startTime.Add(this[i].Duration)); } } if(nextItem != null) { if(IsDebugEnabled) log.Debug("후행 Period에 기초하여 삽입한 Period와 선행 Period들의 시간을 조정합니다..."); var nextStart = nextItem.Start.Subtract(itemDuration); item.Setup(nextStart, nextStart.Add(itemDuration)); for(var i = 0; i < index - 1; i++) { nextStart = this[i].Start.Subtract(itemDuration); this[i].Setup(nextStart, nextStart.Add(this[i].Duration)); } } }
// ---------------------------------------------------------------------- public virtual void Insert( int index, ITimePeriod period ) { if ( index < 0 || index > Count ) { throw new ArgumentOutOfRangeException( "index" ); } if ( period == null ) { throw new ArgumentNullException( "period" ); } CheckReadOnlyItem( period ); TimeSpan itemDuration = period.Duration; ITimePeriod previous = null; ITimePeriod next = null; if ( Count > 0 ) { if ( index > 0 ) { previous = this[ index - 1 ]; CheckSpaceAfter( End, itemDuration ); } if ( index < Count - 1 ) { next = this[ index ]; CheckSpaceBefore( Start, itemDuration ); } } periods.Insert( index, period ); // adjust time periods after the inserted item if ( previous != null ) { period.Setup( previous.End, previous.End + period.Duration ); for ( int i = index + 1; i < Count; i++ ) { DateTime previousStart = this[ i ].Start.Add( itemDuration ); this[ i ].Setup( previousStart, previousStart.Add( this[ i ].Duration ) ); } } // adjust time periods before the inserted item if ( next == null ) { return; } DateTime nextStart = next.Start.Subtract( itemDuration ); period.Setup( nextStart, nextStart.Add( period.Duration ) ); for ( int i = 0; i < index - 1; i++ ) { nextStart = this[ i ].Start.Subtract( itemDuration ); this[ i ].Setup( nextStart, nextStart.Add( this[ i ].Duration ) ); } }
// ---------------------------------------------------------------------- public virtual void Add( ITimePeriod item ) { if ( item == null ) { throw new ArgumentNullException( "item" ); } CheckReadOnlyItem( item ); ITimePeriod last = Last; if ( last != null ) { CheckSpaceAfter( last.End, item.Duration ); item.Setup( last.End, last.End.Add( item.Duration ) ); } periods.Add( item ); }
/// <summary> /// <see cref="ITimePeriod"/>의 Chain의 <paramref name="index"/>번째에 <paramref name="item"/>을 삽입합니다. 선행 Period와 후행 Period의 기간 값이 조정됩니다. /// </summary> /// <param name="index">추가할 위치</param> /// <param name="item">추가할 기간</param> public override void Insert(int index, ITimePeriod item) { item.ShouldNotBeNull("item"); Guard.Assert <ArgumentOutOfRangeException>(index >= 0 && index <= Count, "인덱스 범위가 잘못되었습니다. Count=[{0}], index=[{1}]", Count, index); item.AssertMutable(); if (IsDebugEnabled) { log.Debug("Chain의 인덱스[{0}]에 새로운 요소[{1}]를 삽입합니다...", index, item); } var itemDuration = item.Duration; ITimePeriod previousItem = null; ITimePeriod nextItem = null; if (Count > 0) { if (index > 0) { previousItem = this[index - 1]; AssertSpaceAfter(End, itemDuration); } if (index < Count - 1) { nextItem = this[index]; AssertSpaceBefore(Start, itemDuration); } } _periods.Insert(index, item); if (previousItem != null) { if (IsDebugEnabled) { log.Debug("선행 Period에 기초하여 삽입한 Period와 후행 Period들의 시간을 조정합니다..."); } item.Setup(previousItem.End, previousItem.End.Add(itemDuration)); for (int i = index + 1; i < Count; i++) { var startTime = this[i].Start.Add(itemDuration); this[i].Setup(startTime, startTime.Add(this[i].Duration)); } } if (nextItem != null) { if (IsDebugEnabled) { log.Debug("후행 Period에 기초하여 삽입한 Period와 선행 Period들의 시간을 조정합니다..."); } var nextStart = nextItem.Start.Subtract(itemDuration); item.Setup(nextStart, nextStart.Add(itemDuration)); for (var i = 0; i < index - 1; i++) { nextStart = this[i].Start.Subtract(itemDuration); this[i].Setup(nextStart, nextStart.Add(this[i].Duration)); } } }