Skip to content

Commit 0f47fb7

Browse files
authored
remove valuetuple and valuetask dependencies (#3892)
* remove valuetuple and valuetask dependencies * remove commented code
1 parent bb190d8 commit 0f47fb7

File tree

17 files changed

+99
-79
lines changed

17 files changed

+99
-79
lines changed

build/Elasticsearch.Net.nuspec

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
<dependency id="System.Buffers" version="[4.5.0,)"/>
2121
<dependency id="System.Reflection.Emit" version="[4.3.0,)"/>
2222
<dependency id="System.Reflection.Emit.Lightweight" version="[4.3.0,)"/>
23-
<dependency id="System.Threading.Tasks.Extensions" version="[4.4.0,)"/>
24-
<dependency id="System.ValueTuple" version="[4.4.0,)"/>
2523
</group>
2624
<group targetFramework="net461">
2725
<dependency id="System.Buffers" version="[4.5.0,)"/>
28-
<dependency id="System.Threading.Tasks.Extensions" version="[4.4.0,)"/>
29-
<dependency id="System.ValueTuple" version="[4.4.0,)"/>
3026
</group>
3127
</dependencies>
3228
</metadata>

src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
using System.ComponentModel;
66
using System.Diagnostics;
77
using System.Diagnostics.CodeAnalysis;
8+
#if DOTNETCORE
89
using System.Net.Http;
10+
using System.Runtime.InteropServices;
11+
#endif
912
using System.Net.Security;
1013
using System.Reflection;
11-
using System.Runtime.InteropServices;
1214
using System.Security;
1315
using System.Security.Cryptography.X509Certificates;
1416
using System.Threading;
@@ -21,7 +23,11 @@ namespace Elasticsearch.Net
2123
/// </summary>
2224
public class ConnectionConfiguration : ConnectionConfiguration<ConnectionConfiguration>
2325
{
26+
#if DOTNETCORE
2427
private static bool IsCurlHandler { get; } = typeof(HttpClientHandler).Assembly.GetType("System.Net.Http.CurlHandler") != null;
28+
#else
29+
private static bool IsCurlHandler { get; } = false;
30+
#endif
2531

2632
/// <summary>
2733
/// The default ping timeout. Defaults to 2 seconds
@@ -41,9 +47,10 @@ public class ConnectionConfiguration : ConnectionConfiguration<ConnectionConfigu
4147
public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(1);
4248

4349
/// <summary>
44-
/// The default connection limit for both Elasticsearch.Net and Nest. Defaults to <c>80</c> except for
45-
/// <see cref="HttpClientHandler"/> implementations based on curl, which defaults to
46-
/// <see cref="Environment.ProcessorCount"/>
50+
/// The default connection limit for both Elasticsearch.Net and Nest. Defaults to <c>80</c>
51+
#if DOTNETCORE
52+
/// <para>Except for <see cref="HttpClientHandler"/> implementations based on curl, which defaults to <see cref="Environment.ProcessorCount"/></para>
53+
#endif
4754
/// </summary>
4855
public static readonly int DefaultConnectionLimit = IsCurlHandler ? Environment.ProcessorCount : 80;
4956

src/Elasticsearch.Net/Connection/Content/RequestDataContent.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// modified to be dedicated for RequestData only
55

6+
#if DOTNETCORE
67
using System;
78
using System.Diagnostics.CodeAnalysis;
89
using System.Diagnostics.Contracts;
@@ -18,22 +19,22 @@ namespace Elasticsearch.Net
1819
{
1920
/// <summary>
2021
/// Provides an <see cref="HttpContent"/> implementation that exposes an output <see cref="Stream"/>
21-
/// which can be written to directly. The ability to push data to the output stream differs from the
22+
/// which can be written to directly. The ability to push data to the output stream differs from the
2223
/// <see cref="StreamContent"/> where data is pulled and not pushed.
2324
/// </summary>
2425
internal class RequestDataContent : HttpContent
2526
{
2627
private readonly RequestData _requestData;
2728
private readonly Func<PostData, CompleteTaskOnCloseStream, RequestDataContent, TransportContext, Task> _onStreamAvailable;
28-
29-
29+
30+
3031
public RequestDataContent(RequestData requestData)
3132
{
3233
_requestData = requestData;
3334
Headers.ContentType = new MediaTypeHeaderValue(requestData.RequestMimeType);
3435
if (requestData.HttpCompression)
3536
Headers.ContentEncoding.Add("gzip");
36-
37+
3738
Task OnStreamAvailable(PostData data, Stream stream, HttpContent content, TransportContext context)
3839
{
3940
using(stream)
@@ -58,8 +59,8 @@ async Task OnStreamAvailable(PostData data, Stream stream, HttpContent content,
5859
}
5960

6061
/// <summary>
61-
/// When this method is called, it calls the action provided in the constructor with the output
62-
/// stream to write to. Once the action has completed its work it closes the stream which will
62+
/// When this method is called, it calls the action provided in the constructor with the output
63+
/// stream to write to. Once the action has completed its work it closes the stream which will
6364
/// close this content instance and complete the HTTP request or response.
6465
/// </summary>
6566
/// <param name="stream">The <see cref="Stream"/> to which to write.</param>
@@ -68,7 +69,7 @@ async Task OnStreamAvailable(PostData data, Stream stream, HttpContent content,
6869
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exception is passed as task result.")]
6970
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
7071
{
71-
72+
7273
var data = _requestData.PostData;
7374
if (data == null) return;
7475

@@ -109,7 +110,7 @@ protected override void Dispose(bool disposing)
109110
_serializeToStreamTask.TrySetResult(true);
110111
base.Dispose();
111112
}
112-
113+
113114

114115
public override void Close() => _serializeToStreamTask.TrySetResult(true);
115116
}
@@ -195,3 +196,4 @@ public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, As
195196
}
196197
}
197198
}
199+
#endif
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
2+
using System.Collections.Generic;
23

3-
namespace Elasticsearch.Net.Diagnostics
4+
namespace Elasticsearch.Net.Diagnostics
45
{
56
/// <summary> Provides a typed listener to <see cref="AuditEvent"/> events that <see cref="RequestPipeline"/> emits </summary>
67
public class AuditDiagnosticObserver : TypedDiagnosticObserverBase<Audit>
78
{
89
public AuditDiagnosticObserver(
9-
Action<(string EventName, Audit Audit)> onNext,
10+
Action<KeyValuePair<string, Audit>> onNext,
1011
Action<Exception> onError = null,
1112
Action onCompleted = null
1213
) : base(onNext, onError, onCompleted) { }
1314
}
14-
}
15+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace Elasticsearch.Net.Diagnostics
4+
namespace Elasticsearch.Net.Diagnostics
55
{
66
/// <summary> Provides a typed listener to the events that <see cref="HttpConnection"/> emits </summary>
77
public class HttpConnectionDiagnosticObserver : TypedDiagnosticObserverBase<RequestData, int?>
88
{
99
public HttpConnectionDiagnosticObserver(
10-
Action<(string EventName, RequestData RequestData)> onNextStart,
11-
Action<(string EventName, int? StatusCode)> onNextEnd,
10+
Action<KeyValuePair<string, RequestData>> onNextStart,
11+
Action<KeyValuePair<string, int?>> onNextEnd,
1212
Action<Exception> onError = null,
1313
Action onCompleted = null
1414
) : base(onNextStart, onNextEnd, onError, onCompleted) { }
1515

1616
}
17-
}
17+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System;
2+
using System.Collections.Generic;
23

3-
namespace Elasticsearch.Net.Diagnostics
4+
namespace Elasticsearch.Net.Diagnostics
45
{
56
/// <summary> Provides a typed listener to actions that <see cref="RequestPipeline"/> takes e.g sniff, ping, or making an API call </summary>
67
public class RequestPipelineDiagnosticObserver : TypedDiagnosticObserverBase<RequestData, IApiCallDetails>
78
{
89
public RequestPipelineDiagnosticObserver(
9-
Action<(string EventName, RequestData RequestData)> onNextStart,
10-
Action<(string EventName, IApiCallDetails Response)> onNextEnd,
10+
Action<KeyValuePair<string, RequestData>> onNextStart,
11+
Action<KeyValuePair<string, IApiCallDetails>> onNextEnd,
1112
Action<Exception> onError = null,
1213
Action onCompleted = null
1314
) : base(onNextStart, onNextEnd, onError, onCompleted) { }
1415

1516
}
16-
}
17+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
2+
using System.Collections.Generic;
23

3-
namespace Elasticsearch.Net.Diagnostics
4+
namespace Elasticsearch.Net.Diagnostics
45
{
56
/// <summary> Provides a typed listener any time an <see cref="IElasticsearchSerializer"/> does a write or read</summary>
67
public class SerializerDiagnosticObserver : TypedDiagnosticObserverBase<SerializerRegistrationInformation>
78
{
89
public SerializerDiagnosticObserver(
9-
Action<(string EventName, SerializerRegistrationInformation Registration)> onNext,
10+
Action<KeyValuePair<string, SerializerRegistrationInformation>> onNext,
1011
Action<Exception> onError = null,
1112
Action onCompleted = null
1213
) : base(onNext, onError, onCompleted) { }
1314
}
14-
}
15+
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace Elasticsearch.Net.Diagnostics
4+
namespace Elasticsearch.Net.Diagnostics
55
{
66
public abstract class TypedDiagnosticObserverBase<TOnNext> : IObserver<KeyValuePair<string, object>>
77
{
8-
private readonly Action<(string EventName, TOnNext EventData)> _onNext;
8+
private readonly Action<KeyValuePair<string, TOnNext>> _onNext;
99
private readonly Action<Exception> _onError;
1010
private readonly Action _onCompleted;
1111

1212
protected TypedDiagnosticObserverBase(
13-
Action<(string EventName, TOnNext RequestData)> onNext,
13+
Action<KeyValuePair<string, TOnNext>> onNext,
1414
Action<Exception> onError = null,
1515
Action onCompleted = null
1616
)
@@ -19,30 +19,30 @@ protected TypedDiagnosticObserverBase(
1919
_onError = onError;
2020
_onCompleted = onCompleted;
2121
}
22-
22+
2323
void IObserver<KeyValuePair<string, object>>.OnCompleted() => _onCompleted?.Invoke();
2424

2525
void IObserver<KeyValuePair<string, object>>.OnError(Exception error) => _onError?.Invoke(error);
2626

2727
void IObserver<KeyValuePair<string, object>>.OnNext(KeyValuePair<string, object> value)
2828
{
29-
if (value.Value is TOnNext next) _onNext?.Invoke((EventName: value.Key, EventData: next));
30-
else if (value.Value == null) _onNext?.Invoke((EventName: value.Key, EventData: default));
31-
29+
if (value.Value is TOnNext next) _onNext?.Invoke(new KeyValuePair<string, TOnNext>(value.Key, next));
30+
else if (value.Value == null) _onNext?.Invoke(new KeyValuePair<string, TOnNext>(value.Key, default));
31+
3232
else throw new Exception($"{value.Key} received unexpected type {value.Value.GetType()}");
3333

34-
}
34+
}
3535
}
3636
public abstract class TypedDiagnosticObserverBase<TOnNextStart, TOnNextEnd> : IObserver<KeyValuePair<string, object>>
3737
{
38-
private readonly Action<(string EventName, TOnNextStart EventData)> _onNextStart;
39-
private readonly Action<(string EventName, TOnNextEnd EventData)> _onNextEnd;
38+
private readonly Action<KeyValuePair<string, TOnNextStart>> _onNextStart;
39+
private readonly Action<KeyValuePair<string, TOnNextEnd>> _onNextEnd;
4040
private readonly Action<Exception> _onError;
4141
private readonly Action _onCompleted;
4242

4343
protected TypedDiagnosticObserverBase(
44-
Action<(string EventName, TOnNextStart RequestData)> onNextStart,
45-
Action<(string EventName, TOnNextEnd RequestData)> onNextEnd,
44+
Action<KeyValuePair<string, TOnNextStart>> onNextStart,
45+
Action<KeyValuePair<string, TOnNextEnd>> onNextEnd,
4646
Action<Exception> onError = null,
4747
Action onCompleted = null
4848
)
@@ -52,21 +52,21 @@ protected TypedDiagnosticObserverBase(
5252
_onError = onError;
5353
_onCompleted = onCompleted;
5454
}
55-
55+
5656
void IObserver<KeyValuePair<string, object>>.OnCompleted() => _onCompleted?.Invoke();
5757

5858
void IObserver<KeyValuePair<string, object>>.OnError(Exception error) => _onError?.Invoke(error);
5959

6060
void IObserver<KeyValuePair<string, object>>.OnNext(KeyValuePair<string, object> value)
6161
{
62-
if (value.Value is TOnNextStart nextStart) _onNextStart?.Invoke((EventName: value.Key, EventData: nextStart));
63-
else if (value.Key.EndsWith(".Start") && value.Value is null) _onNextStart?.Invoke((EventName: value.Key, EventData: default));
64-
65-
else if (value.Value is TOnNextEnd nextEnd) _onNextEnd?.Invoke((EventName: value.Key, EventData: nextEnd));
66-
else if (value.Key.EndsWith(".Stop") && value.Value is null) _onNextEnd?.Invoke((EventName: value.Key, EventData: default));
67-
62+
if (value.Value is TOnNextStart nextStart) _onNextStart?.Invoke(new KeyValuePair<string, TOnNextStart>(value.Key, nextStart));
63+
else if (value.Key.EndsWith(".Start") && value.Value is null) _onNextStart?.Invoke(new KeyValuePair<string, TOnNextStart>(value.Key, default));
64+
65+
else if (value.Value is TOnNextEnd nextEnd) _onNextEnd?.Invoke(new KeyValuePair<string, TOnNextEnd>(value.Key, nextEnd));
66+
else if (value.Key.EndsWith(".Stop") && value.Value is null) _onNextEnd?.Invoke(new KeyValuePair<string, TOnNextEnd>(value.Key, default));
67+
6868
else throw new Exception($"{value.Key} received unexpected type {value.Value.GetType()}");
6969

70-
}
70+
}
7171
}
72-
}
72+
}

src/Elasticsearch.Net/Elasticsearch.Net.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515

1616
</ItemGroup>
1717
<ItemGroup>
18-
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
19-
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.4.0" />
2018
<PackageReference Include="System.Buffers" Version="4.5.0" />
21-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
19+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
2220

2321
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Reflection.Emit" Version="4.3.0" />
2422
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
25-
26-
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.4.0" />
27-
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
23+
2824
</ItemGroup>
2925
<ItemGroup>
3026
<Compile Update="ElasticLowLevelClient.*.cs">

src/Elasticsearch.Net/Serialization/DiagnosticsSerializerProxy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public class SerializerRegistrationInformation
1414

1515
public SerializerRegistrationInformation(Type type, string purpose)
1616
{
17-
(TypeInformation, Purpose) = (type, purpose);
17+
TypeInformation = type;
18+
Purpose = purpose;
1819
_stringRepresentation = $"{Purpose}: {TypeInformation.FullName}";
1920
}
20-
21+
2122

2223
public Type TypeInformation { get; }
2324

0 commit comments

Comments
 (0)