Skip to content

Commit

Permalink
fix: Adds try/catch around pre/post activation calls and adds JsonPro…
Browse files Browse the repository at this point in the history
…perty decorators to Key and Name properties in interfaces
  • Loading branch information
ndorin committed May 7, 2024
1 parent 165841b commit 2558f44
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Pepperdash Core/CoreInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Newtonsoft.Json;
using Serilog;

namespace PepperDash.Core
Expand All @@ -15,6 +16,7 @@ public interface IKeyed
/// <summary>
/// Unique Key
/// </summary>
[JsonProperty("key")]
string Key { get; }
}

Expand All @@ -26,6 +28,7 @@ public interface IKeyName : IKeyed
/// <summary>
/// Isn't it obvious :)
/// </summary>
[JsonProperty("name")]
string Name { get; }
}

Expand Down
21 changes: 19 additions & 2 deletions src/Pepperdash Core/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ public void AddPostActivationAction(Action act)
public void PreActivate()
{
if (_PreActivationActions != null)
_PreActivationActions.ForEach(a => a.Invoke());
_PreActivationActions.ForEach(a => {
try
{
a.Invoke();
} catch (Exception e)
{
Debug.LogMessage(e, "Error in PreActivationAction: " + e.Message, this);
}
});
}

/// <summary>
Expand All @@ -123,7 +131,16 @@ public bool Activate()
public void PostActivate()
{
if (_PostActivationActions != null)
_PostActivationActions.ForEach(a => a.Invoke());
_PostActivationActions.ForEach(a => {
try
{
a.Invoke();
}
catch (Exception e)
{
Debug.LogMessage(e, "Error in PostActivationAction: " + e.Message, this);
}
});
}

/// <summary>
Expand Down

0 comments on commit 2558f44

Please sign in to comment.