-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part 2 in the move to IOCing the world.
- Loading branch information
Showing
8 changed files
with
219 additions
and
124 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/DaemonRunner/DaemonRunner/Infrastructure/Extensions/AssemblyExtensions.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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace NetDaemon.Infrastructure.Extensions | ||
{ | ||
public static class AssemblyExtensions | ||
{ | ||
public static IEnumerable<Type> GetTypesWhereSubclassOf<T>(this Assembly assembly) | ||
{ | ||
return assembly.GetTypes().Where(x => x.IsClass && x.IsSubclassOf(typeof(T))); | ||
} | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/DaemonRunner/DaemonRunner/Service/App/DaemonAppCompiler.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,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using NetDaemon.Common; | ||
using NetDaemon.Common.Configuration; | ||
using NetDaemon.Infrastructure.Extensions; | ||
|
||
namespace NetDaemon.Service.App | ||
{ | ||
public class DaemonAppCompiler : IDaemonAppCompiler | ||
{ | ||
private readonly ILogger<DaemonAppCompiler> _logger; | ||
private readonly IOptions<NetDaemonSettings> _netDaemonSettings; | ||
|
||
public DaemonAppCompiler(ILogger<DaemonAppCompiler> logger, IOptions<NetDaemonSettings> netDaemonSettings) | ||
{ | ||
_logger = logger; | ||
_netDaemonSettings = netDaemonSettings; | ||
} | ||
|
||
public IEnumerable<Type> GetApps() | ||
{ | ||
var assembly = Load(); | ||
var apps = assembly.GetTypesWhereSubclassOf<NetDaemonAppBase>(); | ||
|
||
if (!apps.Any()) | ||
_logger.LogWarning("No .cs files found, please add files to {sourceFolder}/apps", _netDaemonSettings.Value.SourceFolder); | ||
|
||
return apps; | ||
} | ||
|
||
public Assembly Load() | ||
{ | ||
CollectibleAssemblyLoadContext alc; | ||
var appFolder = Path.Combine(_netDaemonSettings.Value.SourceFolder!, "apps"); | ||
return DaemonCompiler.GetCompiledAppAssembly(out alc, appFolder!, _logger); | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/DaemonRunner/DaemonRunner/Service/App/IDaemonAppCompiler.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,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace NetDaemon.Service.App | ||
{ | ||
public interface IDaemonAppCompiler | ||
{ | ||
/// <summary> | ||
/// Temporary | ||
/// </summary> | ||
/// <returns></returns> | ||
[Obsolete("Only exists while migrating the world to IOC.")] | ||
IEnumerable<Type> GetApps(); | ||
Assembly Load(); | ||
} | ||
} |
Oops, something went wrong.