-
Notifications
You must be signed in to change notification settings - Fork 90
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 #438 from MindscapeHQ/md/cr-259/release-xamarin-io…
…s-storage-changes [CR-259] Release the Xamarin iOS changes to the storage directory
- Loading branch information
Showing
14 changed files
with
572 additions
and
32 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
136 changes: 136 additions & 0 deletions
136
Mindscape.Raygun4Net.Xamarin.Android/RaygunClientBase.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,136 @@ | ||
using System; | ||
using System.Net; | ||
using Mindscape.Raygun4Net.Messages; | ||
|
||
namespace Mindscape.Raygun4Net | ||
{ | ||
public abstract class RaygunClientBase | ||
{ | ||
private bool _handlingRecursiveErrorSending; | ||
private bool _handlingRecursiveGrouping; | ||
|
||
protected internal const string SentKey = "AlreadySentByRaygun"; | ||
|
||
/// <summary> | ||
/// Raised just before a message is sent. This can be used to make final adjustments to the <see cref="RaygunMessage"/>, or to cancel the send. | ||
/// </summary> | ||
public event EventHandler<RaygunSendingMessageEventArgs> SendingMessage; | ||
|
||
/// <summary> | ||
/// Raised before a message is sent. This can be used to add a custom grouping key to a RaygunMessage before sending it to the Raygun service. | ||
/// </summary> | ||
public event EventHandler<RaygunCustomGroupingKeyEventArgs> CustomGroupingKey; | ||
|
||
/// <summary> | ||
/// Gets or sets the user identity string. | ||
/// </summary> | ||
public virtual string User { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets information about the user including the identity string. | ||
/// </summary> | ||
public virtual RaygunIdentifierMessage UserInfo { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the context identifier defining a scope under which errors are related | ||
/// </summary> | ||
public string ContextId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a custom application version identifier for all error messages sent to the Raygun endpoint. | ||
/// </summary> | ||
public string ApplicationVersion { get; set; } | ||
|
||
/// <summary> | ||
/// Transmits an exception to Raygun synchronously. | ||
/// </summary> | ||
/// <param name="exception">The exception to deliver.</param> | ||
public abstract void Send(Exception exception); | ||
|
||
/// <summary> | ||
/// Posts a RaygunMessage to the Raygun API endpoint. | ||
/// </summary> | ||
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property | ||
/// set to a valid DateTime and as much of the Details property as is available.</param> | ||
public abstract void Send(RaygunMessage raygunMessage); | ||
|
||
protected virtual bool CanSend(Exception exception) | ||
{ | ||
return exception == null || exception.Data == null || !exception.Data.Contains(SentKey) || false.Equals(exception.Data[SentKey]); | ||
} | ||
|
||
protected void FlagAsSent(Exception exception) | ||
{ | ||
if (exception != null && exception.Data != null) | ||
{ | ||
try | ||
{ | ||
Type[] genericTypes = exception.Data.GetType().GetGenericArguments(); | ||
if (genericTypes.Length == 0 || genericTypes[0].IsAssignableFrom(typeof(string))) | ||
{ | ||
exception.Data[SentKey] = true; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
RaygunLogger.Debug($"Failed to flag exception as sent: {ex.Message}"); | ||
} | ||
} | ||
} | ||
|
||
// Returns true if the message can be sent, false if the sending is canceled. | ||
protected bool OnSendingMessage(RaygunMessage raygunMessage) | ||
{ | ||
bool result = true; | ||
|
||
if (!_handlingRecursiveErrorSending) | ||
{ | ||
EventHandler<RaygunSendingMessageEventArgs> handler = SendingMessage; | ||
if (handler != null) | ||
{ | ||
RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage); | ||
try | ||
{ | ||
handler(this, args); | ||
} | ||
catch (Exception e) | ||
{ | ||
// Catch and send exceptions that occur in the SendingMessage event handler. | ||
// Set the _handlingRecursiveErrorSending flag to prevent infinite errors. | ||
_handlingRecursiveErrorSending = true; | ||
Send(e); | ||
_handlingRecursiveErrorSending = false; | ||
} | ||
result = !args.Cancel; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected string OnCustomGroupingKey(Exception exception, RaygunMessage message) | ||
{ | ||
string result = null; | ||
if(!_handlingRecursiveGrouping) | ||
{ | ||
var handler = CustomGroupingKey; | ||
if(handler != null) | ||
{ | ||
var args = new RaygunCustomGroupingKeyEventArgs(exception, message); | ||
try | ||
{ | ||
handler(this, args); | ||
} | ||
catch (Exception e) | ||
{ | ||
_handlingRecursiveGrouping = true; | ||
Send(e); | ||
_handlingRecursiveGrouping = false; | ||
} | ||
result = args.CustomGroupingKey; | ||
} | ||
} | ||
return result; | ||
} | ||
} | ||
} |
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
136 changes: 136 additions & 0 deletions
136
Mindscape.Raygun4Net.Xamarin.Mac.Unified/RaygunClientBase.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,136 @@ | ||
using System; | ||
using System.Net; | ||
using Mindscape.Raygun4Net.Messages; | ||
|
||
namespace Mindscape.Raygun4Net | ||
{ | ||
public abstract class RaygunClientBase | ||
{ | ||
private bool _handlingRecursiveErrorSending; | ||
private bool _handlingRecursiveGrouping; | ||
|
||
protected internal const string SentKey = "AlreadySentByRaygun"; | ||
|
||
/// <summary> | ||
/// Raised just before a message is sent. This can be used to make final adjustments to the <see cref="RaygunMessage"/>, or to cancel the send. | ||
/// </summary> | ||
public event EventHandler<RaygunSendingMessageEventArgs> SendingMessage; | ||
|
||
/// <summary> | ||
/// Raised before a message is sent. This can be used to add a custom grouping key to a RaygunMessage before sending it to the Raygun service. | ||
/// </summary> | ||
public event EventHandler<RaygunCustomGroupingKeyEventArgs> CustomGroupingKey; | ||
|
||
/// <summary> | ||
/// Gets or sets the user identity string. | ||
/// </summary> | ||
public virtual string User { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets information about the user including the identity string. | ||
/// </summary> | ||
public virtual RaygunIdentifierMessage UserInfo { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the context identifier defining a scope under which errors are related | ||
/// </summary> | ||
public string ContextId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a custom application version identifier for all error messages sent to the Raygun endpoint. | ||
/// </summary> | ||
public string ApplicationVersion { get; set; } | ||
|
||
/// <summary> | ||
/// Transmits an exception to Raygun synchronously. | ||
/// </summary> | ||
/// <param name="exception">The exception to deliver.</param> | ||
public abstract void Send(Exception exception); | ||
|
||
/// <summary> | ||
/// Posts a RaygunMessage to the Raygun API endpoint. | ||
/// </summary> | ||
/// <param name="raygunMessage">The RaygunMessage to send. This needs its OccurredOn property | ||
/// set to a valid DateTime and as much of the Details property as is available.</param> | ||
public abstract void Send(RaygunMessage raygunMessage); | ||
|
||
protected virtual bool CanSend(Exception exception) | ||
{ | ||
return exception == null || exception.Data == null || !exception.Data.Contains(SentKey) || false.Equals(exception.Data[SentKey]); | ||
} | ||
|
||
protected void FlagAsSent(Exception exception) | ||
{ | ||
if (exception != null && exception.Data != null) | ||
{ | ||
try | ||
{ | ||
Type[] genericTypes = exception.Data.GetType().GetGenericArguments(); | ||
if (genericTypes.Length == 0 || genericTypes[0].IsAssignableFrom(typeof(string))) | ||
{ | ||
exception.Data[SentKey] = true; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
System.Diagnostics.Trace.WriteLine($"Failed to flag exception as sent: {ex.Message}"); | ||
} | ||
} | ||
} | ||
|
||
// Returns true if the message can be sent, false if the sending is canceled. | ||
protected bool OnSendingMessage(RaygunMessage raygunMessage) | ||
{ | ||
bool result = true; | ||
|
||
if (!_handlingRecursiveErrorSending) | ||
{ | ||
EventHandler<RaygunSendingMessageEventArgs> handler = SendingMessage; | ||
if (handler != null) | ||
{ | ||
RaygunSendingMessageEventArgs args = new RaygunSendingMessageEventArgs(raygunMessage); | ||
try | ||
{ | ||
handler(this, args); | ||
} | ||
catch (Exception e) | ||
{ | ||
// Catch and send exceptions that occur in the SendingMessage event handler. | ||
// Set the _handlingRecursiveErrorSending flag to prevent infinite errors. | ||
_handlingRecursiveErrorSending = true; | ||
Send(e); | ||
_handlingRecursiveErrorSending = false; | ||
} | ||
result = !args.Cancel; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected string OnCustomGroupingKey(Exception exception, RaygunMessage message) | ||
{ | ||
string result = null; | ||
if(!_handlingRecursiveGrouping) | ||
{ | ||
var handler = CustomGroupingKey; | ||
if(handler != null) | ||
{ | ||
var args = new RaygunCustomGroupingKeyEventArgs(exception, message); | ||
try | ||
{ | ||
handler(this, args); | ||
} | ||
catch (Exception e) | ||
{ | ||
_handlingRecursiveGrouping = true; | ||
Send(e); | ||
_handlingRecursiveGrouping = false; | ||
} | ||
result = args.CustomGroupingKey; | ||
} | ||
} | ||
return result; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.