Exemplo n.º 1
0
        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);
        }