Skip to content

Commit

Permalink
Merge pull request #599 from WideSpectrumComputing/master
Browse files Browse the repository at this point in the history
Fixing VS build warnings and intelli-sense suggestions
  • Loading branch information
akornich committed Oct 13, 2021
2 parents 9d4ede2 + aa57ec4 commit 992c0b6
Show file tree
Hide file tree
Showing 36 changed files with 226 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -151,7 +151,7 @@ csharp_space_after_cast = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
Expand Down
12 changes: 6 additions & 6 deletions Benchmarker.Common/BenchmarksConfig.cs
Expand Up @@ -21,8 +21,8 @@ public BenchmarksConfig()

Job[] jobs = new Job[]
{
Job.Default.With(ClrRuntime.Net48),
Job.Default.With(CoreRuntime.Core30),
Job.Default.WithRuntime(ClrRuntime.Net48),
Job.Default.WithRuntime(CoreRuntime.Core30),
//Job.CoreRT,
//Job.Mono,
};
Expand Down Expand Up @@ -59,11 +59,11 @@ public BenchmarksConfig()
{
foreach(var job in jobs)
{
Add(
AddJob(
job
.With(platform)
.With(jit)
.With(runtime)
.WithPlatform(platform)
.WithJit(jit)
.WithRuntime(runtime)
.WithLaunchCount(1)
.WithMinIterationCount(100)
.WithIterationCount(100)
Expand Down
304 changes: 0 additions & 304 deletions ReleaseNotes.md

This file was deleted.

14 changes: 7 additions & 7 deletions Rollbar.Net.AspNet/HttpRequestPackageDecorator.cs
@@ -1,8 +1,7 @@
using System.Collections.Generic;

namespace Rollbar.Net.AspNet
namespace Rollbar.Net.AspNet
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Hosting;
Expand Down Expand Up @@ -87,21 +86,22 @@ protected override void Decorate(Data? rollbarData)
// try harvesting Request DTO info:
///////////////////////////////////

var request = new Request();
Request request = new();
request.Url = this._httpRequest.Url?.ToString();
request.Method = this._httpRequest.HttpMethod;
request.Headers = this._httpRequest.Headers?.ToStringDictionary();
request.Headers = this._httpRequest.Headers?.ToCompactStringDictionary();

try
{
request.GetParams = this._httpRequest.QueryString?.ToObjectDictionary();
request.GetParams = this._httpRequest.QueryString?.ToCompactObjectDictionary();
}
catch
{
// calls in try-block may throw an exception. we are just trying our best...
}
try
{
request.PostParams = this._httpRequest.Unvalidated?.Form?.ToObjectDictionary();
request.PostParams = this._httpRequest.Unvalidated?.Form?.ToCompactObjectDictionary();
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion Rollbar.Net.AspNet/HttpResponsePackageDecorator.cs
Expand Up @@ -88,7 +88,7 @@ protected override void Decorate(Data? rollbarData)
}

rollbarData.Response.StatusCode = this._httpResponse.StatusCode;
rollbarData.Response.Headers = this._httpResponse.Headers?.ToStringDictionary();
rollbarData.Response.Headers = this._httpResponse.Headers?.ToCompactStringDictionary();

// some custom fields goodies:
rollbarData.Response.Add("sub_status_code", this._httpResponse.SubStatusCode);
Expand Down
51 changes: 3 additions & 48 deletions Rollbar.NetCore.AspNet/Rollbar.NetCore.AspNet.csproj
Expand Up @@ -22,53 +22,8 @@
<ProjectReference Include="..\Rollbar\Rollbar.csproj" />
</ItemGroup>

<Choose>
<When Condition="'$(TargetFramework)' == 'net5.0'">
<ItemGroup Label="Unconditional Package References">
<PackageReference Include="Microsoft.AspNetCore.App" Version="5.0.*"/>
</ItemGroup>
</When>
<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<ItemGroup Label="Unconditional Package References">
<PackageReference Include="Microsoft.AspNetCore.App" Version="3.1.*"/>
</ItemGroup>
</When>
</Choose>

<!--Choose>
<When Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PropertyGroup Label=".NetStandard 2.0 build">
<NetVariant>NET_STANDARD</NetVariant>
<DefineConstants>$(DefineConstants);NETSTANDARD_2_0</DefineConstants>
</PropertyGroup>
</When>
<When Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PropertyGroup Label=".NetCore 2.0 build">
<NetVariant>NET_CORE</NetVariant>
<DefineConstants>$(DefineConstants);NETCORE_2_0</DefineConstants>
</PropertyGroup>
</When>
</Choose-->

<!--Choose>
<When Condition="'$(TargetFramework)' == 'net5.0' Or $(TargetFramework.StartsWith('netcoreapp3.')) Or '$(TargetFramework)' == 'netstandard2.1'">
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
</When>
<When Condition="$(TargetFramework.StartsWith('netcoreapp2.')) And '$(TargetFramework)' != 'netcoreapp2.0'">
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.0" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0.0" />
</ItemGroup>
</Otherwise>
</Choose-->
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

</Project>
18 changes: 11 additions & 7 deletions Rollbar.NetCore.AspNet/RollbarMiddleware.cs
Expand Up @@ -153,13 +153,18 @@ RequestDelegate nextRequestProcessor
/// <returns>A middleware invocation/execution task.</returns>
public async Task Invoke(HttpContext context)
{
if (context == null)
{
return;
}

// as we learned from a field issue, apparently a middleware can even be invoked without a valid HttpContext:
string? requestId = null;
requestId = context?.Features?
requestId = context.Features?
.Get<IHttpRequestIdentifierFeature>()?
.TraceIdentifier;

context?.Request.EnableBuffering(); // so that we can rewind the body stream once we are done
context.Request.EnableBuffering(); // so that we can rewind the body stream once we are done

using(_logger.BeginScope($"Request: {requestId ?? string.Empty}"))
{
Expand All @@ -168,14 +173,13 @@ public async Task Invoke(HttpContext context)
try
{
if (RollbarInfrastructure.Instance != null
&& RollbarInfrastructure.Instance.TelemetryCollector != null
&& RollbarInfrastructure.Instance.TelemetryCollector != null
&& RollbarInfrastructure.Instance.TelemetryCollector.IsAutocollecting
&& context != null
&& context.Request != null
)
{
int? telemetryStatusCode = null;
telemetryStatusCode = context?.Response?.StatusCode;
telemetryStatusCode = context.Response?.StatusCode;

networkTelemetry = new NetworkTelemetry(
method: context!.Request.Method,
Expand All @@ -185,9 +189,9 @@ public async Task Invoke(HttpContext context)
statusCode: telemetryStatusCode
);
RollbarInfrastructure.Instance.TelemetryCollector.Capture(new Telemetry(TelemetrySource.Server, TelemetryLevel.Info, networkTelemetry));
}

await this._nextRequestProcessor(context);
await this._nextRequestProcessor(context);
}
}
catch (System.Exception ex)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

namespace Rollbar.Migrations
{
using Microsoft.EntityFrameworkCore.Migrations;

public partial class InitialWithScaffold : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand All @@ -15,3 +17,5 @@ protected override void Down(MigrationBuilder migrationBuilder)
}
}
}

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
@@ -1,7 +1,7 @@
<Project ToolsVersion="Current">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>net48;net472;net471;net47;net462;net461</TargetFrameworks>
<AssemblyName>Rollbar.PlugIns.MSEnterpriseLibrary</AssemblyName>
<RootNamespace>Rollbar.PlugIns.MSEnterpriseLibrary</RootNamespace>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down
2 changes: 1 addition & 1 deletion Rollbar/Common/DateTimeUtil.cs
Expand Up @@ -46,7 +46,7 @@ public static DateTimeOffset ConvertFromUnixTimestampInSeconds(long unixTimestam
/// <param name="inputString">The input string.</param>
/// <param name="dateTimeOffset">The date time offset.</param>
/// <returns><c>true</c> if was able to parse successfully, <c>false</c> otherwise.</returns>
public static bool TryParseFromUnixTimestampInSecondsString(string inputString, out DateTimeOffset dateTimeOffset)
public static bool TryParseFromUnixTimestampInSecondsString(string? inputString, out DateTimeOffset dateTimeOffset)
{
if (long.TryParse(inputString, out long unixTimestamp))
{
Expand Down
2 changes: 1 addition & 1 deletion Rollbar/Common/FileUtility.cs
Expand Up @@ -11,7 +11,7 @@
/// </summary>
public static class FileUtility
{
private static readonly TraceSource traceSource = new TraceSource(typeof(FileUtility).FullName);
private static readonly TraceSource traceSource = new TraceSource(typeof(FileUtility).FullName ?? "FileUtility");

/// <summary>
/// Verifies if the specified application file (a file that is part of an application) exists.
Expand Down
8 changes: 4 additions & 4 deletions Rollbar/Common/HttpHeadersExtension.cs
Expand Up @@ -23,7 +23,7 @@ public static class HttpHeadersExtension
/// <returns>IEnumerable&lt;System.String&gt;.</returns>
public static IEnumerable<string> GetHeaderValuesSafely(this HttpHeaders httpHeaders, string headerName)
{
IEnumerable<string> headerValues;
IEnumerable<string>? headerValues;

if (httpHeaders.TryGetValues(headerName, out headerValues))
{
Expand All @@ -42,9 +42,9 @@ public static IEnumerable<string> GetHeaderValuesSafely(this HttpHeaders httpHea
/// <param name="httpHeaders">The HTTP headers.</param>
/// <param name="headerName">Name of the header.</param>
/// <returns>System.String.</returns>
public static string GetLastHeaderValueSafely(this HttpHeaders httpHeaders, string headerName)
public static string? GetLastHeaderValueSafely(this HttpHeaders httpHeaders, string headerName)
{
string headerValue = httpHeaders.GetHeaderValuesSafely(headerName).LastOrDefault();
string? headerValue = httpHeaders.GetHeaderValuesSafely(headerName).LastOrDefault();
return headerValue;
}

Expand All @@ -59,7 +59,7 @@ public static string GetLastHeaderValueSafely(this HttpHeaders httpHeaders, stri
public static T? ParseHeaderValueSafelyIfAny<T>(this HttpHeaders httpHeaders, string headerName, StringUtility.TryParseHandler<T> tryParseHandler)
where T : struct
{
string stringValue = httpHeaders.GetLastHeaderValueSafely(headerName);
string? stringValue = httpHeaders.GetLastHeaderValueSafely(headerName);
return StringUtility.Parse<T>(stringValue, tryParseHandler);
}

Expand Down
60 changes: 50 additions & 10 deletions Rollbar/Common/NameValueCollectionExtension.cs
@@ -1,44 +1,84 @@
namespace Rollbar.Common
{
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

/// <summary>
/// Class NameValueCollectionExtension.
/// </summary>
public static class NameValueCollectionExtension
{
/// <summary>
/// Converts to string dictionary (where keys are strings and values are strings).
/// Converts to a string dictionary (where keys are strings and values are strings).
/// </summary>
/// <param name="nvc">The NVC.</param>
/// <returns>IDictionary&lt;System.String, System.String&gt;.</returns>
public static IDictionary<string, string> ToStringDictionary(this NameValueCollection nvc)
public static IDictionary<string, string?> ToStringDictionary(this NameValueCollection nvc)
{
if (nvc == null || nvc.Count == 0)
{
return new Dictionary<string, string>();
return new Dictionary<string, string?>(0);
}

return nvc.AllKeys.Where(n => n != null).ToDictionary(k => k, k => nvc[k]);
return nvc.AllKeys.Where(n => n != null).Cast<string>().ToDictionary(k => k, k => nvc[k] as string ?? null);
}

/// <summary>
/// Converts to object dictionary (where keys are strings and values are objects).
/// Converts to a compact (excluding null-values) string dictionary (where keys are strings and values are strings).
/// </summary>
/// <param name="nvc">The NVC.</param>
/// <returns>IDictionary&lt;System.String, System.String&gt;.</returns>
public static IDictionary<string, string> ToCompactStringDictionary(this NameValueCollection nvc)
{
var headers = NameValueCollectionExtension.ToStringDictionary(nvc);

var compactedHeaders = new Dictionary<string, string>(headers.Count);
foreach (var kvp in headers)
{
if (kvp.Value != null)
{
compactedHeaders[kvp.Key] = kvp.Value;
}
}

return compactedHeaders;
}

/// <summary>
/// Converts to an object dictionary (where keys are strings and values are objects).
/// </summary>
/// <param name="nvc">The NVC.</param>
/// <returns>IDictionary&lt;System.String, System.Object&gt;.</returns>
public static IDictionary<string, object> ToObjectDictionary(this NameValueCollection nvc)
public static IDictionary<string, object?> ToObjectDictionary(this NameValueCollection nvc)
{
if (nvc == null || nvc.Count == 0)
{
return new Dictionary<string, object>();
return new Dictionary<string, object?>(0);
}

return nvc.AllKeys.Where(n => n != null).Cast<string>().ToDictionary(k => k, k => nvc[k] as object ?? null);
}

/// <summary>
/// Converts to a compact (excluding null-values) object dictionary (where keys are strings and values are objects).
/// </summary>
/// <param name="nvc">The NVC.</param>
/// <returns>IDictionary&lt;System.String, System.Object&gt;.</returns>
public static IDictionary<string, object> ToCompactObjectDictionary(this NameValueCollection nvc)
{
var headers = NameValueCollectionExtension.ToObjectDictionary(nvc);

var compactedHeaders = new Dictionary<string, object>(headers.Count);
foreach (var kvp in headers)
{
if (kvp.Value != null)
{
compactedHeaders[kvp.Key] = kvp.Value;
}
}

return nvc.AllKeys.Where(n => n != null).ToDictionary(k => k, k => nvc[k] as object);
return compactedHeaders;
}
}
}

0 comments on commit 992c0b6

Please sign in to comment.