Skip to content

Commit b42701f

Browse files
committed
minor cleanup
1 parent e2f5e67 commit b42701f

File tree

15 files changed

+135
-37
lines changed

15 files changed

+135
-37
lines changed

src/FluentCommand.SqlServer/Merge/DataMergeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ private static bool NeedQuote(Type type)
443443
return true;
444444
if (underType == typeof(Guid))
445445
return true;
446-
#if !NETSTANDARD2_0
446+
#if NET6_0_OR_GREATER
447447
if (underType == typeof(DateOnly))
448448
return true;
449449
if (underType == typeof(TimeOnly))
@@ -465,7 +465,7 @@ private static string GetValue(object value)
465465
DateTimeOffset dateTimeOffset => dateTimeOffset.ToString("u"),
466466
byte[] byteArray => ToHex(byteArray),
467467
bool boolValue => boolValue ? "1" : "0",
468-
#if !NETSTANDARD2_0
468+
#if NET6_0_OR_GREATER
469469
DateOnly dateValue => dateValue.ToString("yyyy-MM-dd"),
470470
TimeOnly timeValue => timeValue.ToString("hh:mm:ss.ffffff"),
471471
#endif

src/FluentCommand/ConcurrencyToken.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public ConcurrencyToken(byte[] value)
1515

1616
public ConcurrencyToken(string value)
1717
{
18-
#if !NETSTANDARD2_0
18+
#if NET5_0_OR_GREATER
1919
Value = string.IsNullOrEmpty(value) ? Array.Empty<byte>() : Convert.FromHexString(value);
2020
#else
2121
Value = string.IsNullOrEmpty(value) ? Array.Empty<byte>() : FromHexString(value);
@@ -24,7 +24,7 @@ public ConcurrencyToken(string value)
2424

2525
public override string ToString()
2626
{
27-
#if !NETSTANDARD2_0
27+
#if NET5_0_OR_GREATER
2828
return Value != null ? Convert.ToHexString(Value) : null;
2929
#else
3030
return Value != null ? ToHexString(Value) : null;

src/FluentCommand/DataCommand.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System.Data;
22
using System.Data.Common;
3-
using System.Diagnostics;
43

54
using FluentCommand.Extensions;
5+
using FluentCommand.Internal;
66

77
using HashCode = FluentCommand.Internal.HashCode;
88

@@ -162,7 +162,7 @@ public IDataCommand UseCache(DateTimeOffset absoluteExpiration)
162162
/// A fluent <see langword="interface" /> to the data command.
163163
/// </returns>
164164
/// <remarks>
165-
/// Cached keys are created using the current DataCommand state. When any Query opertion is
165+
/// Cached keys are created using the current DataCommand state. When any Query operation is
166166
/// executed with a cache policy, the results are cached. Use this method with the same parameters
167167
/// to expire the cached item.
168168
/// </remarks>
@@ -525,7 +525,7 @@ protected override void DisposeManagedResources()
525525
Command?.Dispose();
526526
}
527527

528-
#if !NETSTANDARD2_0
528+
#if NETCOREAPP3_0_OR_GREATER
529529
/// <summary>
530530
/// Disposes the managed resources.
531531
/// </summary>
@@ -556,12 +556,14 @@ private TResult QueryFactory<TResult>(Func<TResult> query, bool supportCache)
556556

557557
AssertDisposed();
558558

559-
var watch = Stopwatch.StartNew();
559+
var watch = SharedStopwatch.StartNew();
560+
var logged = false;
561+
560562
try
561563
{
562564
var cacheKey = CacheKey<TResult>(supportCache);
563565

564-
(bool cacheSuccess, TResult cacheValue) = GetCache<TResult>(cacheKey);
566+
var (cacheSuccess, cacheValue) = GetCache<TResult>(cacheKey);
565567
if (cacheSuccess)
566568
return cacheValue;
567569

@@ -577,19 +579,16 @@ private TResult QueryFactory<TResult>(Func<TResult> query, bool supportCache)
577579
}
578580
catch (Exception ex)
579581
{
580-
watch.Stop();
581582
LogCommand(watch.Elapsed, ex);
583+
logged = true;
582584

583585
throw;
584586
}
585587
finally
586588
{
587589
// if catch block didn't already log
588-
if (watch.IsRunning)
589-
{
590-
watch.Stop();
590+
if (!logged)
591591
LogCommand(watch.Elapsed);
592-
}
593592

594593
_dataSession.ReleaseConnection();
595594
Dispose();
@@ -606,12 +605,14 @@ private async Task<TResult> QueryFactoryAsync<TResult>(
606605

607606
AssertDisposed();
608607

609-
var watch = Stopwatch.StartNew();
608+
var watch = SharedStopwatch.StartNew();
609+
var logged = false;
610+
610611
try
611612
{
612613
var cacheKey = CacheKey<TResult>(supportCache);
613614

614-
(bool cacheSuccess, TResult cacheValue) = await GetCacheAsync<TResult>(cacheKey, cancellationToken).ConfigureAwait(false);
615+
var (cacheSuccess, cacheValue) = await GetCacheAsync<TResult>(cacheKey, cancellationToken).ConfigureAwait(false);
615616
if (cacheSuccess)
616617
return cacheValue;
617618

@@ -627,22 +628,25 @@ private async Task<TResult> QueryFactoryAsync<TResult>(
627628
}
628629
catch (Exception ex)
629630
{
630-
watch.Stop();
631631
LogCommand(watch.Elapsed, ex);
632+
logged = true;
632633

633634
throw;
634635
}
635636
finally
636637
{
637638
// if catch block didn't already log
638-
if (watch.IsRunning)
639-
{
640-
watch.Stop();
639+
if (!logged)
641640
LogCommand(watch.Elapsed);
642-
}
643641

642+
#if NETCOREAPP3_0_OR_GREATER
643+
644+
await _dataSession.ReleaseConnectionAsync();
645+
await DisposeAsync();
646+
#else
644647
_dataSession.ReleaseConnection();
645648
Dispose();
649+
#endif
646650
}
647651
}
648652

src/FluentCommand/DataMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static DataMapping()
3535
{typeof(ushort), DbType.UInt16},
3636
{typeof(uint), DbType.UInt32},
3737
{typeof(ulong), DbType.UInt64},
38-
#if !NETSTANDARD2_0
38+
#if NET6_0_OR_GREATER
3939
{typeof(DateOnly), DbType.Date},
4040
{typeof(TimeOnly), DbType.Time},
4141
#endif

src/FluentCommand/DataParameterHandlers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static DataParameterHandlers()
1515
_dataTypeHandlers = new ConcurrentDictionary<Type, IDataParameterHandler>();
1616
_dataTypeHandlers.TryAdd(typeof(ConcurrencyToken), new ConcurrencyTokenHandler());
1717

18-
#if !NETSTANDARD2_0
18+
#if NET6_0_OR_GREATER
1919
// once ADO supports DateOnly & TimeOnly, this can be removed
2020
_dataTypeHandlers.TryAdd(typeof(DateOnly), new DateOnlyHandler());
2121
_dataTypeHandlers.TryAdd(typeof(TimeOnly), new TimeOnlyHandler());

src/FluentCommand/DataSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public DbTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationL
124124
return Transaction;
125125
}
126126

127-
#if !NETSTANDARD2_0
127+
#if NETCOREAPP3_0_OR_GREATER
128128
/// <summary>
129129
/// Starts a database transaction with the specified isolation level.
130130
/// </summary>
@@ -237,7 +237,7 @@ public void ReleaseConnection()
237237
_openedConnection = false;
238238
}
239239

240-
#if !NETSTANDARD2_0
240+
#if NETCOREAPP3_0_OR_GREATER
241241
/// <summary>
242242
/// Releases the connection.
243243
/// </summary>

src/FluentCommand/DisposableBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace FluentCommand;
55
/// </summary>
66
public abstract class DisposableBase
77
: IDisposable
8-
#if !NETSTANDARD2_0
8+
#if NETCOREAPP3_0_OR_GREATER
99
, IAsyncDisposable
1010
#endif
1111
{
@@ -65,7 +65,7 @@ protected virtual void DisposeManagedResources()
6565
protected virtual void DisposeUnmanagedResources()
6666
{ }
6767

68-
#if !NETSTANDARD2_0
68+
#if NETCOREAPP3_0_OR_GREATER
6969
/// <summary>
7070
/// Disposes the asynchronous.
7171
/// </summary>

src/FluentCommand/Handlers/DateOnlyHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !NETSTANDARD2_0
1+
#if NET6_0_OR_GREATER
22
using System.Data;
33

44
using FluentCommand;

src/FluentCommand/Handlers/TimeOnlyHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !NETSTANDARD2_0
1+
#if NET6_0_OR_GREATER
22
using System.Data;
33

44
using FluentCommand;

src/FluentCommand/IDataQueryAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace FluentCommand;
66
/// An <see langword="interface"/> defining a data query operations asynchronously.
77
/// </summary>
88
public interface IDataQueryAsync
9-
#if !NETSTANDARD2_0
9+
#if NETCOREAPP3_0_OR_GREATER
1010
: IAsyncDisposable
1111
#endif
1212

0 commit comments

Comments
 (0)