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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop: (25 commits)
  Add back .NET 4.0 compatibility
  Verified tests
  Added test for ErrorLevel
  Skip ExceptionData of InnerException if it is empty
  Added back Unix guards
  Log level is not set on JsonPacket
  #114 Check if httpcontext is available and reuse properties from reflection.
  Upgraded GitVersionTask from v3.3.0 to v3.4.1
  Set the next version to 2.1
  Wrap async in !net40 regions
  Adjusted namespace and removed the RavenClient prefix of the RavenClient test classes
  Moved RavenClient tests into a RavenClientTests folder
  Added CaptureException tests
  Tidied up async tests
  Added Capture tests
  Added CaptureAsync() tests
  Merge tags in Capture(SentryEvent)
  Fixed InvokesSendAndJsonPacketFactoryOnCreate async test
  Set LastPacket in async as well
  Add CaptureMessageAsync tests
  ...
  • Loading branch information
asbjornu committed Apr 6, 2016
2 parents 2b94249 + a835694 commit ef56df9
Show file tree
Hide file tree
Showing 28 changed files with 1,463 additions and 245 deletions.
2 changes: 1 addition & 1 deletion GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 2.0
next-version: 2.1
branches:
feature[/-]:
mode: ContinuousDeployment
Expand Down
6 changes: 3 additions & 3 deletions src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>05c78a3e</NuGetPackageImportStamp>
<NuGetPackageImportStamp>ec5b9b6c</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 4.0|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -102,11 +102,11 @@
<None Include="SharpRaven.Nancy.nuspec" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets') And '$(OS)' != 'Unix'" />
<Import Project="..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets') And '$(OS)' != 'Unix'" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.3.3.0\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets'))" />
<Error Condition="!Exists('..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.3.4.1\Build\portable-net+sl+win+wpa+wp\GitVersionTask.targets'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/app/SharpRaven.Nancy/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GitVersionTask" version="3.3.0" targetFramework="net45" developmentDependency="true" />
<package id="GitVersionTask" version="3.4.1" targetFramework="net45" developmentDependency="true" />
<package id="Nancy" version="1.4.3" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net40" />
</packages>
6 changes: 6 additions & 0 deletions src/app/SharpRaven/Data/ExceptionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public ExceptionData(Exception exception)
return;

var exceptionData = new ExceptionData(exception.InnerException);

if (exceptionData.Count == 0)
{
return;
}

exceptionData.AddTo(this);
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/SharpRaven/Data/IJsonPacketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public interface IJsonPacketFactory
/// <returns>
/// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
/// </returns>
[Obsolete("Use Create(string, SentryEvent) instead.")]
JsonPacket Create(string project,
SentryMessage message,
ErrorLevel level = ErrorLevel.Info,
Expand All @@ -76,6 +77,7 @@ JsonPacket Create(string project,
/// A new instance of <see cref="JsonPacket" /> for the specified
/// <paramref name="project" />, with the given <paramref name="exception" />.
/// </returns>
[Obsolete("Use Create(string, SentryEvent) instead.")]
JsonPacket Create(string project,
Exception exception,
SentryMessage message = null,
Expand Down
56 changes: 56 additions & 0 deletions src/app/SharpRaven/Data/JsonPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using SharpRaven.Serialization;
using SharpRaven.Utilities;
Expand Down Expand Up @@ -72,10 +74,64 @@ public JsonPacket(string project, SentryEvent @event)
Initialize(@event.Exception);

Message = @event.Message != null ? @event.Message.ToString() : null;
Level = @event.Level;
Extra = Merge(@event);
Tags = @event.Tags;
Fingerprint = @event.Fingerprint.ToArray();
MessageObject = @event.Message;
}


private static object Merge(SentryEvent @event)
{
var exception = @event.Exception;
var extra = @event.Extra;

if (exception == null && extra == null)
return null;

if (extra != null && exception == null)
return extra;

var exceptionData = new ExceptionData(exception);

if (extra == null)
return exceptionData;

JObject result;

if (extra.GetType().IsArray)
{
result = new JObject();
var array = JArray.FromObject(extra);

foreach (var o in array)
{
var jo = o as JObject;
JProperty[] properties;

if (jo == null || (properties = jo.Properties().ToArray()).Length != 2 || properties[0].Name != "Key"
|| properties[1].Name != "Value")
{
result.Merge(o);
continue;
}

var key = properties[0].Value.ToString();
var value = properties[1].Value;
result.Add(key, value);
}
}
else
result = JObject.FromObject(extra);

var jExceptionData = JObject.FromObject(exceptionData);
result.Merge(jExceptionData);

return result;
}


/// <summary>
/// Initializes a new instance of the <see cref="JsonPacket"/> class.
/// </summary>
Expand Down
70 changes: 10 additions & 60 deletions src/app/SharpRaven/Data/JsonPacketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
using System.Collections.Generic;
using System.Linq;

using Newtonsoft.Json.Linq;

namespace SharpRaven.Data
{
/// <summary>
Expand All @@ -56,24 +54,23 @@ public class JsonPacketFactory : IJsonPacketFactory
/// <returns>
/// A new instance of <see cref="JsonPacket" /> for the specified <paramref name="project" />.
/// </returns>
[Obsolete("Use Create(string, SentryEvent) instead.")]
public JsonPacket Create(string project,
SentryMessage message,
ErrorLevel level = ErrorLevel.Info,
IDictionary<string, string> tags = null,
string[] fingerprint = null,
object extra = null)
{
var json = new JsonPacket(project)
var @event = new SentryEvent(message)
{
Message = message != null ? message.ToString() : null,
MessageObject = message,
Level = level,
Extra = extra,
Tags = tags,
Fingerprint = fingerprint,
Extra = Merge(extra)
Fingerprint = fingerprint
};

return OnCreate(json);
return Create(project, @event);
}


Expand All @@ -98,6 +95,7 @@ public JsonPacket Create(string project,
/// given
/// <paramref name="exception" />.
/// </returns>
[Obsolete("Use Create(string, SentryEvent) instead.")]
public JsonPacket Create(string project,
Exception exception,
SentryMessage message = null,
Expand All @@ -106,17 +104,16 @@ public JsonPacket Create(string project,
string[] fingerprint = null,
object extra = null)
{
var json = new JsonPacket(project, exception)
var @event = new SentryEvent(exception)
{
Message = message != null ? message.ToString() : exception.Message,
MessageObject = message,
Message = message,
Level = level,
Extra = extra,
Tags = tags,
Fingerprint = fingerprint,
Extra = Merge(extra, exception)
};

return OnCreate(json);
return Create(project, @event);
}


Expand Down Expand Up @@ -149,52 +146,5 @@ protected virtual JsonPacket OnCreate(JsonPacket jsonPacket)
{
return jsonPacket;
}


private static object Merge(object extra, Exception exception = null)
{
if (exception == null && extra == null)
return null;

if (extra != null && exception == null)
return extra;

var exceptionData = new ExceptionData(exception);

if (extra == null)
return exceptionData;

JObject result;

if (extra.GetType().IsArray)
{
result = new JObject();
var array = JArray.FromObject(extra);

foreach (var o in array)
{
var jo = o as JObject;
JProperty[] properties;

if (jo == null || (properties = jo.Properties().ToArray()).Length != 2 || properties[0].Name != "Key"
|| properties[1].Name != "Value")
{
result.Merge(o);
continue;
}

var key = properties[0].Value.ToString();
var value = properties[1].Value;
result.Add(key, value);
}
}
else
result = JObject.FromObject(extra);

var jExceptionData = JObject.FromObject(exceptionData);
result.Merge(jExceptionData);

return result;
}
}
}
17 changes: 12 additions & 5 deletions src/app/SharpRaven/Data/SentryEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace SharpRaven.Data
public class SentryEvent
{
private readonly Exception exception;
private readonly IList<string> fingerprint;
private readonly IDictionary<string, string> tags;
private IList<string> fingerprint;
private SentryMessage message;
private IDictionary<string, string> tags;


/// <summary>Initializes a new instance of the <see cref="SentryEvent" /> class.</summary>
Expand All @@ -65,8 +66,8 @@ public SentryEvent(SentryMessage message)
/// <summary>Prevents a default instance of the <see cref="SentryEvent"/> class from being created.</summary>
private SentryEvent()
{
this.tags = new Dictionary<string, string>();
this.fingerprint = new List<string>();
Tags = new Dictionary<string, string>();
Fingerprint = new List<string>();
}


Expand All @@ -92,6 +93,7 @@ public Exception Exception
public IList<string> Fingerprint
{
get { return this.fingerprint; }
internal set { this.fingerprint = value ?? new List<string>(); }
}

/// <summary>
Expand All @@ -108,7 +110,11 @@ public IList<string> Fingerprint
/// <value>
/// The optional message to capture instead of the default <see cref="T:Exception.Message" />.
/// </value>
public SentryMessage Message { get; set; }
public SentryMessage Message
{
get { return this.message ?? (Exception != null ? Exception.Message : null); }
set { this.message = value; }
}

/// <summary>Gets the tags to annotate the captured <see name="Exception" /> or <see cref="Message" /> with.</summary>
/// <value>
Expand All @@ -117,6 +123,7 @@ public IList<string> Fingerprint
public IDictionary<string, string> Tags
{
get { return this.tags; }
internal set { this.tags = value ?? new Dictionary<string, string>(); }
}
}
}
Loading

0 comments on commit ef56df9

Please sign in to comment.