public virtual void LoadData(ObjectId seekRowId, SeekDirection seekDirection, int rowCount) { this.contents = this.CreateListViewContents(); this.contents.DataSource = this.CreateDataSource(this.contents.Properties); this.contents.DataSource.Load(seekRowId, seekDirection, rowCount); this.SubscribeForFolderContentChanges(); }
public void Seek(bool dir) { SeekDirection d = SeekDirection.Forward; if (dir == true) { d = SeekDirection.Forward; } else if (dir == false) { d = SeekDirection.Backward; } if (d == SeekDirection.Forward) { currentIndex = currentIndex + 1; if (currentIndex == clips.Count) { currentIndex = 0; } } else { currentIndex--; if (currentIndex < 0) { currentIndex = clips.Count - 1; } } }
private TimeSpan SeekNextPosition(SeekDirection direction, TimeSpan streamDuration) { // Compute new position based on direction and ESPlayer playback position. _esPlayer.GetPlayingTime(out var position); Log.Enter(position.ToString()); if (direction == SeekDirection.Forward) { position += SeekDistance; if (position >= streamDuration) { position = streamDuration; } } else { position -= SeekDistance; if (position < TimeSpan.Zero) { position = TimeSpan.Zero; } } Log.Exit(position.ToString()); return(position); }
public IEnumerable <(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction) { if (keyOrPrefix == null) { keyOrPrefix = Array.Empty <byte>(); } using var it = db.NewIterator(store.defaultFamily, options); byte[] fullKey = keyOrPrefix; if (direction == SeekDirection.Forward) { for (it.Seek(fullKey); it.Valid(); it.Next()) { yield return(it.Key(), it.Value()); } } else { for (it.SeekForPrev(fullKey); it.Valid(); it.Prev()) { yield return(it.Key(), it.Value()); } } }
// Token: 0x06001DDF RID: 7647 RVA: 0x000AD211 File Offset: 0x000AB411 public override void LoadAdjacent(ObjectId adjacentId, SeekDirection seekDirection, int rowCount) { if (!this.IsContactView) { throw new NotImplementedException(); } base.LoadAdjacent(adjacentId, seekDirection, rowCount); }
public IEnumerable <(byte[] Key, byte[] Value)> Seek(byte[]?key, SeekDirection direction) { if (disposed || db.Handle == IntPtr.Zero) { throw new ObjectDisposedException(nameof(RocksDbStore)); } return(db.Seek(columnFamily, key, direction, readOptions)); }
private void StepForwardButton_Clicked(object sender, RoutedEventArgs e) { _isLeftMouseDown = true; _seekDirection = SeekDirection.Forward; if (!_myDispatcherTimer.IsEnabled) { _myDispatcherTimer.Start(); } }
public virtual void LoadAdjacent(ObjectId adjacentId, SeekDirection seekDirection, int rowCount) { this.contents = this.CreateListViewContents(); this.contents.DataSource = this.CreateDataSource(this.contents.Properties); if (!this.contents.DataSource.LoadAdjacent(adjacentId, seekDirection, rowCount)) { this.forceRefresh = true; } this.SubscribeForFolderContentChanges(); }
/// <summary> /// Missle Lock on behavior /// </summary> /// <returns>returns velocity vector facing player</returns> private Vector3 Seek() { Vector3 SeekDirection; SeekDirection = player.transform.position - transform.position; SeekDirection.Normalize(); //Debug.DrawLine(transform.position, SeekDirection); SeekDirection *= 20; SeekDirection.z = 0; return(SeekDirection); }
public IEnumerable <(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) { ByteArrayComparer comparer = direction == SeekDirection.Forward ? ByteArrayComparer.Default : ByteArrayComparer.Reverse; IEnumerable <KeyValuePair <byte[], byte[]> > records = immutableData; if (keyOrPrefix?.Length > 0) { records = records.Where(p => comparer.Compare(p.Key, keyOrPrefix) >= 0); } records = records.OrderBy(p => p.Key, comparer); return(records.Select(p => (p.Key, p.Value))); }
private bool SeekDevice(SeekDirection direction) { this.ReadRegisters(); //Set Seek mode wrap bit this.registers[RadioFM1.REGISTER_POWERCFG] &= 0xFBFF; if (direction == SeekDirection.Backward) { this.registers[RadioFM1.REGISTER_POWERCFG] &= 0xFDFF; //Seek down is the default upon reset } else { this.registers[RadioFM1.REGISTER_POWERCFG] |= 1 << RadioFM1.BIT_SEEKUP; //Set the bit to Seek up } this.registers[RadioFM1.REGISTER_POWERCFG] |= (1 << RadioFM1.BIT_SEEK); //Start Seek this.UpdateRegisters(); //Poll to see if STC is set while (true) { this.ReadRegisters(); if ((this.registers[RadioFM1.REGISTER_STATUSRSSI] & (1 << RadioFM1.BIT_STC)) != 0) { break; } } this.ReadRegisters(); int valueSFBL = this.registers[RadioFM1.REGISTER_STATUSRSSI] & (1 << RadioFM1.BIT_SFBL); this.registers[RadioFM1.REGISTER_POWERCFG] &= 0xFEFF; //Clear the Seek bit after Seek has completed this.UpdateRegisters(); //Wait for the si4703 to clear the STC as well while (true) { this.ReadRegisters(); if ((this.registers[RadioFM1.REGISTER_STATUSRSSI] & (1 << RadioFM1.BIT_STC)) == 0) { break; } } if (valueSFBL > 0) //The bit was set indicating we hit a band limit or failed to find a station { return(false); } return(true); }
private Boolean SeekDevice(SeekDirection direction) { ReadRegisters(); //Set Seek mode wrap bit _shadowRegisters[REGISTER_POWERCFG] &= 0xFBFF; switch (direction) { case SeekDirection.Backward: _shadowRegisters[REGISTER_POWERCFG] &= 0xFDFF; //Seek down is the default upon reset break; default: _shadowRegisters[REGISTER_POWERCFG] |= 1 << BIT_SEEKUP; //Set the bit to Seek up break; } _shadowRegisters[REGISTER_POWERCFG] |= 1 << BIT_SEEK; //Start Seek UpdateRegisters(); // Poll to see if STC is set while (true) { ReadRegisters(); if ((_shadowRegisters[REGISTER_STATUSRSSI] & (1 << BIT_STC)) != 0) { break; } } ReadRegisters(); var valueSfbl = _shadowRegisters[REGISTER_STATUSRSSI] & (1 << BIT_SFBL); _shadowRegisters[REGISTER_POWERCFG] &= 0xFEFF; //Clear the Seek bit after Seek has completed UpdateRegisters(); //Wait for the si4703 to clear the STC as well while (true) { ReadRegisters(); if ((_shadowRegisters[REGISTER_STATUSRSSI] & (1 << BIT_STC)) == 0) { break; } } return(valueSfbl <= 0); }
/// <summary>Tells the radio to Seek in the given direction until it finds a station.</summary> /// <param name="direction">The direction to Seek the radio.</param> /// <remarks>It does wrap around when seeking.</remarks> /// <returns>The Channel that was tuned to or <see cref="INVALID_CHANNEL" /> if no Channel was found.</returns> public double Seek(SeekDirection direction) { this.currentRadioText = "N/A"; if (this.SeekDevice(direction)) { return(this.Channel); } else { return(RadioFM1.INVALID_CHANNEL); } }
public IEnumerable <(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) { if (keyOrPrefix == null) { keyOrPrefix = Array.Empty <byte>(); } byte[] fullKey = keyOrPrefix; using var it = db.NewIterator(defaultFamily, Options.ReadDefault); if (direction == SeekDirection.Forward) { for (it.Seek(fullKey); it.Valid(); it.Next()) { yield return(it.Key()[1..], it.Value());
void Seek(SeekDirection dir) { prevIndex = currentIndex; if (dir == SeekDirection.Forward) { currentIndex = (currentIndex + 1) % clips.Count; } else if (dir == SeekDirection.Backward) { backwards++; currentIndex = trackList[(trackList.Count - 1) - backwards]; //if (currentIndex < 0) currentIndex = clips.Count - 1; } }
// Token: 0x06002E6B RID: 11883 RVA: 0x00109268 File Offset: 0x00107468 private void Refresh(ListView.RenderFlags renderFlags, int startRange, SeekDirection direction) { this.PreRefresh(); if (startRange < 0) { startRange = 0; } ListView listView = this.GetListView(); IListViewDataSource dataSource = this.GetDataSource(listView); this.LoadDataSource(dataSource, startRange, base.UserContext.UserOptions.ViewRowCount, direction); listView.DataSource = dataSource; this.WriteResponse(renderFlags, listView); }
private bool SeekDevice(SeekDirection direction) { this.ReadRegisters(); this.registers[RadioFM1.REGISTER_POWERCFG] &= 0xFBFF; if (direction == SeekDirection.Backward) { this.registers[RadioFM1.REGISTER_POWERCFG] &= 0xFDFF; } else { this.registers[RadioFM1.REGISTER_POWERCFG] |= 1 << RadioFM1.BIT_SEEKUP; } this.registers[RadioFM1.REGISTER_POWERCFG] |= (1 << RadioFM1.BIT_SEEK); this.UpdateRegisters(); while (true) { this.ReadRegisters(); if ((this.registers[RadioFM1.REGISTER_STATUSRSSI] & (1 << RadioFM1.BIT_STC)) != 0) { break; } } this.ReadRegisters(); int valueSFBL = this.registers[RadioFM1.REGISTER_STATUSRSSI] & (1 << RadioFM1.BIT_SFBL); this.registers[RadioFM1.REGISTER_POWERCFG] &= 0xFEFF; this.UpdateRegisters(); while (true) { this.ReadRegisters(); if ((this.registers[RadioFM1.REGISTER_STATUSRSSI] & (1 << RadioFM1.BIT_STC)) == 0) { break; } } if (valueSFBL > 0) { return(false); } return(true); }
public IEnumerable <(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) { ByteArrayComparer comparer = direction == SeekDirection.Forward ? ByteArrayComparer.Default : ByteArrayComparer.Reverse; IEnumerable <KeyValuePair <byte[], byte[]> > records = innerData; if (keyOrPrefix?.Length > 0) { records = records.Where(p => comparer.Compare(p.Key, keyOrPrefix) >= 0); } records = records.OrderBy(p => p.Key, comparer); foreach (var pair in records) { yield return(pair.Key, pair.Value); } }
private void Seek(SeekDirection d) { if (d == SeekDirection.Forward) { currentIndex = (currentIndex + 1) % clips.Count; } else { currentIndex--; if (currentIndex < 0) { currentIndex = clips.Count - 1; } } }
public static MarkupType SeekMarkup(this byte[] array, out long position, SeekDirection direction = SeekDirection.Forward, int offset = 0, int _length = -1) { bool isFwd = (direction != SeekDirection.Forward) ? false : true; short noiseFlag = 0; MarkupType noiseKind = MarkupType.None; MarkupType lastKind = MarkupType.None; if (array.Length > 0) { long length = (_length <= 0 || _length > array.Length) ? array.Length : _length; int arraylength = array.Length; offset += (!isFwd) ? 1 : 0; length -= ((!isFwd) ? 0 : 1); for (int i = offset; i < length; i++) { byte checknoise = 0; if (!isFwd) { checknoise = array[arraylength - i]; } else { checknoise = array[i]; } MarkupType tempKind = MarkupType.None; if (checknoise.IsMarkup(out tempKind)) { lastKind = tempKind; noiseFlag++; } else if (noiseFlag >= 16) { noiseKind = lastKind; position = (!isFwd) ? arraylength - i + 1 : i; return(noiseKind); } else { lastKind = tempKind; noiseFlag = 0; } } } position = (!isFwd && noiseFlag != 0) ? array.Length - noiseFlag + 1 : 0; return(lastKind); }
/// <summary> /// Seeks in a direction for an element using a query /// </summary> /// <param name="query">Item to look for using the query</param> /// <param name="dir">Direction to scroll in</param> private void SeekToElement(Func <AppQuery, AppQuery> query, SeekDirection dir) { if (app.Query(query).Length == 0) { switch (dir) { case SeekDirection.Up: app.ScrollUpTo(query); break; case SeekDirection.Down: app.ScrollDownTo(query); break; } } }
protected DateTime?CalculateEnd(DateTime start, TimeSpan offset, SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode) { if (offset < TimeSpan.Zero) { throw new InvalidOperationException("time span must be positive"); } DateTime?endDate = null; DateTime moment = start; TimeSpan?remaining = offset; Week week = new Week(start, Calendar); // search end date, iteraring week by week while (week != null) { base.IncludePeriods.Clear(); base.IncludePeriods.AddAll(GetAvailableWeekPeriods(week)); endDate = CalculateEnd(moment, remaining.Value, seekDirection, seekBoundaryMode, out remaining); if (endDate != null || !remaining.HasValue) { break; } switch (seekDirection) { case SeekDirection.Forward: week = FindNextWeek(week); if (week != null) { moment = week.Start; } break; case SeekDirection.Backward: week = FindPreviousWeek(week); if (week != null) { moment = week.End; } break; } } return(endDate); }
// ------------------------------------------------------------------------ protected CalendarVisitor(TFilter filter, ITimePeriod limits, SeekDirection seekDirection = SeekDirection.Forward, ITimeCalendar calendar = null) { if (filter == null) { throw new ArgumentNullException("filter"); } if (limits == null) { throw new ArgumentNullException("limits"); } this.filter = filter; this.limits = limits; this.seekDirection = seekDirection; this.calendar = calendar; } // CalendarVisitor
// Token: 0x06002CB1 RID: 11441 RVA: 0x000FA3DC File Offset: 0x000F85DC private void LoadNextOrPrevious(SeekDirection seekDirection) { try { ObjectId adjacentId = (ObjectId)base.GetParameter("AId"); int rowCount = this.GetRowCount(); VirtualListView2 listView = this.GetListView(); listView.LoadAdjacent(adjacentId, seekDirection, rowCount); listView.RenderData(this.Writer); listView.RenderChunk(this.Writer); this.RenderExtraData(listView); } finally { this.EndProcessEvent(); } }
public Day FindDay(Day start, int offset) { if (offset == 0) { return(start); } DaySeekerContext context = new DaySeekerContext(start, offset); SeekDirection visitDirection = SeekDirection; // reverse seek direction if (offset < 0) { visitDirection = (visitDirection == SeekDirection.Forward) ? SeekDirection.Backward : SeekDirection.Forward; } StartDayVisit(start, context, visitDirection); return(context.FoundDay); }
// Token: 0x06002CB2 RID: 11442 RVA: 0x000FA44C File Offset: 0x000F864C private void SeekNextOrPrevious(SeekDirection seekDirection) { try { ObjectId seekRowId = (ObjectId)base.GetParameter("SId"); int rowCount = this.GetRowCount(); VirtualListView2 listView = this.GetListView(); listView.LoadData(seekRowId, seekDirection, rowCount); listView.RenderData(this.Writer); listView.RenderChunk(this.Writer); this.RenderExtraData(listView); if (base.IsParameterSet("nwSel") && (bool)base.GetParameter("nwSel")) { this.RenderNewSelection(listView); } } finally { this.EndProcessEvent(); } }
public void Seek(bool dir) { SeekDirection d = SeekDirection.Forward; if (dir == true) { d = SeekDirection.Forward; } else if (dir == false) { d = SeekDirection.Backward; } if (d == SeekDirection.Forward) { currentIndex = currentIndex + 1; if (currentIndex == questions.Count) { currentIndex = 0; } currentQuestion.text = questions[currentIndex]; if (!currentAnswer.text.Contains(answers[currentIndex])) { currentAnswer.text += System.Environment.NewLine + (currentIndex + 1) + "." + answers[currentIndex]; } } else { currentIndex--; if (currentIndex < 0) { currentIndex = questions.Count - 1; } currentQuestion.text = questions[currentIndex]; if (!currentAnswer.text.Contains(answers[currentIndex])) { currentAnswer.text += System.Environment.NewLine + (currentIndex + 1) + "." + answers[currentIndex]; } } }
public void Seek(bool dir) { SeekDirection d = SeekDirection.Forward; if (dir == true) { d = SeekDirection.Forward; } else if (dir == false) { d = SeekDirection.Backward; } if (d == SeekDirection.Forward) { currentIndex = currentIndex + 1; if (currentIndex == images.Count) { currentIndex = 0; } holder.sprite = images[currentIndex]; if (!output.text.Contains(holder.sprite.name)) { output.text += System.Environment.NewLine + (currentIndex + 1) + "." + holder.sprite.name; } } else { currentIndex--; if (currentIndex < 0) { currentIndex = images.Count - 1; } holder.sprite = images[currentIndex]; if (!output.text.Contains(holder.sprite.name)) { output.text += System.Environment.NewLine + (currentIndex + 1) + "." + holder.sprite.name; } } }
protected override IEnumerable <(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPrefix, SeekDirection direction) { return(store.Seek(keyOrPrefix, direction).Select(p => (p.Key.AsSerializable <StorageKey>(), p.Value.AsSerializable <StorageItem>()))); }
// Token: 0x06002085 RID: 8325 RVA: 0x000BC534 File Offset: 0x000BA734 public new void Load(ObjectId seekToObjectId, SeekDirection seekDirection, int itemCount) { ExTraceGlobals.MailCallTracer.TraceDebug((long)this.GetHashCode(), "DumpsterListViewDataSource.Load(ObjectId seekToObjectId, SeekDirection seekDirection, int itemCount)"); if (itemCount < 1) { throw new ArgumentOutOfRangeException("itemCount", "itemCount must be greater than 0"); } if (seekToObjectId == null) { throw new ArgumentNullException("seekToObjectId"); } if (!base.UserHasRightToLoad) { return; } StoreObjectId storeObjectId = Utilities.TryGetStoreId(seekToObjectId) as StoreObjectId; if (storeObjectId == null) { throw new ArgumentException("seekToObjectId could not be converted to a StoreObjectId"); } PropertyDefinition[] requestedProperties = base.GetRequestedProperties(); using (QueryResult queryResult = base.Folder.FolderQuery(FolderQueryFlags.SoftDeleted, null, DumpsterListViewDataSource.folderSortBy, requestedProperties)) { using (QueryResult queryResult2 = base.Folder.ItemQuery(ItemQueryType.SoftDeleted, null, base.SortBy, requestedProperties)) { this.totalCount = queryResult.EstimatedRowCount + queryResult2.EstimatedRowCount; object[][] itemsItemQuery = null; if (this.totalCount != 0) { queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.Id, storeObjectId)); switch (seekDirection) { case SeekDirection.Next: if (this.totalCount < queryResult.CurrentRow + itemCount + 1) { queryResult.SeekToOffset(SeekReference.OriginCurrent, this.totalCount - queryResult.CurrentRow - itemCount); } break; case SeekDirection.Previous: { int offset; if (queryResult.CurrentRow + 1 < itemCount) { offset = -1 * (queryResult.CurrentRow + 1); } else { offset = 1 - itemCount; } queryResult.SeekToOffset(SeekReference.OriginCurrent, offset); break; } } object[][] array = Utilities.FetchRowsFromQueryResult(queryResult, itemCount); if (array.Length > 0) { base.StartRange = queryResult.CurrentRow - array.Length; } itemCount -= array.Length; if (itemCount > 0) { if (array.Length == 0) { queryResult2.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.Id, storeObjectId)); switch (seekDirection) { case SeekDirection.Next: if (queryResult2.EstimatedRowCount < queryResult2.CurrentRow + itemCount + 1) { queryResult2.SeekToOffset(SeekReference.OriginCurrent, queryResult2.EstimatedRowCount - queryResult2.CurrentRow - itemCount); } break; case SeekDirection.Previous: { int offset2; if (queryResult2.CurrentRow + 1 < itemCount) { offset2 = -1 * (queryResult2.CurrentRow + 1); int num = itemCount - queryResult2.CurrentRow; int estimatedRowCount = queryResult.EstimatedRowCount; if (num > estimatedRowCount) { num = estimatedRowCount; } queryResult.SeekToOffset(SeekReference.OriginCurrent, -1 * num); array = Utilities.FetchRowsFromQueryResult(queryResult, num); } else { offset2 = 1 - itemCount; } queryResult.SeekToOffset(SeekReference.OriginCurrent, offset2); break; } } } itemsItemQuery = Utilities.FetchRowsFromQueryResult(queryResult2, itemCount); } this.CombineView(array, itemsItemQuery, queryResult, queryResult2); } } } }
/// <summary> /// <paramref name="start"/>시각으로부터 <paramref name="offset"/> 만큼 떨어진 시각을 구합니다. /// </summary> /// <param name="start">기준 시각</param> /// <param name="offset">기간</param> /// <param name="seekDirection">검색 방향 (이전|이후)</param> /// <param name="seekBoundaryMode">검색 값 포함 여부</param> /// <returns>기준 시각으로터 오프셋만큼 떨어진 시각</returns> protected DateTime? CalculateEnd(DateTime start, TimeSpan offset, SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode) { if(IsDebugEnabled) log.Debug("기준시각으로부터 오프셋만큼 떨어진 시각을 구합니다... " + @"start=[{0}], offset=[{1}], seekDirection=[{2}], seekBoundaryMode=[{3}], Calendar=[{4}]", start, offset, seekDirection, seekBoundaryMode, TimeCalendar); Guard.Assert(offset >= TimeSpan.Zero, "offset 값은 TimeSpan.Zero 이상이어야 합니다. offset=[{0}]", offset); DateTime? end = null; DateTime moment = start; TimeSpan? remaining = offset; var week = new WeekRange(start, TimeCalendar); while(week != null) { base.IncludePeriods.Clear(); base.IncludePeriods.AddAll(GetAvailableWeekPeriods(week)); if(IsDebugEnabled) log.Debug("가능한 기간은=[{0}]", base.IncludePeriods.CollectionToString()); end = CalculateEnd(moment, remaining.Value, seekDirection, seekBoundaryMode, out remaining); if(end != null || remaining.HasValue == false) break; if(seekDirection == SeekDirection.Forward) { week = FindNextWeek(week); if(week != null) moment = week.Start; } else { week = FindPreviousWeek(week); if(week != null) moment = week.End; } } if(IsDebugEnabled) log.Debug("기준시각으로부터 오프셋만큼 떨어진 시각을 구했습니다!!! " + @"start=[{0}], offset=[{1}], seekDirection=[{2}], seekBoundaryMode=[{3}], Calendar=[{4}], end=[{5}], remaining=[{6}]", start, offset, seekDirection, seekBoundaryMode, TimeCalendar, end, remaining); return end; }
// ---------------------------------------------------------------------- protected DateTime? CalculateEnd( DateTime start, TimeSpan offset, SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode, out TimeSpan? remaining) { if ( offset < TimeSpan.Zero ) { throw new InvalidOperationException( "time span must be positive" ); } remaining = offset; // search periods TimePeriodCollection searchPeriods = new TimePeriodCollection( includePeriods ); // no search periods specified: search anytime if ( searchPeriods.Count == 0 ) { searchPeriods.Add( TimeRange.Anytime ); } // available periods ITimePeriodCollection availablePeriods = new TimePeriodCollection(); // no exclude periods specified: use all search periods if ( excludePeriods.Count == 0 ) { availablePeriods.AddAll( searchPeriods ); } else // remove exclude periods { TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<TimeRange>(); foreach ( ITimePeriod searchPeriod in searchPeriods ) { // no overlaps: use the entire search range if ( !excludePeriods.HasOverlapPeriods( searchPeriod ) ) { availablePeriods.Add( searchPeriod ); } else // add gaps of search period using the exclude periods { availablePeriods.AddAll( gapCalculator.GetGaps( excludePeriods, searchPeriod ) ); } } } // no periods available if ( availablePeriods.Count == 0 ) { return null; } // combine the available periods, ensure no overlapping // used for FindNextPeriod/FindPreviousPeriod if ( availablePeriods.Count > 1 ) { TimePeriodCombiner<TimeRange> periodCombiner = new TimePeriodCombiner<TimeRange>(); availablePeriods = periodCombiner.CombinePeriods( availablePeriods ); } // find the starting search period ITimePeriod startPeriod = null; DateTime seekMoment = start; switch ( seekDirection ) { case SeekDirection.Forward: startPeriod = FindNextPeriod( start, availablePeriods, out seekMoment ); break; case SeekDirection.Backward: startPeriod = FindPreviousPeriod( start, availablePeriods, out seekMoment ); break; } // no starting period available if ( startPeriod == null ) { return null; } // no offset: use the search staring position // maybe moved to the next available search period if ( offset == TimeSpan.Zero ) { return seekMoment; } // setup destination search switch ( seekDirection ) { case SeekDirection.Forward: for ( int i = availablePeriods.IndexOf( startPeriod ); i < availablePeriods.Count; i++ ) { ITimePeriod gap = availablePeriods[ i ]; TimeSpan gapRemining = gap.End - seekMoment; bool isTargetPeriod = false; switch ( seekBoundaryMode ) { case SeekBoundaryMode.Fill: isTargetPeriod = gapRemining >= remaining; break; case SeekBoundaryMode.Next: isTargetPeriod = gapRemining > remaining; break; } if ( isTargetPeriod ) { DateTime end = seekMoment + remaining.Value; remaining = null; return end; } remaining = remaining - gapRemining; if ( i == availablePeriods.Count - 1 ) { return null; } seekMoment = availablePeriods[ i + 1 ].Start; // next period } break; case SeekDirection.Backward: for ( int i = availablePeriods.IndexOf( startPeriod ); i >= 0; i-- ) { ITimePeriod gap = availablePeriods[ i ]; TimeSpan gapRemining = seekMoment - gap.Start; bool isTargetPeriod = false; switch ( seekBoundaryMode ) { case SeekBoundaryMode.Fill: isTargetPeriod = gapRemining >= remaining; break; case SeekBoundaryMode.Next: isTargetPeriod = gapRemining > remaining; break; } if ( isTargetPeriod ) { DateTime end = seekMoment - remaining.Value; remaining = null; return end; } remaining = remaining - gapRemining; if ( i == 0 ) { return null; } seekMoment = availablePeriods[ i - 1 ].End; // previous period } break; } return null; }
// ---------------------------------------------------------------------- protected DateTime? CalculateEnd( DateTime start, TimeSpan offset, SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode ) { if ( offset < TimeSpan.Zero ) { throw new InvalidOperationException( "time span must be positive" ); } DateTime? endDate = null; DateTime moment = start; TimeSpan? remaining = offset; Week week = new Week( start, calendar ); // search end date, iteraring week by week while ( week != null ) { base.IncludePeriods.Clear(); base.IncludePeriods.AddAll( GetAvailableWeekPeriods( week ) ); endDate = CalculateEnd( moment, remaining.Value, seekDirection, seekBoundaryMode, out remaining ); if ( endDate != null || !remaining.HasValue ) { break; } switch ( seekDirection ) { case SeekDirection.Forward: week = FindNextWeek( week ); if ( week != null ) { moment = week.Start; } break; case SeekDirection.Backward: week = FindPreviousWeek( week ); if ( week != null ) { moment = week.End; } break; } } return endDate; }
/// <summary> /// <paramref name="start"/>시각으로부터 <paramref name="offset"/> 만큼 떨어진 시각을 구합니다. /// </summary> /// <param name="start">기준 시각</param> /// <param name="offset">기간</param> /// <param name="seekDirection">검색 방향 (이전|이후)</param> /// <param name="seekBoundaryMode">검색 값 포함 여부</param> /// <param name="remaining">짜투리 기간</param> /// <returns>기준 시각으로터 오프셋만큼 떨어진 시각</returns> protected DateTime? CalculateEnd(DateTime start, TimeSpan offset, SeekDirection seekDirection, SeekBoundaryMode seekBoundaryMode, out TimeSpan? remaining) { if(IsDebugEnabled) log.Debug("기준시각으로부터 오프셋만큼 떨어진 시각을 구합니다... " + @"start=[{0}], offset=[{1}], seekDirection=[{2}], seekBoundaryMode=[{3}]", start, offset, seekDirection, seekBoundaryMode); Guard.Assert(offset >= TimeSpan.Zero, "offset 값은 항상 0 이상이어야 합니다. offset=[{0}]", offset); remaining = offset; // search periods ITimePeriodCollection searchPeriods = new TimePeriodCollection(IncludePeriods); if(searchPeriods.Count == 0) searchPeriods.Add(TimeRange.Anytime); // available periods ITimePeriodCollection availablePeriods = new TimePeriodCollection(); if(ExcludePeriods.Count == 0) { availablePeriods.AddAll(searchPeriods); } else { // 예외 기간을 제외합니다. // var gapCalculator = new TimeGapCalculator<TimeRange>(); var query = searchPeriods #if !SILVERLIGHT .AsParallel() .AsOrdered() #endif .SelectMany(searchPeriod => ExcludePeriods.HasOverlapPeriods(searchPeriod) ? gapCalculator.GetGaps(ExcludePeriods, searchPeriod) // 예외 기간과 검색 기간에서 겹치지 않는 기간을 계산하여, 추려냅니다. : new TimePeriodCollection { searchPeriod } // 예외 기간과 겹쳐진 부분이 없다면, 기간 전체를 추가합니다. ); availablePeriods.AddAll(query); } // 유효한 Period가 없다면 중단합니다. if(availablePeriods.Count == 0) return null; // 기간중에 중복되는 부분의 없도록 유효한 기간을 결합합니다. if(availablePeriods.Count > 1) { var periodCombiner = new TimePeriodCombiner<TimeRange>(); availablePeriods = periodCombiner.CombinePeriods(availablePeriods); } // 첫 시작 기간을 찾습니다. // DateTime seekMoment; var startPeriod = (seekDirection == SeekDirection.Forward) ? FindNextPeriod(start, availablePeriods, out seekMoment) : FindPreviousPeriod(start, availablePeriods, out seekMoment); // 첫 시작 기간이 없다면 중단합니다. if(startPeriod == null) return null; // 오프셋 값이 0 이라면, 바로 다음 값이므로 seekMoment를 반환합니다. if(offset == TimeSpan.Zero) return seekMoment; if(seekDirection == SeekDirection.Forward) { for(var i = availablePeriods.IndexOf(startPeriod); i < availablePeriods.Count; i++) { var gap = availablePeriods[i]; var gapRemaining = gap.End - seekMoment; if(IsDebugEnabled) log.Debug("Seek Forward... gap=[{0}], gapRemaining=[{1}], remaining=[{2}], seekMoment=[{3}]", gap, gapRemaining, remaining, seekMoment); var isTargetPeriod = (seekBoundaryMode == SeekBoundaryMode.Fill) ? gapRemaining >= remaining : gapRemaining > remaining; if(isTargetPeriod) { var end = seekMoment + remaining.Value; remaining = null; return end; } remaining = remaining - gapRemaining; if(i == availablePeriods.Count - 1) return null; seekMoment = availablePeriods[i + 1].Start; // next period } } else { for(var i = availablePeriods.IndexOf(startPeriod); i >= 0; i--) { var gap = availablePeriods[i]; var gapRemaining = seekMoment - gap.Start; if(IsDebugEnabled) log.Debug("Seek Backward... gap=[{0}], gapRemaining=[{1}], remaining=[{2}], seekMoment=[{3}]", gap, gapRemaining, remaining, seekMoment); var isTargetPeriod = (seekBoundaryMode == SeekBoundaryMode.Fill) ? gapRemaining >= remaining : gapRemaining > remaining; if(isTargetPeriod) { var end = seekMoment - remaining.Value; remaining = null; return end; } remaining = remaining - gapRemaining; if(i == 0) return null; seekMoment = availablePeriods[i - 1].End; // previous period } } return null; }