Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.14.0
22.15.0
12 changes: 12 additions & 0 deletions clients/algoliasearch-client-csharp/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.0.1",
"commands": [
"csharpier"
]
}
}
}
2 changes: 2 additions & 0 deletions clients/algoliasearch-client-csharp/.csharpierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
obj
bin
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected AlgoliaConfig(string appId, string apiKey, string clientName, string c
{ Defaults.AlgoliaApiKeyHeader.ToLowerInvariant(), ApiKey },
{ Defaults.UserAgentHeader.ToLowerInvariant(), "" },
{ Defaults.Connection.ToLowerInvariant(), Defaults.KeepAlive },
{ Defaults.AcceptHeader.ToLowerInvariant(), JsonConfig.JsonContentType }
{ Defaults.AcceptHeader.ToLowerInvariant(), JsonConfig.JsonContentType },
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ public class AlgoliaException : Exception
/// Create a new Algolia exception.
/// </summary>
/// <param name="message">The exception details.</param>
public AlgoliaException(string message) : base(message)
{
}
public AlgoliaException(string message)
: base(message) { }

/// <summary>
/// Create a new Algolia exception, with an inner exception.
/// </summary>
/// <param name="message"></param>
/// <param name="inner"></param>
public AlgoliaException(string message, Exception inner)
: base(message, inner)
{
}
: base(message, inner) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class AlgoliaUnreachableHostException : Exception
/// Create a new AlgoliaUnreachableHostException.
/// </summary>
/// <param name="message">The exception details.</param>
public AlgoliaUnreachableHostException(string message) : base(message)
{
}
public AlgoliaUnreachableHostException(string message)
: base(message) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ internal class AlgoliaHttpRequester : IHttpRequester
private readonly HttpClient _httpClient = new(
new TimeoutHandler
{
InnerHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip }
});
InnerHandler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip },
}
);

private readonly ILogger<AlgoliaHttpRequester> _logger;

Expand All @@ -41,8 +42,12 @@ public AlgoliaHttpRequester(ILoggerFactory loggerFactory)
/// <param name="connectTimeout">Connect timeout</param>
/// <param name="ct">Optional cancellation token</param>
/// <returns></returns>
public async Task<AlgoliaHttpResponse> SendRequestAsync(Request request, TimeSpan requestTimeout,
TimeSpan connectTimeout, CancellationToken ct = default)
public async Task<AlgoliaHttpResponse> SendRequestAsync(
Request request,
TimeSpan requestTimeout,
TimeSpan connectTimeout,
CancellationToken ct = default
)
{
if (request.Method == null)
{
Expand All @@ -58,7 +63,7 @@ public async Task<AlgoliaHttpResponse> SendRequestAsync(Request request, TimeSpa
{
Method = request.Method,
RequestUri = request.Uri,
Content = request.Body != null ? new StreamContent(request.Body) : null
Content = request.Body != null ? new StreamContent(request.Body) : null,
};

if (request.Body != null && httpRequestMessage.Content != null)
Expand All @@ -73,7 +78,9 @@ public async Task<AlgoliaHttpResponse> SendRequestAsync(Request request, TimeSpa
try
{
using (httpRequestMessage)
using (var response = await _httpClient.SendAsync(httpRequestMessage, ct).ConfigureAwait(false))
using (
var response = await _httpClient.SendAsync(httpRequestMessage, ct).ConfigureAwait(false)
)
{
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
Expand All @@ -82,7 +89,7 @@ public async Task<AlgoliaHttpResponse> SendRequestAsync(Request request, TimeSpa
return new AlgoliaHttpResponse
{
Error = await StreamToStringAsync(stream),
HttpStatusCode = (int)response.StatusCode
HttpStatusCode = (int)response.StatusCode,
};
}

Expand All @@ -93,7 +100,7 @@ public async Task<AlgoliaHttpResponse> SendRequestAsync(Request request, TimeSpa
return new AlgoliaHttpResponse
{
Body = outputStream,
HttpStatusCode = (int)response.StatusCode
HttpStatusCode = (int)response.StatusCode,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void AddSegment(string key, string value)
_segments.Add(new KeyValuePair<string, string>(key, value));
}


/// <summary>
/// Create a valid user-agent header
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ internal static void SetTimeout(this HttpRequestMessage request, TimeSpan? timeo
{
if (request == null)
throw new ArgumentNullException(nameof(request));
if (request.Properties.TryGetValue(TimeoutPropertyKey, out var value) && value is TimeSpan timeout)
if (
request.Properties.TryGetValue(TimeoutPropertyKey, out var value) && value is TimeSpan timeout
)
return timeout;
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ public interface IHttpRequester
/// <param name="connectTimeout">Connect timeout</param>
/// <param name="ct">Optional cancellation token</param>
/// <returns></returns>
Task<AlgoliaHttpResponse> SendRequestAsync(Request request, TimeSpan requestTimeout, TimeSpan connectTimeout, CancellationToken ct = default);
Task<AlgoliaHttpResponse> SendRequestAsync(
Request request,
TimeSpan requestTimeout,
TimeSpan connectTimeout,
CancellationToken ct = default
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public InternalRequestOptions(RequestOptions options = null)

public void AddQueryParameter(string key, object value)
{
if (value == null) return;
if (value == null)
return;

if (!QueryParameters.ContainsKey(key))
{
Expand All @@ -42,7 +43,8 @@ public void AddQueryParameter(string key, object value)

public void AddCustomQueryParameters(IDictionary<string, object> values)
{
if (values == null) return;
if (values == null)
return;

foreach (var t in values)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Request
public Uri Uri { get; set; }

/// <summary>
/// Headers
/// Headers
/// </summary>
public IDictionary<string, string> Headers { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public RequestOptionBuilder()
_options = new RequestOptions
{
Headers = new Dictionary<string, string>(),
QueryParameters = new Dictionary<string, object>()
QueryParameters = new Dictionary<string, object>(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ internal class TimeoutHandler : DelegatingHandler
{
private TimeSpan DefaultTimeout { get; set; } = TimeSpan.FromSeconds(100);

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken
)
{
using var cts = GetCancellationTokenSource(request, cancellationToken);
try
Expand All @@ -27,8 +29,10 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}
}

private CancellationTokenSource GetCancellationTokenSource(HttpRequestMessage request,
CancellationToken cancellationToken)
private CancellationTokenSource GetCancellationTokenSource(
HttpRequestMessage request,
CancellationToken cancellationToken
)
{
var timeout = request.GetTimeout() ?? DefaultTimeout;
if (timeout == Timeout.InfiniteTimeSpan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public enum CompressionType
/// <summary>
/// GZip Compression. Only supported by Search API.
/// </summary>
Gzip = 2
Gzip = 2,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.Json.Serialization;
using Algolia.Search.Http;
using Algolia.Search.Utils;
using System.Collections.Generic;

namespace Algolia.Search.Models.Search;

Expand All @@ -12,7 +12,6 @@ namespace Algolia.Search.Models.Search;
/// </summary>
public partial class SecuredApiKeyRestrictions
{

/// <summary>
/// Transforms the restriction into a query string
/// </summary>
Expand All @@ -23,10 +22,14 @@ public string ToQueryString()
if (SearchParams != null)
{
// merge SearchParams into restrictions
restrictions = restrictions.Concat(ToQueryMap(SearchParams)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
restrictions = restrictions
.Concat(ToQueryMap(SearchParams))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
}

return QueryStringHelper.ToQueryString(restrictions.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
return QueryStringHelper.ToQueryString(
restrictions.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
);
}

/// <summary>
Expand All @@ -38,15 +41,18 @@ public string ToQueryString()
/// <returns></returns>
private static Dictionary<string, string> ToQueryMap<T>(T value, params string[] ignoreList)
{
return typeof(T).GetTypeInfo()
return typeof(T)
.GetTypeInfo()
.DeclaredProperties.Where(p =>
p.GetValue(value, null) != null && !ignoreList.Contains(p.Name) &&
p.GetCustomAttribute<JsonPropertyNameAttribute>() != null)
p.GetValue(value, null) != null
&& !ignoreList.Contains(p.Name)
&& p.GetCustomAttribute<JsonPropertyNameAttribute>() != null
)
.Select(p => new
{
propsName = p.GetCustomAttribute<JsonPropertyNameAttribute>().Name,
value = QueryStringHelper.ParameterToString(p.GetValue(value, null))
}).ToDictionary(p => p.propsName, p => p.value);
value = QueryStringHelper.ParameterToString(p.GetValue(value, null)),
})
.ToDictionary(p => p.propsName, p => p.value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Algolia.Search.Serializer;

internal class DefaultJsonSerializer(ILoggerFactory logger) : ISerializer
{
private readonly ILogger<DefaultJsonSerializer> _logger = logger.CreateLogger<DefaultJsonSerializer>();
private readonly ILogger<DefaultJsonSerializer> _logger =
logger.CreateLogger<DefaultJsonSerializer>();

/// <summary>
/// Serialize the object into a JSON string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer
/// <summary>
/// Custom JsonConverter to convert enum to string, using the JsonPropertyNameAttribute if present
/// </summary>
public class JsonStringEnumConverter<TEnum> : JsonConverter<TEnum> where TEnum : struct, Enum
public class JsonStringEnumConverter<TEnum> : JsonConverter<TEnum>
where TEnum : struct, Enum
{
private readonly Dictionary<TEnum, string> _enumToString = new();
private readonly Dictionary<string, TEnum> _stringToEnum = new();
Expand All @@ -52,7 +53,8 @@ public JsonStringEnumConverter()
foreach (var value in Enum.GetValues(type))
{
var enumMember = type.GetMember(value.ToString())[0];
var attr = enumMember.GetCustomAttributes(typeof(JsonPropertyNameAttribute), false)
var attr = enumMember
.GetCustomAttributes(typeof(JsonPropertyNameAttribute), false)
.Cast<JsonPropertyNameAttribute>()
.FirstOrDefault();

Expand All @@ -79,7 +81,11 @@ public JsonStringEnumConverter()
/// <param name="typeToConvert"></param>
/// <param name="options"></param>
/// <returns></returns>
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override TEnum Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options
)
{
var type = reader.TokenType;
switch (type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ internal static class JsonConfig
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
Converters =
{
new SearchResultConverterFactory()
}
Converters = { new SearchResultConverterFactory() },
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public enum CallType
/// <summary>
/// Write Call
/// </summary>
Write = 2
Write = 2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public enum HttpScheme
/// Http
/// </summary>
Http,

/// <summary>
/// Https
/// </summary>
Https
Https,
}
Loading