-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from MindscapeHQ/webapi-experiment
Webapi experiment
- Loading branch information
Showing
32 changed files
with
1,637 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
162
Mindscape.Raygun4Net45/Messages/RaygunRequestMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
Oops, something went wrong.