Skip to content

[Backport 8.0] Refactor to file-scoped namespaces #6794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,68 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Elastic.Clients.Elasticsearch;
using Elastic.Transport;
using Newtonsoft.Json;

namespace Elastic.Clients.Elasticsearch.JsonNetSerializer
namespace Elastic.Clients.Elasticsearch.JsonNetSerializer;

public abstract partial class ConnectionSettingsAwareSerializer : Serializer
{
public abstract partial class ConnectionSettingsAwareSerializer : Serializer
{
// Default buffer size of StreamWriter, which is private :(
internal const int DefaultBufferSize = 1024;
// Default buffer size of StreamWriter, which is private :(
internal const int DefaultBufferSize = 1024;

private static readonly Task CompletedTask = Task.CompletedTask;
private static readonly Task CompletedTask = Task.CompletedTask;

internal static readonly Encoding ExpectedEncoding = new UTF8Encoding(false);
private readonly JsonSerializer _collapsedSerializer;
internal static readonly Encoding ExpectedEncoding = new UTF8Encoding(false);
private readonly JsonSerializer _collapsedSerializer;

private readonly JsonSerializer _serializer;
protected virtual int BufferSize => DefaultBufferSize;
private readonly JsonSerializer _serializer;
protected virtual int BufferSize => DefaultBufferSize;

public override T Deserialize<T>(Stream stream)
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
return _serializer.Deserialize<T>(jsonTextReader);
}
public override T Deserialize<T>(Stream stream)
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
return _serializer.Deserialize<T>(jsonTextReader);
}

public override object Deserialize(Type type, Stream stream)
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
return _serializer.Deserialize(jsonTextReader, type);
}
public override object Deserialize(Type type, Stream stream)
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
return _serializer.Deserialize(jsonTextReader, type);
}

public override async ValueTask<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
var token = await jsonTextReader.ReadTokenWithDateParseHandlingNoneAsync(cancellationToken).ConfigureAwait(false);
return token.ToObject<T>(_serializer);
}
public override async ValueTask<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default)
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
var token = await jsonTextReader.ReadTokenWithDateParseHandlingNoneAsync(cancellationToken).ConfigureAwait(false);
return token.ToObject<T>(_serializer);
}

public override async ValueTask<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default(CancellationToken))
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
var token = await jsonTextReader.ReadTokenWithDateParseHandlingNoneAsync(cancellationToken).ConfigureAwait(false);
return token.ToObject(type, _serializer);
}
public override async ValueTask<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default(CancellationToken))
{
using var streamReader = new StreamReader(stream);
using var jsonTextReader = new JsonTextReader(streamReader);
var token = await jsonTextReader.ReadTokenWithDateParseHandlingNoneAsync(cancellationToken).ConfigureAwait(false);
return token.ToObject(type, _serializer);
}

public override void Serialize<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None)
{
using var writer = new StreamWriter(stream, ExpectedEncoding, BufferSize, true);
using var jsonWriter = new JsonTextWriter(writer);
var serializer = formatting == SerializationFormatting.Indented ? _serializer : _collapsedSerializer;
serializer.Serialize(jsonWriter, data);
}
public override void Serialize<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None)
{
using var writer = new StreamWriter(stream, ExpectedEncoding, BufferSize, true);
using var jsonWriter = new JsonTextWriter(writer);
var serializer = formatting == SerializationFormatting.Indented ? _serializer : _collapsedSerializer;
serializer.Serialize(jsonWriter, data);
}

public override Task SerializeAsync<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None,
CancellationToken cancellationToken = default)
{
//This makes no sense now but we need the async method on the interface in 6.x so we can start swapping this out
//for an implementation that does make sense without having to wait for 7.x
Serialize(data, stream, formatting);
return CompletedTask;
}
public override Task SerializeAsync<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None,
CancellationToken cancellationToken = default)
{
//This makes no sense now but we need the async method on the interface in 6.x so we can start swapping this out
//for an implementation that does make sense without having to wait for 7.x
Serialize(data, stream, formatting);
return CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@
using System;
using Elastic.Clients.Elasticsearch.QueryDsl;

namespace Elastic.Clients.Elasticsearch.AsyncSearch
namespace Elastic.Clients.Elasticsearch.AsyncSearch;

public partial class AsyncSearchSubmitRequest
{
public partial class AsyncSearchSubmitRequest
{
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys = true;
}
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys = true;
}

public sealed partial class AsyncSearchSubmitRequestDescriptor
{
public AsyncSearchSubmitRequestDescriptor MatchAll(Action<MatchAllQueryDescriptor>? selector = null) => selector is null ? Query(q => q.MatchAll()) : Query(q => q.MatchAll(selector));
public sealed partial class AsyncSearchSubmitRequestDescriptor
{
public AsyncSearchSubmitRequestDescriptor MatchAll(Action<MatchAllQueryDescriptor>? selector = null) => selector is null ? Query(q => q.MatchAll()) : Query(q => q.MatchAll(selector));

internal override void BeforeRequest() => TypedKeys(true);
}
internal override void BeforeRequest() => TypedKeys(true);
}

public sealed partial class AsyncSearchSubmitRequestDescriptor<TDocument>
public sealed partial class AsyncSearchSubmitRequestDescriptor<TDocument>
{
public AsyncSearchSubmitRequestDescriptor<TDocument> MatchAll()
{
public AsyncSearchSubmitRequestDescriptor<TDocument> MatchAll()
{
Query(new MatchAllQuery());
return Self;
}

internal override void BeforeRequest() => TypedKeys(true);
Query(new MatchAllQuery());
return Self;
}

internal override void BeforeRequest() => TypedKeys(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

namespace Elastic.Clients.Elasticsearch.AsyncSearch
namespace Elastic.Clients.Elasticsearch.AsyncSearch;

public partial class GetAsyncSearchRequest
{
public partial class GetAsyncSearchRequest
{
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys = true;
}
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys = true;
}

public sealed partial class GetAsyncSearchRequestDescriptor<TDocument>
{
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys(true);
}
public sealed partial class GetAsyncSearchRequestDescriptor<TDocument>
{
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys(true);
}

public sealed partial class GetAsyncSearchRequestDescriptor
{
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys(true);
}
public sealed partial class GetAsyncSearchRequestDescriptor
{
// Any request may contain aggregations so we force typed_keys in order to successfully deserialise them.
internal override void BeforeRequest() => TypedKeys(true);
}
Loading