Пример #1
0
 public Builder(IContext context, ICodeGenerator codeGenerator, IOutputStrategy outputStrategy, ILogger <IBuilder> logger)
 {
     Context         = context ?? throw new ArgumentNullException(nameof(context));
     _codeGenerator  = codeGenerator ?? throw new ArgumentNullException(nameof(codeGenerator));
     _outputStrategy = outputStrategy ?? throw new ArgumentNullException(nameof(outputStrategy));
     _logger         = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Пример #2
0
 public Builder(IContext context, ICodeGenerator codeGenerator, IOutputStrategy outputStrategy, ILogger <Builder> logger)
 {
     _context        = context;
     _codeGenerator  = codeGenerator;
     _outputStrategy = outputStrategy;
     _logger         = logger;
 }
Пример #3
0
Файл: TLD.cs Проект: denjiz/tld
 public Tld(IObjectModel objectModel, ITracker tracker, ILearner learner, IDetector detector, IOutputStrategy outputStrategy)
 {
     _objectModel    = objectModel;
     _tracker        = tracker;
     _learner        = learner;
     _detector       = detector;
     _outputStrategy = outputStrategy;
 }
Пример #4
0
        /// <summary>
        /// Generates output using the specified writer and output strategy.
        /// </summary>
        /// <param name="writer">The writer that should be used to generate the output.</param>
        /// <param name="outputStrategy">The output strategy that should be used to generate the output.</param>
        /// <returns>The output of a benchmark.</returns>
        public string Generate(TextWriter writer, IOutputStrategy outputStrategy)
        {
            Ensure.NotNull(writer, "writer");
            Ensure.NotNull(outputStrategy, "outputStrategy");

            builder.ToCustom(writer).AsCustom(outputStrategy);
            return writer.ToString();
        }
 /// <inheritdoc/>
 public void AsCustom(IOutputStrategy outputStrategy)
 {
     Ensure.ArgumentNotNull(outputStrategy, "outputStrategy");
     using (var writer = new StringWriter())
     {
         string result = generator.Generate(writer, outputStrategy);
         Console.WriteLine(result);
     }
 }
        /// <inheritdoc/>
        public void AsCustom(IOutputStrategy outputStrategy)
        {
            Ensure.ArgumentNotNull(outputStrategy, "outputStrategy");

            using (var stream = File.Open(path, FileMode.Create))
            using (var writer = new StreamWriter(stream))
            {
                builder.ToCustom(writer).AsCustom(outputStrategy);
            }
        }
Пример #7
0
 /// <inheritdoc/>
 public void AsCustom(IOutputStrategy outputStrategy)
 {
     Ensure.ArgumentNotNull(outputStrategy, "outputStrategy");
     using (var stream = File.Open(path, FileMode.CreateNew))
     using (var writer = new StreamWriter(stream))
     {
         string result = generator.Generate(writer, outputStrategy);
         writer.WriteLine(result);
     }
 }
Пример #8
0
        public void Send_MetricsResult_CallFormatterOnce(IOutputStrategy strategy)
        {
            var formatterMock = new Mock <IOutputFormatter>();
            var result        = new List <ScanResult>();
            var optionsMock   = new Mock <ScanCommandOptions>();

            formatterMock.Setup(f => f.Format <ScanResult>(result)).Returns("formatted text");
            strategy.Send(result, formatterMock.Object, optionsMock.Object);
            formatterMock.Verify(f => f.Format <ScanResult>(result), Times.Once());
        }
    public void Send_MetricsResult_CallFormatterOnce(IOutputStrategy strategy)
    {
        var formatterMock = new Mock <IOutputFormatter>();
        var result        = new List <ScanResult>();
        // We cannot mock DirectoryInfo, so we need to provide a real path (pwd for running test will do)
        var options = new ScanCommandOptions {
            Path = new DirectoryInfo(".")
        };

        formatterMock.Setup(f => f.Format <ScanResult>(result)).Returns("formatted text");
        strategy.Send(result, formatterMock.Object, options);
        formatterMock.Verify(f => f.Format <ScanResult>(result), Times.Once());
    }
Пример #10
0
        private static void WriteResults(GitHubFlowVersionContext context)
        {
            var outputStrategies = new IOutputStrategy[]
            {
                new BuildServerOutputStrategy(context.CurrentBuildServer),
                new JsonFileOutputStrategy(),
                new EnvironmentalVariablesOutputStrategy()
            };

            foreach (var outputStrategy in outputStrategies)
            {
                outputStrategy.Write(context);
            }
        }
Пример #11
0
        protected string GetOutput(IOutputStrategy outputStrategy)
        {
            var single = new SingleValueMetric("single", data => data.Sum())
            {
                DataProvider = sample => sample.Ticks,
                Samples = new List<TimeSpan> { new TimeSpan(100) },
                UnitOfMeasurement = "ticks"
            };

            var multiple = new MultipleValueMetric("multiple", data => data)
            {
                DataProvider = sample => sample.Ticks,
                Samples = new List<TimeSpan> { new TimeSpan(50), new TimeSpan(75) },
                UnitOfMeasurement = "ticks"
            };

            var metrics = new List<IMetric> { single, multiple };

            using (var writer = new StringWriter())
            {
                outputStrategy.Execute(writer, metrics);
                return writer.ToString();
            }
        }
Пример #12
0
 private static void WriteResults(GitHubFlowArguments arguments, SemanticVersion nextBuildNumber, IBuildServer currentBuildServer)
 {
     var variableProvider = new VariableProvider();
     var variables = variableProvider.GetVariables(nextBuildNumber);
     var outputStrategies = new IOutputStrategy[]
     {
         new BuildServerOutputStrategy(currentBuildServer),
         new JsonFileOutputStrategy(),
         new EnvironmentalVariablesOutputStrategy()
     };
     foreach (var outputStrategy in outputStrategies)
     {
         outputStrategy.Write(arguments, variables, nextBuildNumber);
     }
 }
Пример #13
0
 public void Check_FormatterType_IsExpectedType(IOutputStrategy outputStrategy, OutputStrategyType expectedType) =>
 outputStrategy.Type.Should().Be(expectedType);
 public OutputContext(IOutputStrategy outputStrategy)
 {
     this.outputStrategy = outputStrategy;
 }
Пример #15
0
 /// <summary>
 /// Specifies the output strategy.
 /// </summary>
 /// <param name="output">The output strategy that should be used to generate the output of the benchmark</param>
 public void AsCustom(IOutputStrategy output)
 {
     Ensure.ArgumentNotNull(output, "output");
     output.Execute(writer, metrics);
 }
Пример #16
0
 public OutputContext(IOutputStrategy outputStrategy)
 {
     this.outputStrategy = outputStrategy;
 }
Пример #17
0
 public OutputService(IOutputStrategy strategy)
 {
     outputStrategy = strategy;
 }
Пример #18
0
        static void Run(Options options)
        {
            if (options.OutputFile == null)
            {
                outputStrategy = new ConsoleOutputStrategy();
            }
            else
            {
                outputStrategy = new FileOutputStrategy(options.OutputFile);
            }

            var filters = new List <string> {
                options.Filters
            };

            if (options.Filters.Contains(";"))
            {
                filters = options.Filters.Split(new[] { ';' }).ToList();
            }

            //Prepare file filters and options,
            // figure out which files to read
            var filesToRead  = new List <string>();
            var searchOption = options.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            string path = Environment.CurrentDirectory;

            if (options.Path != null || Directory.Exists(options.Path))
            {
                path = options.Path;
            }

            foreach (var filter in filters)
            {
                try
                {
                    var files = Directory.EnumerateFiles(path, filter, searchOption);
                    filesToRead.AddRange(files);
                }
                catch (Exception)
                {
                    outputStrategy.Output("Invalid filter, {0}", ConsoleColor.Red, filter);
                }
            }

            //Count lines in the target files
            var linesByFile = new Dictionary <string, int>();
            int totalLines  = 0;
            int pathLength  = path.Length;

            foreach (var file in filesToRead)
            {
                int lines = 0;
                if (options.IncludeEmptyLines)
                {
                    lines = File.ReadLines(file).ToList().Count;
                }
                else
                {
                    lines = File.ReadLines(file).Count(l => !string.IsNullOrWhiteSpace(l));
                }

                linesByFile.Add(file.Substring(pathLength), lines);
                totalLines += lines;
            }

            int     filesCount          = filesToRead.Count;
            decimal averageLinesPerFile = (decimal)totalLines / filesCount;

            //Output the results
            outputStrategy.Output("locin - {0}", path);
            outputStrategy.Output("Number of files: {0}", filesCount);
            outputStrategy.Output("Total lines: {0}", totalLines);
            outputStrategy.Output("Avg. lines per file: {0:F2}", averageLinesPerFile);
            outputStrategy.Output("Breakdown:");
            outputStrategy.Output("==========");
            foreach (var file in linesByFile.OrderByDescending(f => f.Value))
            {
                outputStrategy.Output("{0,-9}{1}", file.Value, file.Key);
            }

            outputStrategy.Output("==========");
            outputStrategy.Output("Total lines: {0}", totalLines);

            outputStrategy.Finalise();
        }