Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions pkgs/sdk/server/src/Internal/DataSources/FileDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal sealed class FileDataSource : IDataSource
private volatile bool _started;
private volatile bool _loadedValidData;
private volatile int _lastVersion;
private object _updateLock = new object();

public FileDataSource(IDataSourceUpdates dataSourceUpdates, FileDataTypes.IFileReader fileReader,
List<string> paths, bool autoUpdate, Func<string, object> alternateParser, bool skipMissingPaths,
Expand Down Expand Up @@ -88,35 +89,39 @@ private void Dispose(bool disposing)

private void LoadAll()
{
var version = Interlocked.Increment(ref _lastVersion);
var flags = new Dictionary<string, ItemDescriptor>();
var segments = new Dictionary<string, ItemDescriptor>();
foreach (var path in _paths)
lock (_updateLock)
{
try
{
var content = _fileReader.ReadAllText(path);
_logger.Debug("file data: {0}", content);
var data = _parser.Parse(content, version);
_dataMerger.AddToData(data, flags, segments);
}
catch (FileNotFoundException) when (_skipMissingPaths)
var version = Interlocked.Increment(ref _lastVersion);
var flags = new Dictionary<string, ItemDescriptor>();
var segments = new Dictionary<string, ItemDescriptor>();
foreach (var path in _paths)
{
_logger.Debug("{0}: {1}", path, "File not found");
}
catch (Exception e)
{
LogHelpers.LogException(_logger, "Failed to load " + path, e);
return;
try
{
var content = _fileReader.ReadAllText(path);
_logger.Debug("file data: {0}", content);
var data = _parser.Parse(content, version);
_dataMerger.AddToData(data, flags, segments);
}
catch (FileNotFoundException) when (_skipMissingPaths)
{
_logger.Debug("{0}: {1}", path, "File not found");
}
catch (Exception e)
{
LogHelpers.LogException(_logger, "Failed to load " + path, e);
return;
}
}

var allData = new FullDataSet<ItemDescriptor>(
ImmutableDictionary.Create<DataKind, KeyedItems<ItemDescriptor>>()
.SetItem(DataModel.Features, new KeyedItems<ItemDescriptor>(flags))
.SetItem(DataModel.Segments, new KeyedItems<ItemDescriptor>(segments))
);
_dataSourceUpdates.Init(allData);
_loadedValidData = true;
}
var allData = new FullDataSet<ItemDescriptor>(
ImmutableDictionary.Create<DataKind, KeyedItems<ItemDescriptor>>()
.SetItem(DataModel.Features, new KeyedItems<ItemDescriptor>(flags))
.SetItem(DataModel.Segments, new KeyedItems<ItemDescriptor>(segments))
);
_dataSourceUpdates.Init(allData);
_loadedValidData = true;
}

private void TriggerReload()
Expand Down
Loading