generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from Nexus-Mods/analyzer-support
analyzer-support
- Loading branch information
Showing
10 changed files
with
145 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace NexusMods.MnemonicDB.Abstractions; | ||
|
||
/// <summary> | ||
/// Interface for a transaction analyzer. These can be injected via DI and they will then be fed each database transaction | ||
/// to analyze and produce a result. | ||
/// </summary> | ||
public interface IAnalyzer | ||
{ | ||
/// <summary> | ||
/// Analyze the database and produce a result. | ||
/// </summary> | ||
public object Analyze(IDb db); | ||
} | ||
|
||
/// <summary> | ||
/// Typed version of <see cref="IAnalyzer"/> that specifies the type of the result. | ||
/// </summary> | ||
public interface IAnalyzer<out T> : IAnalyzer | ||
{ | ||
|
||
} | ||
|
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
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
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
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
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
21 changes: 21 additions & 0 deletions
21
tests/NexusMods.MnemonicDB.TestModel/Analyzers/AttributesAnalyzer.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,21 @@ | ||
using NexusMods.MnemonicDB.Abstractions; | ||
|
||
namespace NexusMods.MnemonicDB.TestModel.Analyzers; | ||
|
||
/// <summary> | ||
/// Records all the attributes in each transaction | ||
/// </summary> | ||
public class AttributesAnalyzer : IAnalyzer<HashSet<IAttribute>> | ||
{ | ||
public object Analyze(IDb db) | ||
{ | ||
var hashSet = new HashSet<IAttribute>(); | ||
var registry = db.Registry; | ||
foreach (var datom in db.RecentlyAdded) | ||
{ | ||
hashSet.Add(registry.GetAttribute(datom.A)); | ||
} | ||
|
||
return hashSet; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/NexusMods.MnemonicDB.TestModel/Analyzers/DatomCountAnalyzer.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,14 @@ | ||
using NexusMods.MnemonicDB.Abstractions; | ||
|
||
namespace NexusMods.MnemonicDB.TestModel.Analyzers; | ||
|
||
/// <summary> | ||
/// Counts the number of dataoms in each transaction | ||
/// </summary> | ||
public class DatomCountAnalyzer : IAnalyzer<int> | ||
{ | ||
public object Analyze(IDb db) | ||
{ | ||
return db.RecentlyAdded.Count; | ||
} | ||
} |
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
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