Skip to content

Commit

Permalink
Added a 'RegisterAllActions' feature to the ConnectionManager (#122)
Browse files Browse the repository at this point in the history
* Refactored to an Proxy interface to address #47

* Added remaining EventsSent to ConfigurationManager

* Attempting to eliminate memory leak

* Adding script to test the Plugin template

* WIP

* Updated to be more cross-platform friendly

* Re-added cheer graffiti

* Cleaning up the inner-loop build-debug-process

* Addressed logger and memory leak issues #73 #114

* Added a default configuration builder #34

 Addressed logger and memory leak issues #73 #114  (#117)

* Refactored to an Proxy interface to address #47

* Added remaining EventsSent to ConfigurationManager

* Attempting to eliminate memory leak

* Adding script to test the Plugin template

* WIP

* Updated to be more cross-platform friendly

* Re-added cheer graffiti

* Cleaning up the inner-loop build-debug-process

* Addressed logger and memory leak issues #73 #114

* Fixed some tests, added UUID constructor for #119

* Added a 'RegisterAllActions' feature to the ConnectionManager
  • Loading branch information
csharpfritz authored Feb 17, 2019
1 parent 218de8c commit 2e72d71
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/SamplePlugin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static async Task Main(string[] args)
{

await ConnectionManager.Initialize(args, config.LoggerFactory)
.RegisterAction(new MySampleAction())
.RegisterAllActions(typeof(Program).Assembly)
.StartAsync();

}
Expand Down
14 changes: 14 additions & 0 deletions src/StreamDeckLib.Test/ConnectionManager_UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ public async Task ShouldNotThrowAnyExceptions_WhenRegistringMultipleUniqueAction
.NotThrow("registering multiple unique actions is valid");
}

[Fact]
public async Task ShouldRegisterAllActions_WhenRegisteringAllActions()
{

Func<ConnectionManager> action = () => ConnectionManager.Initialize(StubProxy.ValidCommandLineArguments)
.RegisterAllActions(this.GetType().Assembly);

action.Should()
.NotThrow("No problems when registering All Actions");


}


}

}
4 changes: 2 additions & 2 deletions src/StreamDeckLib.Test/Stubs/StubAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace StreamDeckLib.Test
public class StubAction : BaseStreamDeckAction
{

public StubAction() : this(string.Empty)
public StubAction() : this("Test UUID")
{

}
Expand All @@ -29,4 +29,4 @@ public StubAction SetUUID(string uuid)

}

}
}
17 changes: 17 additions & 0 deletions src/StreamDeckLib/ConnectionManager_Actions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace StreamDeckLib
{
Expand All @@ -12,6 +14,21 @@ partial class ConnectionManager

public ConnectionManager RegisterAction(BaseStreamDeckAction action) => RegisterActionInternal(this, action);

public ConnectionManager RegisterAllActions(Assembly assembly)
{

var actions = assembly.GetTypes().Where(t => typeof(BaseStreamDeckAction).IsAssignableFrom(t));

foreach (var actionType in actions)
{
var newAction = Activator.CreateInstance(actionType) as BaseStreamDeckAction;
RegisterActionInternal(this, newAction);
}

return this;

}

private static ConnectionManager RegisterActionInternal(ConnectionManager manager, BaseStreamDeckAction action)
{

Expand Down

0 comments on commit 2e72d71

Please sign in to comment.