新增 FlowScope Git 包雏形
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowScope.Config
|
||||
{
|
||||
public sealed class FileConfigSource : IConfigSource
|
||||
{
|
||||
private readonly string _rootPath;
|
||||
|
||||
public FileConfigSource(string rootPath, string name = "File")
|
||||
{
|
||||
_rootPath = string.IsNullOrWhiteSpace(rootPath)
|
||||
? throw new ArgumentException("Config root path is required.", nameof(rootPath))
|
||||
: rootPath;
|
||||
Name = string.IsNullOrWhiteSpace(name)
|
||||
? throw new ArgumentException("Config source name is required.", nameof(name))
|
||||
: name;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public Task<string> LoadTextAsync(string fileName, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var path = Path.Combine(_rootPath, fileName);
|
||||
return Task.Run(() => File.ReadAllText(path), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user