Skip to content

Commit

Permalink
Formatted all files according to the new R# settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
asbjornu committed Dec 5, 2014
1 parent 2b60c5d commit 1b49a80
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 136 deletions.
1 change: 0 additions & 1 deletion src/app/SharpRaven/Data/JsonPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

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

using Newtonsoft.Json;

Expand Down
129 changes: 64 additions & 65 deletions src/app/SharpRaven/Data/SentryRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ internal SentryRequest()
}


/// <summary>
/// Gets or sets the HTTP context.
/// </summary>
/// <value>
/// The HTTP context.
/// </value>
internal static dynamic HttpContext { get; set; }


/// <summary>
/// Gets or sets the cookies.
/// </summary>
Expand Down Expand Up @@ -135,6 +126,14 @@ internal SentryRequest()
[JsonProperty(PropertyName = "url", NullValueHandling = NullValueHandling.Ignore)]
public string Url { get; set; }

/// <summary>
/// Gets or sets the HTTP context.
/// </summary>
/// <value>
/// The HTTP context.
/// </value>
internal static dynamic HttpContext { get; set; }

[JsonIgnore]
private static bool HasHttpContext
{
Expand Down Expand Up @@ -173,33 +172,59 @@ public SentryUser GetUser()
}


private static IPrincipal GetPrincipal()
private static IDictionary<string, string> Convert(Func<dynamic, NameObjectCollectionBase> collectionGetter)
{
if (!HasHttpContext)
return null;

IDictionary<string, string> dictionary = new Dictionary<string, string>();

try
{
return HttpContext.User as IPrincipal;
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
var collection = collectionGetter.Invoke(HttpContext);
var keys = Enumerable.ToArray(collection.AllKeys);

return null;
}
foreach (object key in keys)
{
if (key == null)
continue;

string stringKey = key as string ?? key.ToString();

private static dynamic GetIpAddress()
{
try
{
return HttpContext.Request.UserHostAddress;
// NOTE: Ignore these keys as they just add duplicate information. [asbjornu]
if (stringKey.StartsWith("ALL_") || stringKey.StartsWith("HTTP_"))
continue;

var value = collection[stringKey];
string stringValue = value as string;

if (stringValue != null)
{
// Most dictionary values will be strings and go through this path.
dictionary.Add(stringKey, stringValue);
}
else
{
// HttpCookieCollection is an ugly, evil beast that needs to be treated with a sledgehammer.

try
{
// For whatever stupid reason, HttpCookie.ToString() doesn't return its Value, so we need to dive into the .Value property like this.
dictionary.Add(stringKey, value.Value);
}
catch (Exception exception)
{
dictionary.Add(stringKey, exception.ToString());
}
}
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

return null;
return dictionary;
}


Expand Down Expand Up @@ -238,59 +263,33 @@ private static void GetHttpContext()
}


private static IDictionary<string, string> Convert(Func<dynamic, NameObjectCollectionBase> collectionGetter)
private static dynamic GetIpAddress()
{
if (!HasHttpContext)
return null;

IDictionary<string, string> dictionary = new Dictionary<string, string>();

try
{
var collection = collectionGetter.Invoke(HttpContext);
var keys = Enumerable.ToArray(collection.AllKeys);

foreach (object key in keys)
{
if (key == null)
continue;

string stringKey = key as string ?? key.ToString();

// NOTE: Ignore these keys as they just add duplicate information. [asbjornu]
if (stringKey.StartsWith("ALL_") || stringKey.StartsWith("HTTP_"))
continue;
return HttpContext.Request.UserHostAddress;
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

var value = collection[stringKey];
string stringValue = value as string;
return null;
}

if (stringValue != null)
{
// Most dictionary values will be strings and go through this path.
dictionary.Add(stringKey, stringValue);
}
else
{
// HttpCookieCollection is an ugly, evil beast that needs to be treated with a sledgehammer.

try
{
// For whatever stupid reason, HttpCookie.ToString() doesn't return its Value, so we need to dive into the .Value property like this.
dictionary.Add(stringKey, value.Value);
}
catch (Exception exception)
{
dictionary.Add(stringKey, exception.ToString());
}
}
}
private static IPrincipal GetPrincipal()
{
try
{
return HttpContext.User as IPrincipal;
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

return dictionary;
return null;
}
}
}
22 changes: 11 additions & 11 deletions src/app/SharpRaven/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly : AssemblyTitle("SharpRaven")]
[assembly : AssemblyDescription("SharpRaven is a C# client for Sentry https://www.getsentry.com")]
[assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("Sentry")]
[assembly : AssemblyProduct("SharpRaven")]
[assembly : AssemblyCopyright("Copyright © Sentry 2014")]
[assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")]
[assembly : ComVisible(false)]
[assembly : Guid("b5683941-1254-484e-b074-87cedd4fc78e")]
[assembly : InternalsVisibleTo("SharpRaven.UnitTests")]
[assembly: AssemblyTitle("SharpRaven")]
[assembly: AssemblyDescription("SharpRaven is a C# client for Sentry https://www.getsentry.com")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Sentry")]
[assembly: AssemblyProduct("SharpRaven")]
[assembly: AssemblyCopyright("Copyright © Sentry 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("b5683941-1254-484e-b074-87cedd4fc78e")]
[assembly: InternalsVisibleTo("SharpRaven.UnitTests")]
4 changes: 2 additions & 2 deletions src/app/SharpRaven/RavenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ protected virtual string Send(JsonPacket packet, Dsn dsn)
try
{
var request = (HttpWebRequest) WebRequest.Create(dsn.SentryUri);
request.Timeout = (int)Timeout.TotalMilliseconds;
request.ReadWriteTimeout = (int)Timeout.TotalMilliseconds;
request.Timeout = (int) Timeout.TotalMilliseconds;
request.ReadWriteTimeout = (int) Timeout.TotalMilliseconds;
request.Method = "POST";
request.Accept = "application/json";
request.Headers.Add("X-Sentry-Auth", PacketBuilder.CreateAuthenticationHeader(dsn));
Expand Down
2 changes: 1 addition & 1 deletion src/app/SharpRaven/Utilities/PacketBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static string CreateAuthenticationHeader(Dsn dsn)
+ ", sentry_secret={4}",
SentryVersion,
UserAgent,
(long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds,
(long) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds,
dsn.PublicKey,
dsn.PrivateKey);
}
Expand Down
10 changes: 5 additions & 5 deletions src/tests/SharpRaven.UnitTests/Data/JsonPacketFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Create_InvokesOnCreate()
{
var project = Guid.NewGuid().ToString("N");
var factory = new TestableJsonPacketFactory(project);
var json = factory.Create(String.Empty, (SentryMessage)null);
var json = factory.Create(String.Empty, (SentryMessage) null);

Assert.That(json.Project, Is.EqualTo(project));
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public void Create_ProjectAndException_ServerNameEqualsMachineName()
public void Create_Project_EventIDIsValidGuid()
{
var project = Guid.NewGuid().ToString();
var json = this.jsonPacketFactory.Create(project, (SentryMessage)null);
var json = this.jsonPacketFactory.Create(project, (SentryMessage) null);

Assert.That(json.EventID, Is.Not.Null.Or.Empty, "EventID");
Assert.That(Guid.Parse(json.EventID), Is.Not.Null);
Expand All @@ -148,7 +148,7 @@ public void Create_Project_EventIDIsValidGuid()
public void Create_Project_ModulesHasCountGreaterThanZero()
{
var project = Guid.NewGuid().ToString();
var json = this.jsonPacketFactory.Create(project, (SentryMessage)null);
var json = this.jsonPacketFactory.Create(project, (SentryMessage) null);

Assert.That(json.Modules, Has.Count.GreaterThan(0));
}
Expand All @@ -158,7 +158,7 @@ public void Create_Project_ModulesHasCountGreaterThanZero()
public void Create_Project_ProjectIsEqual()
{
var project = Guid.NewGuid().ToString();
var json = this.jsonPacketFactory.Create(project, (SentryMessage)null);
var json = this.jsonPacketFactory.Create(project, (SentryMessage) null);

Assert.That(json.Project, Is.EqualTo(project));
}
Expand All @@ -168,7 +168,7 @@ public void Create_Project_ProjectIsEqual()
public void Create_Project_ServerNameEqualsMachineName()
{
var project = Guid.NewGuid().ToString();
var json = this.jsonPacketFactory.Create(project, (SentryMessage)null);
var json = this.jsonPacketFactory.Create(project, (SentryMessage) null);

Assert.That(json.ServerName, Is.EqualTo(Environment.MachineName));
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/SharpRaven.UnitTests/Data/JsonPacketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void Constructor_WithHttpContext_RequestDataContainsExpectedItem()
{
Assert.That(json.Request.Data, Is.Not.Null);
Assert.That(json.Request.Data, Is.TypeOf<Dictionary<string, string>>());
var data = (Dictionary<string, string>)json.Request.Data;
var data = (Dictionary<string, string>) json.Request.Data;
Assert.That(data, Has.Count.EqualTo(1));
Assert.That(data, Has.Member(new KeyValuePair<string, string>("Form1", "Value1")));
});
Expand Down
3 changes: 3 additions & 0 deletions src/tests/SharpRaven.UnitTests/Data/SentryRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace SharpRaven.UnitTests.Data
[TestFixture]
public class SentryRequestTests
{
#region Setup/Teardown

[SetUp]
public void SetUp()
{
Expand All @@ -56,6 +58,7 @@ public void TearDown()
SentryRequest.HttpContext = null;
}

#endregion

private static void SimulateHttpRequest(Action<SentryRequest> test)
{
Expand Down
4 changes: 2 additions & 2 deletions src/tests/SharpRaven.UnitTests/Data/SentryUserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public void Constructor_AssignedPrincipal_UsernameIsSet()
[Test]
public void Constructor_NullPrincipal_DoesNotThrow()
{
var user = new SentryUser((IPrincipal)null);
var user = new SentryUser((IPrincipal) null);
Assert.That(user.Username, Is.Null);
}


[Test]
public void Constructor_NullUsername_DoesNotThrow()
{
var user = new SentryUser((string)null);
var user = new SentryUser((string) null);
Assert.That(user.Username, Is.Null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/SharpRaven.UnitTests/Integration/CaptureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void CaptureException_WithStacktrace_ReturnsValidID()
tags["TAG"] = "TAG1";
extra["extra"] = "EXTRA1";

var id = this.ravenClient.CaptureException(e, tags : tags, extra : extra);
var id = this.ravenClient.CaptureException(e, tags: tags, extra: extra);

//Console.WriteLine("Sent packet: " + id);

Expand Down
24 changes: 12 additions & 12 deletions src/tests/SharpRaven.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.

[assembly : AssemblyTitle("SharpRaven.UnitTests")]
[assembly : AssemblyDescription("")]
[assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("")]
[assembly : AssemblyProduct("SharpRaven.UnitTests")]
[assembly : AssemblyCopyright("Copyright © 2013")]
[assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")]
[assembly: AssemblyTitle("SharpRaven.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SharpRaven.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.

[assembly : ComVisible(false)]
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM

[assembly : Guid("cf1c285c-42e3-46f3-a8b1-9339c3f1f8ae")]
[assembly: Guid("cf1c285c-42e3-46f3-a8b1-9339c3f1f8ae")]

// Version information for an assembly consists of the following four values:
//
Expand All @@ -65,5 +65,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly : AssemblyVersion("1.0.0.0")]
[assembly : AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 2 additions & 2 deletions src/tests/SharpRaven.UnitTests/RavenClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ public void CaptureMessage_ScrubberIsInvoked()
[Test]
public void Constructor_NullDsnString_ThrowsArgumentNullException()
{
var exception = Assert.Throws<ArgumentNullException>(() => new RavenClient((string)null));
var exception = Assert.Throws<ArgumentNullException>(() => new RavenClient((string) null));
Assert.That(exception.ParamName, Is.EqualTo("dsn"));
}


[Test]
public void Constructor_NullDsn_ThrowsArgumentNullException()
{
var exception = Assert.Throws<ArgumentNullException>(() => new RavenClient((Dsn)null));
var exception = Assert.Throws<ArgumentNullException>(() => new RavenClient((Dsn) null));
Assert.That(exception.ParamName, Is.EqualTo("dsn"));
}

Expand Down
Loading

0 comments on commit 1b49a80

Please sign in to comment.