private async Task LoadProjectsAsync(CancellationToken token) { var blockOptions = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Configuration.Parallelism, CancellationToken = token, }; var block = new ActionBlock <string>(projectIndexFile => { var project = new ServerProject { ContentPath = Path.GetDirectoryName(projectIndexFile), }; project.Load(); var projectId = project.Description?.Id ?? string.Empty; projectsCollection[projectId] = project; }, blockOptions); var root = Configuration.ProjectsDirectory; foreach (var path in Directory.EnumerateDirectories(root, "*", SearchOption.TopDirectoryOnly)) { var projectIndexFile = Path.Combine(path, "project.json"); if (!File.Exists(projectIndexFile)) { Log.Warn($"Missing project.json in '{path}'."); continue; } block.Post(projectIndexFile); } block.Complete(); await block.Completion; }
public ServerProject New(string id) { if (!isLoaded) { Task.WaitAll(loadTask.Task); } if (projectsCollection.ContainsKey(id)) { throw new ApplicationException($"Project '{id}' already exists!"); } var path = GetProjectPath(id); var project = new ServerProject { ContentPath = path, Description = new Project { Id = id, } }; project.InitializeNew(); projectsCollection[id] = project; project.SaveProject(); return(project); }
public bool TryGet(string projectId, out ServerProject project) { return(projectsCollection.TryGetValue(projectId, out project)); }