Exemple #1
0
        public async Task <IList <Project> > TestAsync(IList <Project> projects, CommandOptions options, CancellationToken cancellationToken)
        {
            if (projects.Count <= 0)
            {
                _console.WriteEmphasizedLine("No projects found");
            }

            foreach (var project in projects)
            {
                cancellationToken.ThrowIfCancellationRequested();

                RunScriptsForTask(project, AppTask.Test, options);

                var projectAppDirectoryPaths = project.GetAppDirectoryPaths(_fileSystem);

                foreach (var path in projectAppDirectoryPaths)
                {
                    _queueService.Queue(project.Serial || options.NoParallel, async() =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        string appName = projectAppDirectoryPaths.Count > 1 ? $"{PathUtility.GetDirectoryShortName(path)} ({project.Name})" : project.Name;
                        _console.WriteEmphasizedLine($"Starting tests for {appName}");

                        if (project.RequiredProjects.Any())
                        {
                            string dependencyPluralization = project.RequiredProjects.Count > 1 ? "dependencies" : "dependency";
                            _console.WriteDefaultLine($"Starting {project.RequiredProjects.Count} {dependencyPluralization} for project {appName}");

                            CommandOptions requiredOptions = options.CloneForRequiredProjects();

                            IQueueService dependencyQueue = _frameworkServiceProvider.CreateScopedQueueService();

                            IDictionary <int, Project> requiredProjectsWithPorts = new Dictionary <int, Project>();

                            foreach (var requiredProject in project.RequiredProjects)
                            {
                                RunScriptsForTask(requiredProject, AppTask.Test, options);

                                if (requiredProject != null)
                                {
                                    if (requiredProject.Port.HasValue)
                                    {
                                        if (_networkingService.IsPortListening(requiredProject.Port.Value))
                                        {
                                            _console.WriteWarningLine($"Project {requiredProject.Name} is already listening on port {requiredProject.Port}");
                                            continue;
                                        }

                                        requiredProjectsWithPorts.Add(requiredProject.Port.Value, requiredProject);
                                    }

                                    bool noParallel = requiredProject.Serial || options.NoParallel;

                                    foreach (var requiredPath in requiredProject.GetAppDirectoryPaths(_fileSystem))
                                    {
                                        dependencyQueue.Queue(noParallel, async() =>
                                        {
                                            await InternalStartProject(requiredProject, requiredPath, requiredOptions, cancellationToken);
                                        }, cancellationToken);
                                    }
                                }
                            }

                            await dependencyQueue.RunAllAsync(cancellationToken);
                            await dependencyQueue.ConfirmProjectsStartedAsync(requiredProjectsWithPorts, cancellationToken);
                        }

                        var testProcess = await _frameworkServiceProvider
                                          .GetFrameworkService(project.Framework)
                                          .Test(project, path, options, cancellationToken);

                        project.Processes.Add(testProcess);

                        if (project.Processes?.Count > 0)
                        {
                            var outputStatus     = project.OutputStatus;
                            string outputMessage = $"Finished tests for {appName} with status {outputStatus}";

                            if (outputStatus == AppStatus.Success)
                            {
                                _console.WriteSuccessLine(outputMessage);
                            }
                            else
                            {
                                _console.WriteErrorLine(outputMessage);
                            }

                            await _projectManager.KillAllProcesses(project.RequiredProjects, options, cancellationToken);
                        }
                    }, cancellationToken);
                }
            }

            await _queueService.RunAllAsync(cancellationToken);

            return(projects);
        }
Exemple #2
0
        public async Task <IList <Project> > InstallAsync(IList <Project> projects, CommandOptions options, CancellationToken cancellationToken)
        {
            if (projects.Count <= 0)
            {
                _console.WriteEmphasizedLine("No projects found");
            }

            var installedProjects = new ConcurrentBag <string>();

            foreach (var project in projects)
            {
                foreach (var path in project.GetAppDirectoryPaths(_fileSystem))
                {
                    _queueService.Queue(project.Serial || options.NoParallel, async() =>
                    {
                        if (!installedProjects.Contains(project.Name))
                        {
                            installedProjects.Add(project.Name);
                            await InternalInstallProject(project, path, options, cancellationToken);
                        }

                        if (project.RequiredProjects.Any())
                        {
                            string dependencyPluralization = project.Requires.Count > 1 ? "dependencies" : "dependency";
                            _console.WriteDefaultLine($"Starting install for {project.RequiredProjects.Count} {dependencyPluralization} for project {project.Name}");

                            CommandOptions requiredOptions = options.CloneForRequiredProjects();

                            IQueueService dependencyQueue = _frameworkServiceProvider.CreateScopedQueueService();

                            foreach (var requiredProject in project.RequiredProjects)
                            {
                                if (requiredProject != null)
                                {
                                    if (installedProjects.Contains(requiredProject.Name) || projects.Any(p => p.Name == requiredProject.Name))
                                    {
                                        continue;
                                    }

                                    installedProjects.Add(requiredProject.Name);

                                    foreach (var requiredPath in requiredProject.GetAppDirectoryPaths(_fileSystem))
                                    {
                                        dependencyQueue.Queue(requiredProject.Serial || options.NoParallel, () =>
                                        {
                                            return(InternalInstallProject(requiredProject, requiredPath, requiredOptions, cancellationToken));
                                        }, cancellationToken);
                                    }
                                }
                            }

                            await dependencyQueue.RunAllAsync(cancellationToken);
                        }
                    }, cancellationToken);
                }
            }

            await _queueService.RunAllAsync(cancellationToken);

            return(projects);
        }