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

Commit

Permalink
Made checkedForHttpContextProperty a field and did a R# cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
asbjornu committed Aug 12, 2016
1 parent 51d2276 commit b5196ac
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions src/app/SharpRaven/Data/SentryRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

using Newtonsoft.Json;
using System.IO;
using System.Text;

namespace SharpRaven.Data
{
Expand All @@ -46,6 +46,22 @@ namespace SharpRaven.Data
/// </summary>
public class SentryRequestFactory : ISentryRequestFactory
{
private static bool checkedForHttpContextProperty;

/// <summary>
/// Gets or sets the CurrentHttpContextProperty
/// </summary>
/// <value>
/// The current httpcontext property
/// </value>
internal static dynamic CurrentHttpContextProperty { get; set; }

[JsonIgnore]
internal static bool HasCurrentHttpContextProperty
{
get { return CurrentHttpContextProperty != null; }
}

[JsonIgnore]
internal static bool HasHttpContext
{
Expand All @@ -63,7 +79,7 @@ internal static dynamic HttpContext
get
{
TryGetHttpContextPropertyFromAppDomain();

// [Meilu] If the currentHttpcontext property is not available we couldnt retrieve it, dont continue
if (!HasCurrentHttpContextProperty)
return null;
Expand All @@ -80,22 +96,6 @@ internal static dynamic HttpContext
}
}

/// <summary>
/// Gets or sets the CurrentHttpContextProperty
/// </summary>
/// <value>
/// The current httpcontext property
/// </value>
internal static dynamic CurrentHttpContextProperty { get; set; }

[JsonIgnore]
internal static bool HasCurrentHttpContextProperty
{
get { return CurrentHttpContextProperty != null; }
}

[JsonIgnore]
internal static bool CheckedForHttpContextProperty { get; set; }

/// <summary>
/// Creates a new instance of <see cref="SentryRequest"/>
Expand All @@ -107,7 +107,7 @@ public ISentryRequest Create()
if (!HasHttpContext || HttpContext.Request == null)
return OnCreate(null);

var request = new SentryRequest()
var request = new SentryRequest
{
Url = HttpContext.Request.Url.ToString(),
Method = HttpContext.Request.HttpMethod,
Expand Down Expand Up @@ -147,19 +147,16 @@ private static object BodyConvert()
{
return Convert(x => x.Request.Form);
}
else
{
string body = String.Empty;
var body = string.Empty;

using (MemoryStream stream = new MemoryStream())
{
HttpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
HttpContext.Request.InputStream.CopyTo(stream);
body = Encoding.UTF8.GetString(stream.ToArray());
}

return body;
using (var stream = new MemoryStream())
{
HttpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
HttpContext.Request.InputStream.CopyTo(stream);
body = Encoding.UTF8.GetString(stream.ToArray());
}

return body;
}
catch (Exception exception)
{
Expand Down Expand Up @@ -187,14 +184,14 @@ private static IDictionary<string, string> Convert(Func<dynamic, NameObjectColle
if (key == null)
continue;

string stringKey = key as string ?? key.ToString();
var 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;

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

if (stringValue != null)
{
Expand Down Expand Up @@ -228,10 +225,10 @@ private static IDictionary<string, string> Convert(Func<dynamic, NameObjectColle

private static void TryGetHttpContextPropertyFromAppDomain()
{
if (CheckedForHttpContextProperty)
if (checkedForHttpContextProperty)
return;

CheckedForHttpContextProperty = true;
checkedForHttpContextProperty = true;

try
{
Expand Down

0 comments on commit b5196ac

Please sign in to comment.