Skip to content

Commit

Permalink
Fix #369 (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
zapadi authored Jan 29, 2025
1 parent 9ce6a9d commit 21a6baf
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public partial interface IRedmineManager
/// <summary>
/// Maximum page-size when retrieving complete object lists
/// <remarks>
/// By default only 25 results can be retrieved per request. Maximum is 100. To change the maximum value set
/// By default, only 25 results can be retrieved per request. Maximum is 100. To change the maximum value set
/// in your Settings -&gt; General, "Objects per page options".By adding (for instance) 9999 there would make you
/// able to get that many results per request.
/// </remarks>
Expand All @@ -56,7 +56,7 @@ public partial interface IRedmineManager
int PageSize { get; set; }

/// <summary>
/// As of Redmine 2.2.0 you can impersonate user setting user login (eg. jsmith). This only works when using the API
/// As of Redmine 2.2.0 you can impersonate user setting user login (e.g. jsmith). This only works when using the API
/// with an administrator account, this header will be ignored when using the API with a regular user account.
/// </summary>
/// <value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal sealed class InternalRedmineApiWebClient : IRedmineApiClient
public InternalRedmineApiWebClient(RedmineManagerOptions redmineManagerOptions)
: this(() => new InternalWebClient(redmineManagerOptions), redmineManagerOptions.Authentication, redmineManagerOptions.Serializer)
{
ConfigureServicePointManager(redmineManagerOptions.ClientOptions);
ConfigureServicePointManager(redmineManagerOptions.WebClientOptions);
}

public InternalRedmineApiWebClient(
Expand All @@ -55,9 +55,9 @@ public InternalRedmineApiWebClient(
_serializer = serializer;
}

private static void ConfigureServicePointManager(IRedmineApiClientOptions options)
private static void ConfigureServicePointManager(IRedmineWebClientOptions webClientOptions)
{
if (options is not IRedmineWebClientOptions webClientOptions)
if (webClientOptions == null)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/redmine-net-api/Net/WebClient/InternalWebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class InternalWebClient : System.Net.WebClient
#pragma warning disable SYSLIB0014
public InternalWebClient(RedmineManagerOptions redmineManagerOptions)
{
_webClientOptions = redmineManagerOptions.ClientOptions as IRedmineWebClientOptions;
_webClientOptions = redmineManagerOptions.WebClientOptions;
BaseAddress = redmineManagerOptions.BaseAddress.ToString();
}
#pragma warning restore SYSLIB0014
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Redmine.Net.Api.Net.WebClient;
/// <summary>
///
/// </summary>
public sealed class RedmineWebClientOptions: IRedmineApiClientOptions
public sealed class RedmineWebClientOptions: IRedmineWebClientOptions
{
/// <summary>
///
Expand Down
26 changes: 13 additions & 13 deletions src/redmine-net-api/RedmineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,37 @@ public RedmineManager(RedmineManagerOptionsBuilder optionsBuilder)
#if NET45_OR_GREATER
if (_redmineManagerOptions.VerifyServerCert)
{
_redmineManagerOptions.ClientOptions.ServerCertificateValidationCallback = RemoteCertValidate;
_redmineManagerOptions.WebClientOptions.ServerCertificateValidationCallback = RemoteCertValidate;
}
#endif

if (_redmineManagerOptions.ClientOptions is RedmineWebClientOptions)
if (_redmineManagerOptions.WebClientOptions is RedmineWebClientOptions)
{
Proxy = _redmineManagerOptions.WebClientOptions.Proxy;
Timeout = _redmineManagerOptions.WebClientOptions.Timeout;
SecurityProtocolType = _redmineManagerOptions.WebClientOptions.SecurityProtocolType.GetValueOrDefault();
#pragma warning disable SYSLIB0014
_redmineManagerOptions.ClientOptions.SecurityProtocolType ??= ServicePointManager.SecurityProtocol;
_redmineManagerOptions.WebClientOptions.SecurityProtocolType ??= ServicePointManager.SecurityProtocol;
#pragma warning restore SYSLIB0014
}

if (_redmineManagerOptions.Authentication is RedmineApiKeyAuthentication)
{
ApiKey = _redmineManagerOptions.Authentication.Token;
}

Serializer = _redmineManagerOptions.Serializer;
Host = _redmineManagerOptions.BaseAddress.ToString();
PageSize = _redmineManagerOptions.PageSize;
Format = Serializer.Format;
Scheme = _redmineManagerOptions.BaseAddress.Scheme;
Proxy = _redmineManagerOptions.ClientOptions.Proxy;
Timeout = _redmineManagerOptions.ClientOptions.Timeout;
Format = Serializer.Format;
MimeFormat = RedmineConstants.XML.Equals(Serializer.Format, StringComparison.Ordinal)
? MimeFormat.Xml
: MimeFormat.Json;
SecurityProtocolType = _redmineManagerOptions.ClientOptions.SecurityProtocolType.GetValueOrDefault();

if (_redmineManagerOptions.Authentication is RedmineApiKeyAuthentication)
{
ApiKey = _redmineManagerOptions.Authentication.Token;
}

RedmineApiUrls = new RedmineApiUrls(Serializer.Format);
#if NET45_OR_GREATER || NETCOREAPP
if (_redmineManagerOptions.ClientOptions is RedmineWebClientOptions)
if (_redmineManagerOptions.WebClientOptions is RedmineWebClientOptions)
{
ApiClient = _redmineManagerOptions.ClientFunc != null
? new InternalRedmineApiWebClient(_redmineManagerOptions.ClientFunc, _redmineManagerOptions.Authentication, _redmineManagerOptions.Serializer)
Expand Down
3 changes: 2 additions & 1 deletion src/redmine-net-api/RedmineManagerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
using System.Net;
using Redmine.Net.Api.Authentication;
using Redmine.Net.Api.Net;
using Redmine.Net.Api.Net.WebClient;
using Redmine.Net.Api.Serialization;

namespace Redmine.Net.Api
Expand Down Expand Up @@ -60,7 +61,7 @@ internal sealed class RedmineManagerOptions
/// <summary>
/// Gets or sets the settings for configuring the Redmine web client.
/// </summary>
public IRedmineApiClientOptions ClientOptions { get; init; }
public IRedmineWebClientOptions WebClientOptions { get; init; }

/// <summary>
/// Gets or sets the version of the Redmine server to which this client will connect.
Expand Down
34 changes: 27 additions & 7 deletions src/redmine-net-api/RedmineManagerOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public RedmineManagerOptionsBuilder WithHost(string baseAddress)
/// </summary>
public string Host { get; private set; }


/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -147,17 +146,38 @@ public RedmineManagerOptionsBuilder WithWebClient(Func<WebClient> clientFunc)
/// </summary>
/// <param name="clientOptions"></param>
/// <returns></returns>
[Obsolete("Use WithWebClientOptions(IRedmineWebClientOptions clientOptions) instead.")]
public RedmineManagerOptionsBuilder WithWebClientOptions(IRedmineApiClientOptions clientOptions)
{
return WithWebClientOptions((IRedmineWebClientOptions)clientOptions);
}

/// <summary>
///
/// </summary>
/// <param name="clientOptions"></param>
/// <returns></returns>
public RedmineManagerOptionsBuilder WithWebClientOptions(IRedmineWebClientOptions clientOptions)
{
_clientType = ClientType.WebClient;
this.ClientOptions = clientOptions;
this.WebClientOptions = clientOptions;
return this;
}

/// <summary>
///
/// </summary>
public IRedmineApiClientOptions ClientOptions { get; private set; }
[Obsolete("Use WebClientOptions instead.")]
public IRedmineApiClientOptions ClientOptions
{
get => WebClientOptions;
private set { }
}

/// <summary>
///
/// </summary>
public IRedmineWebClientOptions WebClientOptions { get; private set; }

/// <summary>
///
Expand Down Expand Up @@ -200,7 +220,7 @@ internal RedmineManagerOptions Build()
DecompressionMethods.All;
#endif
#if NET45_OR_GREATER || NETCOREAPP
ClientOptions ??= _clientType switch
WebClientOptions ??= _clientType switch
{
ClientType.WebClient => new RedmineWebClientOptions()
{
Expand All @@ -210,13 +230,13 @@ internal RedmineManagerOptions Build()
_ => throw new ArgumentOutOfRangeException()
};
#else
ClientOptions ??= new RedmineWebClientOptions()
WebClientOptions ??= new RedmineWebClientOptions()
{
UserAgent = defaultUserAgent,
DecompressionFormat = defaultDecompressionFormat,
};
#endif
var baseAddress = CreateRedmineUri(Host, ClientOptions.Scheme);
var baseAddress = CreateRedmineUri(Host, WebClientOptions.Scheme);

var options = new RedmineManagerOptions()
{
Expand All @@ -226,7 +246,7 @@ internal RedmineManagerOptions Build()
Serializer = RedmineSerializerFactory.CreateSerializer(SerializationType),
RedmineVersion = Version,
Authentication = Authentication ?? new RedmineNoAuthentication(),
ClientOptions = ClientOptions
WebClientOptions = WebClientOptions
};

return options;
Expand Down

0 comments on commit 21a6baf

Please sign in to comment.