-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove more json stuff + cache RepositoryAction files and env files for speeding up process. * Update a shitload of packages * Replace Moq with FakeItEasy in last test project * added tests + update log statements
- Loading branch information
Showing
56 changed files
with
487 additions
and
426 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
8 changes: 8 additions & 0 deletions
8
...i/IO/ModuleBasedRepositoryActionProvider/Deserialization/IRepositoryActionDeserializer.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,8 @@ | ||
namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; | ||
|
||
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; | ||
|
||
public interface IRepositoryActionDeserializer | ||
{ | ||
RepositoryActionConfiguration Deserialize(string content); | ||
} |
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
16 changes: 8 additions & 8 deletions
16
...eBasedRepositoryActionProvider/Deserialization/YamlDynamicRepositoryActionDeserializer.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
94 changes: 94 additions & 0 deletions
94
src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositoryActionsFileStore.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,94 @@ | ||
namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using System.Runtime.Caching; | ||
using DotNetEnv; | ||
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; | ||
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; | ||
|
||
internal abstract class FileStore<T> where T : class | ||
{ | ||
private readonly ObjectCache _cache; | ||
|
||
protected FileStore(ObjectCache cache) | ||
{ | ||
_cache = cache ?? throw new ArgumentNullException(nameof(cache)); | ||
} | ||
|
||
internal T? Get(string filename) | ||
{ | ||
if (_cache[filename] is T fileContents) | ||
{ | ||
return fileContents; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
internal T AddOrGetExisting(string filename, T value) | ||
{ | ||
var policy = new CacheItemPolicy(); | ||
var filePaths = new List<string>(1) { filename, }; | ||
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); | ||
var cacheResult = _cache.AddOrGetExisting(filename, value, policy) as T; | ||
return cacheResult ?? value; | ||
} | ||
} | ||
|
||
internal class RepositoryActionsFileStore : FileStore<RepositoryActionConfiguration> | ||
{ | ||
private readonly IFileSystem _fileSystem; | ||
private readonly IRepositoryActionDeserializer _repositoryActionsDeserializer; | ||
|
||
|
||
public RepositoryActionsFileStore(IFileSystem fileSystem, IRepositoryActionDeserializer repositoryActionsDeserializer, ObjectCache cache) : base(cache) | ||
{ | ||
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); | ||
_repositoryActionsDeserializer = repositoryActionsDeserializer ?? throw new ArgumentNullException(nameof(repositoryActionsDeserializer)); | ||
} | ||
|
||
public RepositoryActionConfiguration? TryGet(string filename) | ||
{ | ||
RepositoryActionConfiguration? result = Get(filename); | ||
|
||
if (result != null) | ||
{ | ||
return result; | ||
} | ||
|
||
var payload = _fileSystem.File.ReadAllText(filename); | ||
RepositoryActionConfiguration? fileContents = _repositoryActionsDeserializer.Deserialize(payload); | ||
|
||
if (fileContents == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return AddOrGetExisting(filename, fileContents); | ||
} | ||
} | ||
|
||
internal class EnvFileStore : FileStore<Dictionary<string, string>> | ||
{ | ||
public EnvFileStore(ObjectCache cache) : base(cache) | ||
{ | ||
} | ||
|
||
public IDictionary<string, string> TryGet(string filename) | ||
{ | ||
Dictionary<string, string>? result = Get(filename); | ||
|
||
if (result != null) | ||
{ | ||
return result; | ||
} | ||
|
||
IEnumerable<KeyValuePair<string, string>>? envResult = Env.Load(filename, new LoadOptions(setEnvVars: false)); | ||
|
||
Dictionary<string, string>? fileContents = envResult == null ? new Dictionary<string, string>(0) : envResult.ToDictionary(); | ||
|
||
return AddOrGetExisting(filename, fileContents); | ||
} | ||
} |
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
Oops, something went wrong.