-
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.
- Loading branch information
Showing
8 changed files
with
137 additions
and
37 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/RepoM.ActionMenu.Core/Abstractions/EnvironmentsCacheDecorator.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,20 @@ | ||
namespace RepoM.ActionMenu.Core.Abstractions; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
internal sealed class EnvironmentsCacheDecorator: IEnvironment | ||
{ | ||
private readonly IEnvironment _decoratee; | ||
private Dictionary<string, string>? _cachedValue; | ||
|
||
public EnvironmentsCacheDecorator(IEnvironment decoratee) | ||
{ | ||
_decoratee = decoratee ?? throw new ArgumentNullException(nameof(decoratee)); | ||
} | ||
|
||
public Dictionary<string, string> GetEnvironmentVariables() | ||
{ | ||
return _cachedValue ??= _decoratee.GetEnvironmentVariables(); | ||
} | ||
} |
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.ActionMenu.Core.Abstractions; | ||
|
||
using System.Collections.Generic; | ||
|
||
internal interface IEnvironment | ||
{ | ||
Dictionary<string, string> GetEnvironmentVariables(); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/RepoM.ActionMenu.Core/Abstractions/SystemEnvironments.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,36 @@ | ||
namespace RepoM.ActionMenu.Core.Abstractions; | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
internal sealed class SystemEnvironments : IEnvironment | ||
{ | ||
private SystemEnvironments() | ||
{ | ||
} | ||
|
||
public static SystemEnvironments Instance { get; } = new (); | ||
|
||
public Dictionary<string, string> GetEnvironmentVariables() | ||
{ | ||
var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||
|
||
foreach (DictionaryEntry item in Environment.GetEnvironmentVariables()) | ||
{ | ||
if (item.Key is not string key || string.IsNullOrEmpty(key)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (item.Value is not string value) | ||
{ | ||
continue; | ||
} | ||
|
||
env.Add(key.Trim(), value); | ||
} | ||
|
||
return env; | ||
} | ||
} |
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