-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4e1a24
commit 366c21a
Showing
12 changed files
with
214 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...ta.SqlClient/netcore/src/Microsoft/Data/Reliability/Common/ISqlRetryIntervalEnumerator.cs
This file was deleted.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
...SqlClient/netcore/src/Microsoft/Data/Reliability/Common/SqlRetryIntervalBaseEnumerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Data.SqlClient | ||
{ | ||
/// <summary> | ||
/// Generates a sequence of the time intervals. | ||
/// </summary> | ||
public abstract class SqlRetryIntervalBaseEnumerator : IEnumerator<TimeSpan> | ||
{ | ||
/// <summary> | ||
/// The gap time of each interval | ||
/// </summary> | ||
public TimeSpan GapTimeInterval { get; protected set; } | ||
|
||
/// <summary> | ||
/// Maximum time interval value. | ||
/// </summary> | ||
public TimeSpan MaxTimeInterval { get; protected set; } | ||
|
||
/// <summary> | ||
/// Minimum time interval value. | ||
/// </summary> | ||
public TimeSpan MinTimeInterval { get; protected set; } | ||
|
||
/// <summary> | ||
/// Gets the element in the collection at the current position of the enumerator. | ||
/// </summary> | ||
public TimeSpan Current { get; private set; } = TimeSpan.Zero; | ||
|
||
object IEnumerator.Current => Current; | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public SqlRetryIntervalBaseEnumerator() | ||
{ | ||
GapTimeInterval = TimeSpan.Zero; | ||
MaxTimeInterval = TimeSpan.Zero; | ||
MinTimeInterval = TimeSpan.Zero; | ||
} | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public SqlRetryIntervalBaseEnumerator(TimeSpan timeInterval, TimeSpan maxTime, TimeSpan minTime) | ||
{ | ||
Validate(timeInterval, maxTime, minTime); | ||
GapTimeInterval = timeInterval; | ||
MaxTimeInterval = maxTime; | ||
MinTimeInterval = minTime; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the enumerator to its initial position, which is before the first element in the collection. | ||
/// </summary> | ||
public virtual void Reset() | ||
{ | ||
Current = TimeSpan.Zero; | ||
} | ||
|
||
/// <summary> | ||
/// Validate the enumeration parameters. | ||
/// </summary> | ||
/// <param name="timeInterval">The gap time of each interval</param> | ||
/// <param name="maxTimeInterval">Maximum time interval value.</param> | ||
/// <param name="minTimeInterval">Minimum time interval value.</param> | ||
protected virtual void Validate(TimeSpan timeInterval, TimeSpan maxTimeInterval, TimeSpan minTimeInterval) | ||
{ | ||
// valid time iterval must be between 0 and 2 minutes | ||
// TODO: grab the localized messages from the resource file | ||
if(timeInterval.TotalMinutes > 2) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(timeInterval)); | ||
} | ||
else if (maxTimeInterval < minTimeInterval) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(maxTimeInterval)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Calculate the next interval time. | ||
/// </summary> | ||
/// <returns>Next time interval</returns> | ||
protected abstract TimeSpan GetNextInterval(); | ||
|
||
/// <summary> | ||
/// Advances the enumerator to the next element of the collection. | ||
/// </summary> | ||
/// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns> | ||
public virtual bool MoveNext() | ||
{ | ||
TimeSpan next = Current; | ||
if (Current < MaxTimeInterval) | ||
{ | ||
next = GetNextInterval(); | ||
} | ||
|
||
bool result = next <= MaxTimeInterval; | ||
if (result) | ||
{ | ||
Current = next; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | ||
/// </summary> | ||
public virtual void Dispose() | ||
{ | ||
} | ||
} | ||
} |
78 changes: 0 additions & 78 deletions
78
...ata.SqlClient/netcore/src/Microsoft/Data/Reliability/Common/SqlRetryIntervalEnumerator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.