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

Added Seperate Dotnet Core Project #161

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/app/RavenSharpCore/Data/Breadcrumb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;

using Newtonsoft.Json;

using RavenSharpCore.Serialization;

namespace RavenSharpCore.Data {
/// <summary>
/// Breadcrumb trail.
/// </summary>
public class Breadcrumb {
private readonly DateTime timestamp;

public Breadcrumb(string category)
{
Category = category;
this.timestamp = DateTime.UtcNow;
}


public Breadcrumb(string category, BreadcrumbType type):this(category)
{
Type = type;
}

[JsonProperty(PropertyName = "type", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(LowerInvariantStringEnumConverter))]
public BreadcrumbType? Type { get; set; }

[JsonProperty(PropertyName = "category", NullValueHandling = NullValueHandling.Ignore)]
public string Category { get; set; }

[JsonProperty(PropertyName = "timestamp", NullValueHandling = NullValueHandling.Ignore)]
public DateTime Timestamp
{
get { return this.timestamp; }
}

[JsonProperty(PropertyName = "message", NullValueHandling = NullValueHandling.Ignore)]
public string Message { get; set; }

[JsonProperty(PropertyName = "data", NullValueHandling = NullValueHandling.Ignore)]
public IDictionary<string, string> Data { get; set; }

[JsonProperty(PropertyName = "level", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(LowerInvariantStringEnumConverter))]
public BreadcrumbLevel? Level { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/app/RavenSharpCore/Data/BreadcrumbLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace RavenSharpCore.Data
{
/// <summary>
/// This defines the level of the event. If not provided it defaults to info which is the middle level. In the order of priority from highest to lowest the levels are critical, error, warning, info and debug. Levels are used in the UI to emphasize and deemphasize the crumb.
/// </summary>
public enum BreadcrumbLevel
{
Critical, Error, Warning, Info, Debug
}
}
34 changes: 34 additions & 0 deletions src/app/RavenSharpCore/Data/BreadcrumbType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace RavenSharpCore.Data
{
/// <summary>
/// Indicates the descriptions of individual breadcrumb types, and what their data properties look like.
/// </summary>
public enum BreadcrumbType
{
/// <summary>
/// Describes a navigation breadcrumb. A navigation event can be a URL change in a web application, or a UI transition in a mobile or desktop application, etc.
/// Its data property has the following sub-properties:
/// from
/// A string representing the original application state / location.
/// to
/// A string representing the new application state / location.
/// </summary>
Navigation,

/// <summary>
/// Describes an HTTP request breadcrumb. This represents an HTTP request transmitted from your application. This could be an AJAX request from a web application, or a server-to-server HTTP request to an API service provider, etc.
///
/// Its data property has the following sub-properties:
///
/// url
/// The request URL.
/// method
/// The HTTP request method.
/// status_code
/// The HTTP status code of the response.
/// reason
/// A text that describes the status code.
/// </summary>
Http
}
}
99 changes: 99 additions & 0 deletions src/app/RavenSharpCore/Data/DefaultHttpRequestBodyConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#region License

// Copyright (c) 2014 The Sentry Team and individual contributors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// 3. Neither the name of the Sentry nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.IO;
using System.Text;
using Microsoft.AspNetCore.Http;

namespace RavenSharpCore.Data
{
/// <summary>
/// The default HTTP media type converter; just returns the HTTP request body as a <see cref="string"/>.
/// </summary>
public class DefaultHttpRequestBodyConverter : IHttpRequestBodyConverter
{
/// <summary>
/// Checks whether the specified <paramref name="contentType"/> can be converted by this
/// <see cref="IHttpRequestBodyConverter"/> implementation or not.
/// </summary>
/// <param name="contentType">The media type to match.</param>
/// <returns>
/// Returns <c>true</c> if the <see cref="IHttpRequestBodyConverter"/> implementation can convert
/// the specified <paramref name="contentType"/> cref="contentType"/>; otherwise <c>false</c>.
/// </returns>
public bool Matches(string contentType)
{
return true;
}


/// <summary>
/// Tries to convert the HTTP request body of the specified <paramref name="httpContext"/> to
/// a structured type.
/// </summary>
/// <param name="httpContext">The HTTP context containing the request body to convert.</param>
/// <param name="converted">
/// The converted, structured type for the specified <paramref name="httpContext"/>'s request
/// body or <c>null</c> if the <paramref name="httpContext"/> is null, or the somehow conversion
/// fails.
/// </param>
/// <returns>
/// <c>true</c> if the conversion succeeds; otherwise <c>false</c>.
/// </returns>
public bool TryConvert(HttpContext httpContext, out object converted)
{
converted = null;

if (httpContext == null)
{
return false;
}

try
{
using (var stream = new MemoryStream())
{
httpContext.Request.Body.Seek(0, SeekOrigin.Begin);
httpContext.Request.Body.CopyTo(stream);
converted = Encoding.UTF8.GetString(stream.ToArray());

return true;
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

return false;
}
}
}
68 changes: 68 additions & 0 deletions src/app/RavenSharpCore/Data/ErrorLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#region License

// Copyright (c) 2014 The Sentry Team and individual contributors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// 3. Neither the name of the Sentry nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

namespace RavenSharpCore.Data
{
/// <summary>
/// Indicates the severity of the error.
/// </summary>
public enum ErrorLevel
{
/// <summary>
/// The error is fatal and more severe than a captured exception or regular <see cref="Error"/>. Errors at this severity
/// will show up as dark red in the Sentry Stream.
/// </summary>
Fatal,

/// <summary>
/// The error is of the same severity as a captured exception. Errors at this severity
/// will show up as bright red in the Sentry Stream.
/// </summary>
Error,

/// <summary>
/// The error is less severe than an a regular <see cref="Error"/>. Errors at this severity will show
/// up as orange in the Sentry Stream.
/// </summary>
Warning,

/// <summary>
/// The error is less severe than a <see cref="Warning"/> and is probably expected. Errors at this severity
/// will show up as blue in the Sentry Stream.
/// </summary>
Info,

/// <summary>
/// The error is less even severe than an <see cref="Info"/> and is just captured for debug purposes. Errors
/// at this severity will show up as grey in the Sentry Stream.
/// </summary>
Debug
}
}
119 changes: 119 additions & 0 deletions src/app/RavenSharpCore/Data/ExceptionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#region License

// Copyright (c) 2014 The Sentry Team and individual contributors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// 3. Neither the name of the Sentry nor the names of its contributors may be used to
// endorse or promote products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.Collections.Generic;

using Newtonsoft.Json;

using RavenSharpCore.Utilities;

namespace RavenSharpCore.Data
{
/// <summary>
/// Data class for containing <see cref="Exception.Data"/>.
/// </summary>
public class ExceptionData : Dictionary<string, object>
{
private readonly string exceptionType;


/// <summary>Initializes a new instance of the <see cref="ExceptionData"/> class.</summary>
/// <param name="exception">The exception.</param>
public ExceptionData(Exception exception)
{
if (exception == null)
throw new ArgumentNullException("exception");

this.exceptionType = exception.GetType().FullName;

foreach (var k in exception.Data.Keys)
{
try
{
var value = exception.Data[k];
var key = k as string ?? k.ToString();
Add(key, value);
}
catch (Exception e)
{
SystemUtil.WriteError(e);
}
}

if (exception.InnerException == null)
return;

var exceptionData = new ExceptionData(exception.InnerException);

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

exceptionData.AddTo(this);
}


/// <summary>Gets the type of the exception.</summary>
/// <value>The type of the exception.</value>
[JsonProperty("type")]
public string ExceptionType
{
get { return this.exceptionType; }
}


private void AddTo(IDictionary<string, object> dictionary)
{
var key = String.Concat(ExceptionType, '.', "Data");
key = UniqueKey(dictionary, key);
dictionary.Add(key, this);
}


private static string UniqueKey(IDictionary<string, object> dictionary, object key)
{
var stringKey = key as string ?? key.ToString();

if (!dictionary.ContainsKey(stringKey))
return stringKey;

for (var i = 0; i < 10000; i++)
{
var newKey = String.Concat(stringKey, i);
if (!dictionary.ContainsKey(newKey))
return newKey;
}

throw new ArgumentException(String.Format("Unable to find a unique key for '{0}'.", stringKey), "key");
}
}
}
Loading