public async Task LoadAsync(ConfiguratorPaths paths, CancellationToken token) { Current = await LoadConfigurationAsync(paths); _currentWatcher = Watch(paths.WorkspacePath, async() => { OnConfigurationChanged?.Invoke(this, new ConfigurationChangedArgs(await LoadConfigurationAsync(paths))); }); }
public WorkspaceConfig GetConfigTree(ConfiguratorPaths paths) { var file = new FileInfo(Path.GetFullPath(paths.WorkspacePath)); var rootDir = file.DirectoryName; return(Populate(file.Name, null, rootDir)); WorkspaceConfig Populate(string path, WorkspaceConfig parent, string currentDirectory) { var fullPath = Path.IsPathRooted(path) ? path : Path.Combine(currentDirectory, path); var c = _loader.Load <WorkspaceConfig>(fullPath); if (c == null) { return(new WorkspaceConfig()); } c.Parent = parent; c.path = fullPath; foreach (var r in c.Elements <IRunnableConfig>()) { if (r is IUseWorkingDir wd) { wd.WorkingDir = new FileInfo(c.path).DirectoryName; } r.DeclaredPaths.Add(fullPath); } if (c.import == null) { return(c); } for (var i = 0; i < c.import.Length; i++) { ref var w = ref c.import[i]; w = Populate(w.path, c, new FileInfo(fullPath).DirectoryName); } return(c); }
private async Task <ConfigSet> LoadConfigurationAsync(ConfiguratorPaths paths) { WorkspaceConfig tree = null; const int retries = 5; var tryCount = retries; while (tryCount > 0) { try { tryCount--; tree = _configReader.GetConfigTree(paths); break; } catch (Exception ex) { _logger.LogError(ex, $"Could not open workspace '{paths.WorkspacePath}'. {tryCount} retries left"); await Task.Delay(1000); } } if (tree == null) { throw new FileLoadException($"Could not (re)load workspace after {retries} tries. Path: '{paths.WorkspacePath}'"); } var effectiveConfig = tree.ToEffectiveConfig(); using (_logger.WithHostScope(Phase.CONFIG)) { _logger.LogInformation("Workspace: {WorkspaceFile}", paths.WorkspacePath); _logger.LogInformation(PhaseStatus.OK); } Current = effectiveConfig; return(effectiveConfig); }