Skip to content

Commit c6aec5d

Browse files
committed
fix Elasticsearch.Net style violations and warnings
(cherry picked from commit 2698710)
1 parent 2c524e0 commit c6aec5d

22 files changed

+93
-93
lines changed

.editorconfig

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,30 @@ csharp_prefer_braces = false:warning
8282
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error
8383

8484
# ---
85-
# formatting conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
85+
# formatting conventions https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions
8686

8787
# Newline settings (Allman yo!)
88-
csharp_new_line_before_open_brace = all:error
89-
csharp_new_line_before_else = true:error
90-
csharp_new_line_before_catch = true:error
91-
csharp_new_line_before_finally = true:error
88+
csharp_new_line_before_open_brace = all
89+
csharp_new_line_before_else = true
90+
csharp_new_line_before_catch = true
91+
csharp_new_line_before_finally = true
9292
csharp_new_line_before_members_in_object_initializers = true
9393
# just a suggestion do to our JSON tests that use anonymous types to
9494
# represent json quite a bit (makes copy paste easier).
95-
csharp_new_line_before_members_in_anonymous_types = true:suggestion
96-
csharp_new_line_between_query_expression_clauses = true:error
95+
csharp_new_line_before_members_in_anonymous_types = true
96+
csharp_new_line_between_query_expression_clauses = true
9797

9898
# Indent
99-
csharp_indent_case_contents = true:error
100-
csharp_indent_switch_labels = true:error
101-
csharp_space_after_cast = false:error
102-
csharp_space_after_keywords_in_control_flow_statements = true:error
103-
csharp_space_between_method_declaration_parameter_list_parentheses = false:error
104-
csharp_space_between_method_call_parameter_list_parentheses = false:error
99+
csharp_indent_case_contents = true
100+
csharp_indent_switch_labels = true
101+
csharp_space_after_cast = false
102+
csharp_space_after_keywords_in_control_flow_statements = true
103+
csharp_space_between_method_declaration_parameter_list_parentheses = false
104+
csharp_space_between_method_call_parameter_list_parentheses = false
105105

106106
#Wrap
107-
csharp_preserve_single_line_statements = false:error
108-
csharp_preserve_single_line_blocks = true:error
107+
csharp_preserve_single_line_statements = false
108+
csharp_preserve_single_line_blocks = true
109109

110110
# Resharper
111111
resharper_csharp_braces_for_lock=required_for_complex
@@ -118,6 +118,5 @@ resharper_csharp_braces_for_ifelse=required_for_complex
118118

119119
resharper_csharp_accessor_owner_body=expression_body
120120

121-
122121
resharper_redundant_case_label_highlighting=do_not_show
123-
122+
resharper_redundant_argument_default_value_highlighting=do_not_show

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
<DefineConstants Condition="'$(TargetFramework)'=='net461' or '$(TargetFramework)'=='net472'">$(DefineConstants);FULLFRAMEWORK</DefineConstants>
3737
<DefineConstants Condition="$(DefineConstants.Contains(FULLFRAMEWORK)) == False">$(DefineConstants);DOTNETCORE</DefineConstants>
38+
<DefineConstants Condition="$(DefineConstants.Contains(FULLFRAMEWORK)) == False and '$(TargetFramework)'!='netstandard2.0'">$(DefineConstants);DOTNETCORE_2_1_OR_HIGHER</DefineConstants>
3839

3940
<ExposedPublicKey>002400000480000094000000060200000024000052534131000400000100010025d3a22bf3781ba85067374ad832dfcba3c4fa8dd89227e36121ba17b2c33ad6b6ce03e45e562050a031e2ff7fe12cff9060a50acbc6a0eef9ef32dc258d90f874b2e76b581938071ccc4b4d98204d1d6ca7a1988d7a211f9fc98efd808cf85f61675b11007d0eb0461dc86a968d6af8ebba7e6b540303b54f1c1f5325c252be</ExposedPublicKey>
4041
</PropertyGroup>

src/Elasticsearch.Net/Api/NativeMethods.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ internal static string RtlGetVersion()
1919
{
2020
var osvi = new RTL_OSVERSIONINFOEX();
2121
osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi);
22-
if (RtlGetVersion(out osvi) == 0)
23-
return $"Microsoft Windows {osvi.dwMajorVersion}.{osvi.dwMinorVersion}.{osvi.dwBuildNumber}";
24-
25-
return null;
22+
return RtlGetVersion(out osvi) == 0
23+
? $"Microsoft Windows {osvi.dwMajorVersion}.{osvi.dwMinorVersion}.{osvi.dwBuildNumber}"
24+
: null;
2625
}
2726

2827
[StructLayout(LayoutKind.Sequential)]
28+
// ReSharper disable once MemberCanBePrivate.Global
29+
// ReSharper disable InconsistentNaming
30+
// ReSharper disable FieldCanBeMadeReadOnly.Global
2931
internal struct RTL_OSVERSIONINFOEX
3032
{
3133
internal uint dwOSVersionInfoSize;
@@ -37,6 +39,8 @@ internal struct RTL_OSVERSIONINFOEX
3739
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
3840
internal string szCSDVersion;
3941
}
42+
// ReSharper restore InconsistentNaming
43+
// ReSharper restore FieldCanBeMadeReadOnly.Global
4044
}
4145
}
4246
}

src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
202202
private bool _transferEncodingChunked;
203203
private IMemoryStreamFactory _memoryStreamFactory = RecyclableMemoryStreamFactory.Default;
204204
private bool _enableTcpStats;
205+
//public static IMemoryStreamFactory Default { get; } = RecyclableMemoryStreamFactory.Default;
206+
public static IMemoryStreamFactory DefaultMemoryStreamFactory { get; } = Elasticsearch.Net.MemoryStreamFactory.Default;
205207
private bool _enableThreadPoolStats;
206208

207209
private string _userAgent = ConnectionConfiguration.DefaultUserAgent;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,7 @@ public override int WriteTimeout
155155

156156
protected override void Dispose(bool disposing)
157157
{
158-
if (disposing)
159-
{
160-
_innerStream.Dispose();
161-
}
158+
if (disposing) _innerStream.Dispose();
162159
base.Dispose(disposing);
163160
}
164161

src/Elasticsearch.Net/Connection/HandlerTracking/RequestDataHttpClientFactory.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
#if DOTNETCORE
66
using System;
77
using System.Collections.Concurrent;
8-
using System.Collections.Generic;
98
using System.Diagnostics;
10-
using System.Linq;
119
using System.Net.Http;
1210
using System.Threading;
13-
using System.Xml;
14-
using Elasticsearch.Net;
1511

1612
namespace Elasticsearch.Net
1713
{
@@ -129,6 +125,7 @@ private void ExpiryTimer_Tick(object state)
129125
if (removed)
130126
Interlocked.Increment(ref _removedHandlers);
131127
Debug.Assert(removed, "Entry not found. We should always be able to remove the entry");
128+
// ReSharper disable once RedundantNameQualifier
132129
Debug.Assert(object.ReferenceEquals(active, found.Value), "Different entry found. The entry should not have been replaced");
133130

134131
// At this point the handler is no longer 'active' and will not be handed out to any new clients.
@@ -205,12 +202,10 @@ private void CleanupTimer_Tick()
205202
// ignored (ignored in HttpClientFactory too)
206203
}
207204
}
205+
// If the entry is still live, put it back in the queue so we can process it
206+
// during the next cleanup cycle.
208207
else
209-
{
210-
// If the entry is still live, put it back in the queue so we can process it
211-
// during the next cleanup cycle.
212208
_expiredHandlers.Enqueue(entry);
213-
}
214209
}
215210
}
216211
finally

src/Elasticsearch.Net/Connection/HandlerTracking/ValueStopWatch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#if DOTNETCORE
66
using System;
7-
using System.Diagnostics;
87
using System.Threading;
98

109
namespace Elasticsearch.Net

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#if DOTNETCORE
66
using System;
7-
using System.Collections.Concurrent;
87
using System.Collections.Generic;
98
using System.Collections.ObjectModel;
109
using System.Diagnostics;
@@ -63,7 +62,7 @@ public virtual TResponse Request<TResponse>(RequestData requestData)
6362
where TResponse : class, IElasticsearchResponse, new()
6463
{
6564
var client = GetClient(requestData);
66-
HttpResponseMessage responseMessage = null;
65+
HttpResponseMessage responseMessage;
6766
int? statusCode = null;
6867
IEnumerable<string> warnings = null;
6968
Stream responseStream = null;
@@ -130,7 +129,7 @@ public virtual async Task<TResponse> RequestAsync<TResponse>(RequestData request
130129
where TResponse : class, IElasticsearchResponse, new()
131130
{
132131
var client = GetClient(requestData);
133-
HttpResponseMessage responseMessage = null;
132+
HttpResponseMessage responseMessage;
134133
int? statusCode = null;
135134
IEnumerable<string> warnings = null;
136135
Stream responseStream = null;
@@ -261,7 +260,7 @@ protected virtual void SetAuthenticationIfNeeded(HttpRequestMessage requestMessa
261260
var header = AuthenticationHeaderValue.Parse(requestData.Headers["Authorization"]);
262261
requestMessage.Headers.Authorization = header;
263262
return;
264-
};
263+
}
265264

266265
// Api Key authentication takes precedence
267266
var apiKeySet = SetApiKeyAuthenticationIfNeeded(requestMessage, requestData);
@@ -339,9 +338,7 @@ protected virtual HttpRequestMessage CreateRequestMessage(RequestData requestDat
339338
private static void SetContent(HttpRequestMessage message, RequestData requestData)
340339
{
341340
if (requestData.TransferEncodingChunked)
342-
{
343341
message.Content = new RequestDataContent(requestData);
344-
}
345342
else
346343
{
347344
var stream = requestData.MemoryStreamFactory.Create();
@@ -373,9 +370,7 @@ private static void SetContent(HttpRequestMessage message, RequestData requestDa
373370
private static async Task SetContentAsync(HttpRequestMessage message, RequestData requestData, CancellationToken cancellationToken)
374371
{
375372
if (requestData.TransferEncodingChunked)
376-
{
377373
message.Content = new RequestDataContent(requestData, cancellationToken);
378-
}
379374
else
380375
{
381376
var stream = requestData.MemoryStreamFactory.Create();
@@ -389,7 +384,12 @@ private static async Task SetContentAsync(HttpRequestMessage message, RequestDat
389384
if (requestData.PostData.DisableDirectStreaming.GetValueOrDefault(false) && !requestData.HttpCompression)
390385
{
391386
message.Content = new ByteArrayContent(requestData.PostData.WrittenBytes);
392-
stream.Dispose();
387+
#if DOTNETCORE_2_1_OR_HIGHER
388+
await stream.DisposeAsync().ConfigureAwait(false);
389+
390+
#else
391+
stream.Dispose();
392+
#endif
393393
}
394394
else
395395
{

src/Elasticsearch.Net/Connection/HttpWebRequestConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ CancellationToken cancellationToken
118118
if (data != null)
119119
{
120120
var apmGetRequestStreamTask =
121-
Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream, r => request.EndGetRequestStream(r), null);
121+
Task.Factory.FromAsync(request.BeginGetRequestStream, r => request.EndGetRequestStream(r), null);
122122
unregisterWaitHandle = RegisterApmTaskTimeout(apmGetRequestStreamTask, request, requestData);
123123

124124
using (var stream = await apmGetRequestStreamTask.ConfigureAwait(false))

src/Elasticsearch.Net/ConnectionPool/CloudConnectionPool.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66
using System.Text;
77

8-
namespace Elasticsearch.Net
8+
namespace Elasticsearch.Net
99
{
1010
/// <summary>
1111
/// An <see cref="IConnectionPool"/> implementation that can be seeded with a cloud id
@@ -64,8 +64,9 @@ private CloudConnectionPool(ParsedCloudId parsedCloudId, IDateTimeProvider dateT
6464
ClusterName = parsedCloudId.Name;
6565

6666
//TODO implement debugger display for IConnectionPool implementations and display it there and its ToString()
67+
// ReSharper disable once UnusedAutoPropertyAccessor.Local
6768
private string ClusterName { get; }
68-
69+
6970
public BasicAuthenticationCredentials BasicCredentials { get; }
7071

7172
public ApiKeyAuthenticationCredentials ApiKeyCredentials { get; }
@@ -101,11 +102,11 @@ private static ParsedCloudId ParseCloudId(string cloudId)
101102
var parts = decoded.Split(new[] { '$' });
102103
if (parts.Length < 2)
103104
throw new ArgumentException($"Parameter {nameof(cloudId)} decoded base_64_data contains less then 2 tokens, {exceptionSuffix}", nameof(cloudId));
104-
105+
105106
var domainName = parts[0].Trim();
106107
if (string.IsNullOrWhiteSpace(domainName))
107108
throw new ArgumentException($"Parameter {nameof(cloudId)} decoded base_64_data contains no domain name, {exceptionSuffix}", nameof(cloudId));
108-
109+
109110
var elasticsearchUuid = parts[1].Trim();
110111
if (string.IsNullOrWhiteSpace(elasticsearchUuid))
111112
throw new ArgumentException($"Parameter {nameof(cloudId)} decoded base_64_data contains no elasticsearch UUID, {exceptionSuffix}", nameof(cloudId));

0 commit comments

Comments
 (0)