-
-
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.
- Loading branch information
Showing
8 changed files
with
245 additions
and
156 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace NetDaemon.Infrastructure.Extensions | ||
{ | ||
internal static class AssemblyExtensions | ||
{ | ||
public static IEnumerable<Type> GetTypesWhereSubclassOf<T>(this Assembly assembly) | ||
{ | ||
return assembly.GetTypes() | ||
.Where(type => type.IsClass) | ||
.Where(type => !type.IsGenericType) | ||
.Where(type => !type.IsAbstract) | ||
.Where(type => type.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); | ||
} | ||
} | ||
} |
Oops, something went wrong.