Skip to content

Commit

Permalink
Merge pull request #411 from MindscapeHQ/Intercomm-ticket-resolution
Browse files Browse the repository at this point in the history
Added shared singleton for instantiating the web client.
  • Loading branch information
grugcrood82 authored Sep 16, 2019
2 parents 31bc3f8 + 51bcbec commit e353fe3
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.2" />
<package id="psake" version="4.3.2" />
<package id="psake" version="4.8.0" />
</packages>
4 changes: 2 additions & 2 deletions AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.8.0.0")]
[assembly: AssemblyFileVersion("5.8.0.0")]
[assembly: AssemblyVersion("5.9.0.0")]
[assembly: AssemblyFileVersion("5.9.0.0")]
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net.Core.Signed.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.Core.Signed</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title />
<authors>Raygun</authors>
<owners />
Expand Down
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.Core</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title />
<authors>Raygun</authors>
<owners />
Expand Down
4 changes: 2 additions & 2 deletions Mindscape.Raygun4Net.Mvc.Signed.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.Mvc.Signed</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title />
<authors>Raygun</authors>
<owners />
Expand All @@ -12,7 +12,7 @@
<projectUrl>https://github.com/MindscapeHQ/raygun4net</projectUrl>
<licenseUrl>https://raw.github.com/MindscapeHQ/raygun4net/master/LICENSE</licenseUrl>
<dependencies>
<dependency id="Mindscape.Raygun4Net.Core.Signed" version="5.7.0" />
<dependency id="Mindscape.Raygun4Net.Core.Signed" version="5.9.0" />
</dependencies>
</metadata>
<files>
Expand Down
4 changes: 2 additions & 2 deletions Mindscape.Raygun4Net.Mvc.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.Mvc</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title />
<authors>Raygun</authors>
<owners />
Expand All @@ -12,7 +12,7 @@
<projectUrl>https://github.com/MindscapeHQ/raygun4net</projectUrl>
<licenseUrl>https://raw.github.com/MindscapeHQ/raygun4net/master/LICENSE</licenseUrl>
<dependencies>
<dependency id="Mindscape.Raygun4Net.Core" version="5.7.0" />
<dependency id="Mindscape.Raygun4Net.Core" version="5.9.0" />
</dependencies>
</metadata>
<files>
Expand Down
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net.Signed.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.Signed</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title />
<authors>Raygun</authors>
<owners />
Expand Down
4 changes: 2 additions & 2 deletions Mindscape.Raygun4Net.WebApi.Signed.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.WebApi.Signed</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title>Raygun for ASP.NET Web API</title>
<authors>Raygun</authors>
<owners />
Expand All @@ -13,7 +13,7 @@
<projectUrl>https://github.com/MindscapeHQ/raygun4net</projectUrl>
<licenseUrl>https://raw.github.com/MindscapeHQ/raygun4net/master/LICENSE</licenseUrl>
<dependencies>
<dependency id="Mindscape.Raygun4Net.Core.Signed" version="5.7.0" />
<dependency id="Mindscape.Raygun4Net.Core.Signed" version="5.9.0" />
</dependencies>
</metadata>
<files>
Expand Down
4 changes: 2 additions & 2 deletions Mindscape.Raygun4Net.WebApi.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net.WebApi</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title>Raygun for ASP.NET Web API</title>
<authors>Raygun</authors>
<owners />
Expand All @@ -13,7 +13,7 @@
<projectUrl>https://github.com/MindscapeHQ/raygun4net</projectUrl>
<licenseUrl>https://raw.github.com/MindscapeHQ/raygun4net/master/LICENSE</licenseUrl>
<dependencies>
<dependency id="Mindscape.Raygun4Net.Core" version="5.7.0" />
<dependency id="Mindscape.Raygun4Net.Core" version="5.9.0" />
</dependencies>
</metadata>
<files>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Mindscape.Raygun4Net4\WebClientHelper.cs">
<Link>WebClientHelper.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyVersionInfo.cs" />
<Compile Include="Extensions\RaygunHttpContentExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Mindscape.Raygun4Net.WebApi/Properties/AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.8.0.0")]
[assembly: AssemblyFileVersion("5.8.0.0")]
[assembly: AssemblyVersion("5.9.0.0")]
[assembly: AssemblyFileVersion("5.9.0.0")]
90 changes: 32 additions & 58 deletions Mindscape.Raygun4Net.WebApi/RaygunWebApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,6 @@ public static void Detach(HttpConfiguration config)
}
}

protected bool ValidateApiKey()
{
if (string.IsNullOrEmpty(_apiKey))
{
System.Diagnostics.Debug.WriteLine("ApiKey has not been provided, exception will not be logged");
return false;
}
return true;
}

/// <summary>
/// Gets or sets the username/password credentials which are used to authenticate with the system default Proxy server, if one is set
/// and requires credentials.
Expand All @@ -252,6 +242,7 @@ protected override bool CanSend(Exception exception)
{
return false;
}

return base.CanSend(exception);
}

Expand All @@ -261,6 +252,7 @@ protected bool CanSend(RaygunMessage message)
{
return !RaygunSettings.Settings.ExcludedStatusCodes.Contains(message.Details.Response.StatusCode);
}

return true;
}

Expand Down Expand Up @@ -419,7 +411,7 @@ public void AddRawDataFilter(IRaygunDataFilter filter)
/// <param name="exception">The exception to deliver.</param>
public override void Send(Exception exception)
{
Send(exception, null, (IDictionary)null);
Send(exception, null, (IDictionary) null);
}

/// <summary>
Expand All @@ -430,7 +422,7 @@ public override void Send(Exception exception)
/// <param name="tags">A list of strings associated with the message.</param>
public void Send(Exception exception, IList<string> tags)
{
Send(exception, tags, (IDictionary)null);
Send(exception, tags, (IDictionary) null);
}

/// <summary>
Expand Down Expand Up @@ -458,7 +450,7 @@ public void Send(Exception exception, IList<string> tags, IDictionary userCustom
/// <param name="exception">The exception to deliver.</param>
public void SendInBackground(Exception exception)
{
SendInBackground(exception, null, (IDictionary)null);
SendInBackground(exception, null, (IDictionary) null);
}

/// <summary>
Expand All @@ -468,7 +460,7 @@ public void SendInBackground(Exception exception)
/// <param name="tags">A list of strings associated with the message.</param>
public void SendInBackground(Exception exception, IList<string> tags)
{
SendInBackground(exception, tags, (IDictionary)null);
SendInBackground(exception, tags, (IDictionary) null);
}

/// <summary>
Expand All @@ -486,7 +478,8 @@ public void SendInBackground(Exception exception, IList<string> tags, IDictionar
RaygunRequestMessage currentRequestMessage = BuildRequestMessage();
DateTime currentTime = DateTime.UtcNow;

ThreadPool.QueueUserWorkItem(c => {
ThreadPool.QueueUserWorkItem(c =>
{
_currentRequestMessage.Value = currentRequestMessage;
StripAndSend(exception, tags, userCustomData, currentTime);
});
Expand Down Expand Up @@ -547,6 +540,7 @@ protected RaygunMessage BuildMessage(Exception exception, IList<string> tags, ID
{
message.Details.GroupingKey = customGroupingKey;
}

return message;
}

Expand Down Expand Up @@ -585,11 +579,15 @@ protected IEnumerable<Exception> StripWrapperExceptions(Exception exception)
{
e.Data["Type"] = rtle.Types[index];
}
catch { }
catch
{
}

foreach (Exception ex in StripWrapperExceptions(e))
{
yield return ex;
}

index++;
}
}
Expand All @@ -615,53 +613,29 @@ protected IEnumerable<Exception> StripWrapperExceptions(Exception exception)
/// set to a valid DateTime and as much of the Details property as is available.</param>
public override void Send(RaygunMessage raygunMessage)
{
if (ValidateApiKey())
try
{
bool canSend = OnSendingMessage(raygunMessage) && CanSend(raygunMessage);
if (canSend)
{
using (var client = new WebClient())
{
client.Headers.Add("X-ApiKey", _apiKey);
client.Headers.Add("content-type", "application/json; charset=utf-8");
client.Encoding = System.Text.Encoding.UTF8;

if (WebRequest.DefaultWebProxy != null)
{
Uri proxyUri = WebRequest.DefaultWebProxy.GetProxy(new Uri(RaygunSettings.Settings.ApiEndpoint.ToString()));

if (proxyUri != null && proxyUri.AbsoluteUri != RaygunSettings.Settings.ApiEndpoint.ToString())
{
client.Proxy = new WebProxy(proxyUri, false);

if (ProxyCredentials == null)
{
client.UseDefaultCredentials = true;
client.Proxy.Credentials = CredentialCache.DefaultCredentials;
}
else
{
client.UseDefaultCredentials = false;
client.Proxy.Credentials = ProxyCredentials;
}
}
}

try
{
var message = SimpleJson.SerializeObject(raygunMessage);
client.UploadString(RaygunSettings.Settings.ApiEndpoint, message);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
var message = SimpleJson.SerializeObject(raygunMessage);
WebClientHelper.Send(message, _apiKey, ProxyCredentials);
}
}
catch (Exception ex)
{
try
{
System.Diagnostics.Trace.WriteLine(string.Format("Error Logging Exception to Raygun.io {0}", ex.Message));
}
catch
{
// ignored
}

if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
}
if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion Mindscape.Raygun4Net.WebApi/RaygunWebApiDelegatingHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;

Expand All @@ -23,7 +24,16 @@ protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAs
}
}

return await base.SendAsync(request, cancellationToken);
var response = await base.SendAsync(request, cancellationToken);
if (cancellationToken.IsCancellationRequested)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
ReasonPhrase = "The request was cancelled by the client"
};
}

return response;
}
}
}
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Mindscape.Raygun4Net</id>
<version>5.8.0</version>
<version>5.9.0</version>
<title />
<authors>Raygun</authors>
<owners />
Expand Down
12 changes: 6 additions & 6 deletions Mindscape.Raygun4Net/Mindscape.Raygun4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Sign|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Sign\</OutputPath>
<DefineConstants>SIGN;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<DefineConstants>SIGN;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Raygun4Net.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net/SimpleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, objec

if (visited.Contains(value))
{
return SerializeString(CYCLIC_MESSAGE, builder); ;
return SerializeString(CYCLIC_MESSAGE, builder);
}

visited.Push(value);
Expand Down
5 changes: 3 additions & 2 deletions Mindscape.Raygun4Net4/Mindscape.Raygun4Net4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Sign|AnyCPU' ">
<AssemblyOriginatorKeyFile>Raygun4Net4.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<SignAssembly>true</SignAssembly>
<OutputPath>bin\Sign\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
Expand Down Expand Up @@ -89,6 +89,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RaygunClient.cs" />
<Compile Include="WebClientHelper.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mindscape.Raygun4Net.Core\Mindscape.Raygun4Net.Core.csproj">
Expand Down
Loading

0 comments on commit e353fe3

Please sign in to comment.