Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Fix analyzer issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Jan 26, 2021
1 parent cacb05d commit 2a22e3a
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 202 deletions.
2 changes: 1 addition & 1 deletion src/Faithlife.WebRequests/ByteRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public ByteRange(long from, long to)
/// </summary>
public bool HasEnd => m_to.HasValue;

readonly long? m_to;
private readonly long? m_to;
}
}
6 changes: 3 additions & 3 deletions src/Faithlife.WebRequests/CookieManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CookieManager(IEnumerable<UriCookieHeader> seqCookies)
}

/// <summary>
/// Returns a reference to the <see cref="CookieContainer"/> for this instance.
/// Returns a reference to the <see cref="CookieContainer"/> for this instance.
/// </summary>
public CookieContainer CookieContainer { get; }

Expand Down Expand Up @@ -114,7 +114,7 @@ public void ExpireCookies()
/// </summary>
public event EventHandler? CookiesChanged;

readonly object m_objLock;
readonly HashSet<Uri> m_setUris;
private readonly object m_objLock;
private readonly HashSet<Uri> m_setUris;
}
}
2 changes: 1 addition & 1 deletion src/Faithlife.WebRequests/CookieUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Faithlife.WebRequests
public static class CookieUtility
{
/// <summary>
/// Returns a <see cref="String"/> representing the specified cookie, in the format prescribed by
/// Returns a <see cref="string"/> representing the specified cookie, in the format prescribed by
/// RFC 2965 for the Set-Cookie HTTP header value.
/// </summary>
/// <param name="cookie">The cookie.</param>
Expand Down
23 changes: 23 additions & 0 deletions src/Faithlife.WebRequests/HttpHeadersUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Net;
using System.Net.Http.Headers;
using Faithlife.Utility;

namespace Faithlife.WebRequests
{
internal static class HttpHeadersUtility
{
public static void AddWebHeaders(this HttpHeaders self, WebHeaderCollection headers)
{
foreach (var headerName in headers.AllKeys)
self.Add(headerName, headers[headerName]);
}

public static WebHeaderCollection ToWebHeaderCollection(this HttpHeaders self)
{
var collection = new WebHeaderCollection();
foreach (var pair in self)
collection.Add(pair.Key, pair.Value.Join("; "));
return collection;
}
}
}
4 changes: 2 additions & 2 deletions src/Faithlife.WebRequests/HttpResponseMessageUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static class HttpResponseMessageUtility
/// </summary>
/// <param name="response">The response.</param>
/// <param name="message">The message.</param>
/// <param name="contentPreview">The content preview.</param>
/// <param name="innerException">The inner exception.</param>
/// <param name="contentPreview">The content preview.</param>
/// <returns>A new exception.</returns>
public static WebServiceException CreateWebServiceException(HttpResponseMessage response, string? message = null, Exception? innerException = null, string? contentPreview = null)
{
Expand Down Expand Up @@ -72,6 +72,6 @@ public static async Task<WebServiceException> CreateWebServiceExceptionWithConte
}
}

const int c_contentPreviewCharacterCount = 2000;
private const int c_contentPreviewCharacterCount = 2000;
}
}
8 changes: 4 additions & 4 deletions src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Faithlife.Utility;
using Faithlife.Json;
using System.Threading;
using Faithlife.Utility;

namespace Faithlife.WebRequests.Json
{
Expand Down Expand Up @@ -96,8 +96,8 @@ protected override async Task<bool> HandleResponseCoreAsync(WebServiceResponseHa
// read headers
foreach (var header in webResponse.Headers)
{
string headerName = header.Key;
// remove hyphens before looking for property setter by name
string headerName = header.Key;
string propertyName = headerName.Replace("-", "");
var headerProperty = GetProperty(responseType, propertyName);
if (headerProperty?.CanWrite ?? false)
Expand Down Expand Up @@ -235,7 +235,7 @@ protected override void Dispose(bool disposing)
}
}

readonly HttpResponseMessage m_webResponse;
private readonly HttpResponseMessage m_webResponse;
}
}
}
14 changes: 7 additions & 7 deletions src/Faithlife.WebRequests/Json/AutoWebServiceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ internal Task OnResponseHandledAsync(WebServiceResponseHandlerInfo info)
return OnResponseHandledCoreAsync(info);
}

string? m_requestMethod;
Uri? m_requestUri;
HttpStatusCode? m_responseStatusCode;
HttpHeaders? m_responseHeaders;
string? m_responseContentType;
long? m_responseContentLength;
string? m_responseContentPreview;
private string? m_requestMethod;
private Uri? m_requestUri;
private HttpStatusCode? m_responseStatusCode;
private HttpHeaders? m_responseHeaders;
private string? m_responseContentType;
private long? m_responseContentLength;
private string? m_responseContentPreview;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static class AutoWebServiceResponseUtility
/// <param name="response">The AutoWebServiceResponse to read the property from.</param>
/// <param name="getProperty">The func that reads the desired property.</param>
/// <returns>The value of the property.</returns>
public static TProperty GetExpectedResult<TResponse, TProperty>(this TResponse response, Func<TResponse, TProperty> getProperty) where TResponse : AutoWebServiceResponse
public static TProperty GetExpectedResult<TResponse, TProperty>(this TResponse response, Func<TResponse, TProperty> getProperty)
where TResponse : AutoWebServiceResponse
{
TProperty propertyValue = getProperty(response);

Expand All @@ -33,7 +34,8 @@ public static TProperty GetExpectedResult<TResponse, TProperty>(this TResponse r
/// <typeparam name="TProperty">The type of the property.</typeparam>
/// <param name="response">The AutoWebServiceResponse to read the property from.</param>
/// <param name="getProperty">The func that reads the desired property.</param>
public static void VerifyResultIsExpected<TResponse, TProperty>(this TResponse response, Func<TResponse, TProperty> getProperty) where TResponse : AutoWebServiceResponse
public static void VerifyResultIsExpected<TResponse, TProperty>(this TResponse response, Func<TResponse, TProperty> getProperty)
where TResponse : AutoWebServiceResponse
{
GetExpectedResult(response, getProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Faithlife.WebRequests.Json
{
/// <summary>
/// AutoWebServiceRequest responses with an explicitly set status code.
/// AutoWebServiceRequest responses with an explicitly set status code.
/// </summary>
public class GenericStatusCodeResponse : AutoWebServiceResponse
{
Expand Down
2 changes: 1 addition & 1 deletion src/Faithlife.WebRequests/Json/JsonWebResponseUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Faithlife.Utility;
using Faithlife.Json;
using Faithlife.Utility;
using Newtonsoft.Json;

namespace Faithlife.WebRequests.Json
Expand Down
4 changes: 2 additions & 2 deletions src/Faithlife.WebRequests/Json/JsonWebServiceClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private AutoWebServiceRequest<TResponse> DoCreateRequest<TResponse>(Uri uri)
return request;
}

readonly Uri m_baseUri;
readonly JsonWebServiceClientSettings m_clientSettings;
private readonly Uri m_baseUri;
private readonly JsonWebServiceClientSettings m_clientSettings;
}
}
7 changes: 4 additions & 3 deletions src/Faithlife.WebRequests/Json/JsonWebServiceContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Faithlife.Utility;
using Faithlife.Json;
using Faithlife.Utility;

namespace Faithlife.WebRequests.Json
{
Expand Down Expand Up @@ -100,13 +100,14 @@ protected override bool TryComputeLength(out long length)
return Json is object;
}

string? m_json;
private string? m_json;
}

/// <summary>
/// JSON web service content.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Generic.")]
public class JsonWebServiceContent<TValue> : JsonWebServiceContent
{
/// <summary>
Expand Down Expand Up @@ -145,6 +146,6 @@ protected internal JsonWebServiceContent(TValue value, JsonSettings? settings)
/// <value>The JSON.</value>
protected override string GenerateJson() => JsonUtility.ToJson(Value, m_outputSettings);

readonly JsonSettings? m_outputSettings;
private readonly JsonSettings? m_outputSettings;
}
}
4 changes: 3 additions & 1 deletion src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Faithlife.Utility;
using Faithlife.Json;
using Faithlife.Utility;
using Newtonsoft.Json;

namespace Faithlife.WebRequests.Json
Expand Down Expand Up @@ -70,6 +71,7 @@ protected override async Task<WebServiceResponse> CreateResponseAsync(WebService
/// A JSON web service request.
/// </summary>
/// <typeparam name="TResponseValue">The type of the response value.</typeparam>
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Generic.")]
public class JsonWebServiceRequest<TResponseValue> : JsonWebServiceRequest
{
/// <summary>
Expand Down
23 changes: 5 additions & 18 deletions src/Faithlife.WebRequests/Json/JsonWebServiceRequestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ public static class JsonWebServiceRequestUtility
/// <summary>
/// Sets the Content of the WebServiceRequest.
/// </summary>
/// <typeparam name="TWebServiceRequest">The type of the web service request.</typeparam>
/// <typeparam name="TContentValue">The type of the content value.</typeparam>
/// <param name="request">The request.</param>
/// <param name="contentValue">The content value.</param>
/// <returns>The request.</returns>
public static TWebServiceRequest WithJsonContent<TWebServiceRequest, TContentValue>(this TWebServiceRequest request, TContentValue contentValue) where TWebServiceRequest : WebServiceRequestBase
public static TWebServiceRequest WithJsonContent<TWebServiceRequest, TContentValue>(this TWebServiceRequest request, TContentValue contentValue)
where TWebServiceRequest : WebServiceRequestBase
{
request.Content = JsonWebServiceContent.FromValue(contentValue);
return request;
Expand All @@ -24,25 +20,16 @@ public static TWebServiceRequest WithJsonContent<TWebServiceRequest, TContentVal
/// <summary>
/// Sets the Content of the WebServiceRequest.
/// </summary>
/// <typeparam name="TWebServiceRequest">The type of the web service request.</typeparam>
/// <typeparam name="TContentValue">The type of the content value.</typeparam>
/// <param name="request">The request.</param>
/// <param name="contentValue">The content value.</param>
/// <param name="settings">The settings.</param>
/// <returns>The request.</returns>
public static TWebServiceRequest WithJsonContent<TWebServiceRequest, TContentValue>(this TWebServiceRequest request, TContentValue contentValue, JsonSettings settings) where TWebServiceRequest : WebServiceRequestBase
public static TWebServiceRequest WithJsonContent<TWebServiceRequest, TContentValue>(this TWebServiceRequest request, TContentValue contentValue, JsonSettings settings)
where TWebServiceRequest : WebServiceRequestBase
{
request.Content = JsonWebServiceContent.FromValue(contentValue, settings);
return request;
}

/// <summary>
/// Sets the InputSettings of the WebServiceRequest.
/// Sets the JsonSettings of the WebServiceRequest.
/// </summary>
/// <typeparam name="TResponseContent">The type of the response content.</typeparam>
/// <param name="request">The request.</param>
/// <param name="settings">The settings.</param>
/// <returns>The request.</returns>
public static JsonWebServiceRequest<TResponseContent> WithJsonSettings<TResponseContent>(this JsonWebServiceRequest<TResponseContent> request, JsonSettings settings)
{
request.JsonSettings = settings;
Expand Down
2 changes: 2 additions & 0 deletions src/Faithlife.WebRequests/Json/JsonWebServiceResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -39,6 +40,7 @@ public string? Json
/// A JSON web response.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Generic.")]
public class JsonWebServiceResponse<TValue> : JsonWebServiceResponse
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;
using System.Threading.Tasks;
using Faithlife.Utility;
using Faithlife.Json;
using Faithlife.Utility;
using Newtonsoft.Json;

namespace Faithlife.WebRequests.Json
Expand Down
2 changes: 1 addition & 1 deletion src/Faithlife.WebRequests/WebServiceErrorKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public enum WebServiceErrorKind
/// <summary>
/// The error occurred while handling the response.
/// </summary>
Response
Response,
}
}
2 changes: 1 addition & 1 deletion src/Faithlife.WebRequests/WebServiceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override string Message
}

/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Don't want exceptions thrown from ToString.")]
public override string ToString()
Expand Down
20 changes: 17 additions & 3 deletions src/Faithlife.WebRequests/WebServiceRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -14,6 +15,7 @@ namespace Faithlife.WebRequests
/// <summary>
/// A web service request.
/// </summary>
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Generic.")]
public class WebServiceRequest<TResponse> : WebServiceRequestBase<TResponse>
{
/// <summary>
Expand Down Expand Up @@ -109,8 +111,20 @@ protected override async Task<bool> HandleResponseCoreAsync(WebServiceResponseHa
return true;
}

static readonly IReadOnlyList<HttpStatusCode> s_defaultAcceptedStatusCodes = new[] { HttpStatusCode.OK, HttpStatusCode.Created }.AsReadOnly();
static readonly IReadOnlyList<HttpStatusCode> s_defaultAcceptedStatusCodesWithRedirect = new[] { HttpStatusCode.OK, HttpStatusCode.Created,
HttpStatusCode.Moved, HttpStatusCode.Redirect, HttpStatusCode.RedirectMethod, HttpStatusCode.RedirectKeepVerb }.AsReadOnly();
private static readonly IReadOnlyList<HttpStatusCode> s_defaultAcceptedStatusCodes = new[]
{
HttpStatusCode.OK,
HttpStatusCode.Created,
}.AsReadOnly();

private static readonly IReadOnlyList<HttpStatusCode> s_defaultAcceptedStatusCodesWithRedirect = new[]
{
HttpStatusCode.OK,
HttpStatusCode.Created,
HttpStatusCode.Moved,
HttpStatusCode.Redirect,
HttpStatusCode.RedirectMethod,
HttpStatusCode.RedirectKeepVerb,
}.AsReadOnly();
}
}
Loading

0 comments on commit 2a22e3a

Please sign in to comment.