Skip to content

Commit

Permalink
Merge pull request #161 from MindscapeHQ/webapi-experiment
Browse files Browse the repository at this point in the history
Webapi experiment
  • Loading branch information
QuantumNightmare committed Jul 30, 2014
2 parents a0712bc + 4b55b79 commit 3edf369
Show file tree
Hide file tree
Showing 32 changed files with 1,637 additions and 27 deletions.
4 changes: 2 additions & 2 deletions AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,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("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
[assembly: AssemblyVersion("3.2.0.0")]
[assembly: AssemblyFileVersion("3.2.0.0")]
4 changes: 3 additions & 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>3.1.0</version>
<version>3.2.0</version>
<title />
<authors>Mindscape</authors>
<owners />
Expand All @@ -19,6 +19,8 @@
<file src="build\signed\Mindscape.Raygun4Net.dll" target="lib\net35\Mindscape.Raygun4Net.dll" />
<!-- .NET 4.0 -->
<file src="build\signed\Net4\Mindscape.Raygun4Net.dll" target="lib\net40\Mindscape.Raygun4Net.dll" />
<!-- .NET 4.5 -->
<file src="build\signed\Net45\Mindscape.Raygun4Net.dll" target="lib\net45\Mindscape.Raygun4Net.dll" />
<!-- Xamarin.Android -->
<file src="build\Mindscape.Raygun4Net.Xamarin.Android.dll" target="lib\MonoAndroid2.2\Mindscape.Raygun4Net.Xamarin.Android.dll" />
<file src="build\Mindscape.Raygun4Net.Xamarin.Android.pdb" target="lib\MonoAndroid2.2\Mindscape.Raygun4Net.Xamarin.Android.pdb" />
Expand Down
5 changes: 4 additions & 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>3.1.0</version>
<version>3.2.0</version>
<title />
<authors>Mindscape</authors>
<owners />
Expand All @@ -22,6 +22,9 @@
<!-- .NET 4.0 -->
<file src="build\Net4\Mindscape.Raygun4Net.dll" target="lib\net40\Mindscape.Raygun4Net.dll" />
<file src="build\Net4\Mindscape.Raygun4Net.pdb" target="lib\net40\Mindscape.Raygun4Net.pdb" />
<!-- .NET 4.5 -->
<file src="build\Net45\Mindscape.Raygun4Net.dll" target="lib\net45\Mindscape.Raygun4Net.dll" />
<file src="build\Net45\Mindscape.Raygun4Net.pdb" target="lib\net45\Mindscape.Raygun4Net.pdb" />
<!-- Xamarin.Android -->
<file src="build\Mindscape.Raygun4Net.Xamarin.Android.dll" target="lib\MonoAndroid2.2\Mindscape.Raygun4Net.Xamarin.Android.dll" />
<file src="build\Mindscape.Raygun4Net.Xamarin.Android.pdb" target="lib\MonoAndroid2.2\Mindscape.Raygun4Net.Xamarin.Android.pdb" />
Expand Down
1 change: 0 additions & 1 deletion Mindscape.Raygun4Net/Messages/RaygunEnvironmentMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Security;
using System.Text;

using System.Web;
using System.Windows.Forms;
using System.Management;
using Microsoft.VisualBasic.Devices;
Expand Down
5 changes: 2 additions & 3 deletions Mindscape.Raygun4Net/Messages/RaygunRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Mindscape.Raygun4Net.Messages
{
public class RaygunRequestMessage
{
public RaygunRequestMessage(HttpRequest request, RaygunRequestMessageOptions options)
public RaygunRequestMessage(HttpRequest request, RaygunRequestMessageOptions options)
{
options = options ?? new RaygunRequestMessageOptions();

Expand Down Expand Up @@ -158,6 +158,5 @@ public Cookie(string name, string value)
public string RawData { get; set; }

public IDictionary Headers { get; set; }

}
}
}
7 changes: 1 addition & 6 deletions Mindscape.Raygun4Net/Messages/RaygunResponseMessage.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Mindscape.Raygun4Net.Messages
namespace Mindscape.Raygun4Net.Messages
{
public class RaygunResponseMessage
{
Expand Down
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net/RaygunClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public void Send(RaygunMessage raygunMessage)
else
{
client.UseDefaultCredentials = false;
client.Proxy.Credentials = ProxyCredentials;
client.Proxy.Credentials = ProxyCredentials;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Mindscape.Raygun4Net/RaygunMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Mindscape.Raygun4Net
{
public class RaygunMessageBuilder : IRaygunMessageBuilder
{
public static RaygunMessageBuilder New
public static RaygunMessageBuilder New
{
get
{
Expand Down
23 changes: 23 additions & 0 deletions Mindscape.Raygun4Net45.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mindscape.Raygun4Net45", "Mindscape.Raygun4Net45\Mindscape.Raygun4Net45.csproj", "{5F72C401-B09D-46C4-873B-65F1B4B1AE09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Sign|Any CPU = Sign|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5F72C401-B09D-46C4-873B-65F1B4B1AE09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F72C401-B09D-46C4-873B-65F1B4B1AE09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F72C401-B09D-46C4-873B-65F1B4B1AE09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F72C401-B09D-46C4-873B-65F1B4B1AE09}.Release|Any CPU.Build.0 = Release|Any CPU
{5F72C401-B09D-46C4-873B-65F1B4B1AE09}.Sign|Any CPU.ActiveCfg = Sign|Any CPU
{5F72C401-B09D-46C4-873B-65F1B4B1AE09}.Sign|Any CPU.Build.0 = Sign|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions Mindscape.Raygun4Net45/Messages/IRaygunRequestMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections;

namespace Mindscape.Raygun4Net.Messages
{
public interface IRaygunRequestMessage
{
string HostName { get; set; }

string Url { get; set; }

string HttpMethod { get; set; }

string IPAddress { get; set; }

IDictionary QueryString { get; set; }

IList Cookies { get; set; }

IDictionary Data { get; set; }

IDictionary Form { get; set; }

string RawData { get; set; }

IDictionary Headers { get; set; }
}
}
28 changes: 28 additions & 0 deletions Mindscape.Raygun4Net45/Messages/RaygunMessageDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;

namespace Mindscape.Raygun4Net.Messages
{
public class RaygunMessageDetails
{
public string MachineName { get; set; }

public string Version { get; set; }

public RaygunErrorMessage Error { get; set; }

public RaygunEnvironmentMessage Environment { get; set; }

public RaygunClientMessage Client { get; set; }

public IList<string> Tags { get; set; }

public IDictionary UserCustomData { get; set; }

public RaygunIdentifierMessage User { get; set; }

public IRaygunRequestMessage Request { get; set; }

public RaygunResponseMessage Response { get; set; }
}
}
162 changes: 162 additions & 0 deletions Mindscape.Raygun4Net45/Messages/RaygunRequestMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Web;

namespace Mindscape.Raygun4Net.Messages
{
public class RaygunRequestMessage : IRaygunRequestMessage
{
public RaygunRequestMessage(HttpRequest request, RaygunRequestMessageOptions options)
{
options = options ?? new RaygunRequestMessageOptions();

HostName = request.Url.Host;
Url = request.Url.AbsolutePath;
HttpMethod = request.RequestType;
IPAddress = request.UserHostAddress;
QueryString = ToDictionary(request.QueryString, null);

Headers = ToDictionary(request.Headers, options.IsHeaderIgnored);
Headers.Remove("Cookie");

Form = ToDictionary(request.Form, options.IsFormFieldIgnored, true);
Cookies = GetCookies(request.Cookies, options.IsCookieIgnored);

// Remove ignored and duplicated variables
Data = ToDictionary(request.ServerVariables, options.IsServerVariableIgnored);
Data.Remove("ALL_HTTP");
Data.Remove("HTTP_COOKIE");
Data.Remove("ALL_RAW");

try
{
var contentType = request.Headers["Content-Type"];
if (contentType != "text/html" && contentType != "application/x-www-form-urlencoded" && request.RequestType != "GET")
{
int length = 4096;
string temp = new StreamReader(request.InputStream).ReadToEnd();
if (length > temp.Length)
{
length = temp.Length;
}

RawData = temp.Substring(0, length);
}
}
catch (HttpException)
{
}
}

private IList GetCookies(HttpCookieCollection cookieCollection, Func<string, bool> ignore)
{
return Enumerable.Range(0, cookieCollection.Count)
.Select(i => cookieCollection[i])
.Where(c => !ignore(c.Name))
.Select(c => new Cookie(c.Name, c.Value))
.ToList();
}

private static IDictionary ToDictionary(NameValueCollection nameValueCollection, Func<string, bool> ignore, bool truncateValues = false)
{
IEnumerable<string> keys;

try
{
if (ignore == null)
{
keys = nameValueCollection.AllKeys.Where(k => k != null);
}
else
{
keys = nameValueCollection.AllKeys.Where(k => !ignore(k));
}
}
catch (HttpRequestValidationException)
{
return new Dictionary<string, string> { { "Values", "Not able to be retrieved" } };
}

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

foreach (string key in keys)
{
try
{
var keyToSend = key;
var valueToSend = nameValueCollection[key];

if (truncateValues)
{
if (keyToSend.Length > 256)
{
keyToSend = keyToSend.Substring(0, 256);
}

if (valueToSend != null && valueToSend.Length > 256)
{
valueToSend = valueToSend.Substring(0, 256);
}
}

dictionary.Add(keyToSend, valueToSend);
}
catch (HttpRequestValidationException e)
{
// If changing QueryString to be of type string in future, will need to account for possible
// illegal values - in this case it is contained at the end of e.Message along with an error message

int firstInstance = e.Message.IndexOf('\"');
int lastInstance = e.Message.LastIndexOf('\"');

if (firstInstance != -1 && lastInstance != -1)
{
dictionary.Add(key, e.Message.Substring(firstInstance + 1, lastInstance - firstInstance - 1));
}
else
{
dictionary.Add(key, string.Empty);
}
}
}

return dictionary;
}

public class Cookie
{
public Cookie(string name, string value)
{
Name = name;
Value = value;
}

public string Name { get; set; }
public string Value { get; set; }
}

public string HostName { get; set; }

public string Url { get; set; }

public string HttpMethod { get; set; }

public string IPAddress { get; set; }

public IDictionary QueryString { get; set; }

public IList Cookies { get; set; }

public IDictionary Data { get; set; }

public IDictionary Form { get; set; }

public string RawData { get; set; }

public IDictionary Headers { get; set; }
}
}
Loading

0 comments on commit 3edf369

Please sign in to comment.