예제 #1
0
        public Task <List <FeatureEvidence> > Execute()
        {
            return(Task.Run(() =>
            {
                CleanBuildOutput(workingDir);

                var processDetails = new ProcessDetails(ProcessName, workingDir, Arguments);

                var processOutput = featureRunner.Execute(processDetails);

                if (processOutput.Output == null)
                {
                    ProjectBuilderEvidence.SetInconclusive(new SimpleEvidenceBuilder("No outputs were found in the process"));
                    return null;
                }

                Output = processOutput.Output;

                var errs = processOutput.ErrorOutput;
                CheckBuildSuccess();

                var errorGettingErrorsOrWarnings = GetNumberOfErrors() == -1 || GetNumberOfWarnings() == -1;

                if (errorGettingErrorsOrWarnings)
                {
                    ProjectBuilderEvidence.SetInconclusive(new SimpleEvidenceBuilder($"Could not find output from build process confirming success or failure.\nBuild process error output:\n{errs} "));
                    return new List <FeatureEvidence> {
                        ProjectBuilderEvidence
                    };
                }

                var buildOutput = $"Warning count: {GetNumberOfWarnings()}\nError count: {GetNumberOfErrors()}";
                if (buildSuccessful)
                {
                    ProjectBuilderEvidence.SetPassed(new SimpleEvidenceBuilder(buildOutput));
                    ProjectBuilderEvidence.FeatureRating = 1;
                }
                else
                {
                    ProjectBuilderEvidence.SetFailed(new SimpleEvidenceBuilder($"Error message: {GetErrorOutput(Output)}"));
                    ProjectBuilderEvidence.FeatureRating = 0;
                }

                return new List <FeatureEvidence> {
                    ProjectBuilderEvidence
                };
            }));
        }
예제 #2
0
        public Task <List <FeatureEvidence> > Execute()
        {
            return(projectBuilderTask.ContinueWith(buildTask =>
            {
                var projectRunEvidence = new FeatureEvidence {
                    Feature = Feature.ProjectRunner
                };

                if (!buildTask.Result.All(buildEvidence => buildEvidence.Passed))
                {
                    projectRunEvidence.SetInconclusive(new SimpleEvidenceBuilder("Project build failed, unable to perform check."));
                    return new List <FeatureEvidence> {
                        projectRunEvidence
                    };
                }

                if (!Directory.Exists(workingDir))
                {
                    projectRunEvidence.SetInconclusive(new SimpleEvidenceBuilder($"{workingDir} not found"));
                    return new List <FeatureEvidence> {
                        projectRunEvidence
                    };
                }

                Argument = CreateArgument(workingDir);

                var processDetails = new ProcessDetails(ProcessName, workingDir, Argument);

                var evidence = featureRunner.Execute(processDetails, "Application started. Press Ctrl+C to shut down.", false);
                Output = evidence.Output;
                ErrorOutput = evidence.ErrorOutput;

                const string portKeyword = "Now listening on: ";
                var line = Output.GetLineWithOneKeyword(portKeyword);
                var splitLine = line.Split(portKeyword, StringSplitOptions.None);
                var port = splitLine.Length > 1 ? splitLine[1] : "";

                if (String.IsNullOrEmpty(port))
                {
                    projectRunEvidence.SetInconclusive(new SimpleEvidenceBuilder(messages.BadPort));
                    return new List <FeatureEvidence> {
                        projectRunEvidence
                    };
                }

                portCompletionSource.SetResult(port);

                var applicationStarted = ApplicationStarted();

                if (applicationStarted)
                {
                    projectRunEvidence.SetPassed(new SimpleEvidenceBuilder($"Port: {GetPort().Result}"));
                    projectRunEvidence.FeatureRating = 1;
                }
                else
                {
                    projectRunEvidence.SetFailed(new SimpleEvidenceBuilder($"Error Output: {ErrorOutput}"));
                    projectRunEvidence.FeatureRating = 0;
                }

                return new List <FeatureEvidence> {
                    projectRunEvidence
                };
            }, TaskContinuationOptions.OnlyOnRanToCompletion));
        }