-
-
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.
make code generation logic injectable (#360)
Co-authored-by: Tomas Hellström <tomas.hellstrom@yahoo.se>
- Loading branch information
1 parent
116c976
commit c6256f7
Showing
6 changed files
with
66 additions
and
15 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
src/DaemonRunner/DaemonRunner/Service/App/CodeGenerationHandler.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,33 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NetDaemon.Daemon; | ||
|
||
namespace NetDaemon.Service.App | ||
{ | ||
public class CodeGenerationHandler : ICodeGenerationHandler | ||
{ | ||
private readonly ICodeGenerator _codeGenerator; | ||
|
||
public CodeGenerationHandler(ICodeGenerator codeGenerator) | ||
{ | ||
_codeGenerator = codeGenerator; | ||
} | ||
|
||
public async Task GenerateEntitiesAsync(NetDaemonHost daemonHost, string sourceFolder) | ||
{ | ||
if (daemonHost == null) throw new ArgumentNullException(nameof(daemonHost)); | ||
if (sourceFolder == null) throw new ArgumentNullException(nameof(sourceFolder)); | ||
|
||
var services = await daemonHost.GetAllServices().ConfigureAwait(false); | ||
var sourceRx = _codeGenerator.GenerateCodeRx( | ||
"NetDaemon.Generated.Reactive", | ||
daemonHost.State.Select(n => n.EntityId).Distinct(), | ||
services | ||
); | ||
|
||
await File.WriteAllTextAsync(Path.Combine(sourceFolder, "_EntityExtensionsRx.cs.gen"), sourceRx).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/DaemonRunner/DaemonRunner/Service/App/ICodeGenerationHandler.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,10 @@ | ||
using System.Threading.Tasks; | ||
using NetDaemon.Daemon; | ||
|
||
namespace NetDaemon.Service | ||
{ | ||
public interface ICodeGenerationHandler | ||
{ | ||
Task GenerateEntitiesAsync(NetDaemonHost daemonHost, string sourceFolder); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/DaemonRunner/DaemonRunner/Service/App/ICodeGenerator.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,10 @@ | ||
using System.Collections.Generic; | ||
using JoySoftware.HomeAssistant.Client; | ||
|
||
namespace NetDaemon.Service.App | ||
{ | ||
public interface ICodeGenerator | ||
{ | ||
string? GenerateCodeRx(string nameSpace, IEnumerable<string> entities, IEnumerable<HassServiceDomain> services); | ||
} | ||
} |
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