Skip to content

Commit

Permalink
Merge pull request #438 from MindscapeHQ/md/cr-259/release-xamarin-io…
Browse files Browse the repository at this point in the history
…s-storage-changes

[CR-259] Release the Xamarin iOS changes to the storage directory
  • Loading branch information
mduncan26 committed Sep 15, 2020
2 parents 3692c51 + 65b7302 commit c1c6c23
Show file tree
Hide file tree
Showing 14 changed files with 572 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
<Compile Include="..\Mindscape.Raygun4Net\Messages\RaygunMessage.cs">
<Link>Messages\RaygunMessage.cs</Link>
</Compile>
<Compile Include="..\Mindscape.Raygun4Net\RaygunClientBase.cs">
<Link>RaygunClientBase.cs</Link>
</Compile>
<Compile Include="..\Mindscape.Raygun4Net\RaygunCustomGroupingKeyEventArgs.cs">
<Link>RaygunCustomGroupingKeyEventArgs.cs</Link>
</Compile>
Expand Down Expand Up @@ -114,6 +111,7 @@
<Compile Include="RaygunFileManager.cs" />
<Compile Include="RaygunFile.cs" />
<Compile Include="RaygunResponseStatusCode.cs" />
<Compile Include="RaygunClientBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
Expand Down
136 changes: 136 additions & 0 deletions Mindscape.Raygun4Net.Xamarin.Android/RaygunClientBase.cs
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
<Compile Include="..\Mindscape.Raygun4Net\IRaygunMessageBuilder.cs">
<Link>IRaygunMessageBuilder.cs</Link>
</Compile>
<Compile Include="..\Mindscape.Raygun4Net\RaygunClientBase.cs">
<Link>RaygunClientBase.cs</Link>
</Compile>
<Compile Include="..\Mindscape.Raygun4Net\RaygunSendingMessageEventArgs.cs">
<Link>RaygunSendingMessageEventArgs.cs</Link>
</Compile>
Expand Down Expand Up @@ -116,6 +113,7 @@
<Compile Include="..\Mindscape.Raygun4Net\RaygunCustomGroupingKeyEventArgs.cs">
<Link>RaygunCustomGroupingKeyEventArgs.cs</Link>
</Compile>
<Compile Include="RaygunClientBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
136 changes: 136 additions & 0 deletions Mindscape.Raygun4Net.Xamarin.Mac.Unified/RaygunClientBase.cs
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@
<Link>Messages\RaygunMessageDetails.cs</Link>
</Compile>
<Compile Include="Builders\RaygunEnvironmentMessageBuilder.cs" />
<Compile Include="..\Mindscape.Raygun4Net\RaygunClientBase.cs">
<Link>RaygunClientBase.cs</Link>
</Compile>
<Compile Include="..\Mindscape.Raygun4Net.Core\Messages\RaygunErrorMessage.cs">
<Link>Messages\RaygunErrorMessage.cs</Link>
</Compile>
<Compile Include="..\Mindscape.Raygun4Net\RaygunCustomGroupingKeyEventArgs.cs">
<Link>RaygunCustomGroupingKeyEventArgs.cs</Link>
</Compile>
<Compile Include="RaygunClientBase.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down

0 comments on commit c1c6c23

Please sign in to comment.