Ejemplo n.º 1
0
        private static void QuantifyLoop(
            string gitRepoPath,
            ClientOutputType clientOutputType)
        {
            while (true)
            {
                if ((DateTimeOffset.Now - changedEventDateTime).TotalSeconds < 1)
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(100));
                    continue;
                }

                quantifyClient = new QuantifyClient(contextFilePath);
                PrintResult(
                    quantifyClient.Compute(gitRepoPath).Result,
                    clientOutputType);
                changedEventDateTime = DateTimeOffset.MaxValue;
            }
        }
Ejemplo n.º 2
0
        private static void PrintResult(
            QuantifierResult quantifierResult,
            ClientOutputType clientOutputType)
        {
            Console.ForegroundColor = QuantifyClientHelper.GetColor(quantifierResult.Color);

            switch (clientOutputType)
            {
            case ClientOutputType.None:
            {
                Console.WriteLine(quantifierResult.ToConsoleOutput().Result);
                break;
            }

            case ClientOutputType.Detailed:
            {
                Console.WriteLine(JsonSerializer.Serialize(
                                      quantifierResult,
                                      new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                break;
            }

            case ClientOutputType.SummaryByFile:
            {
                Console.WriteLine(JsonSerializer.Serialize(
                                      new
                    {
                        quantifierResult.Label,
                        quantifierResult.QuantifiedLinesAdded,
                        quantifierResult.QuantifiedLinesDeleted,
                        Formula = quantifierResult.Formula.ToString(),
                        quantifierResult.PercentileAddition,
                        quantifierResult.PercentileDeletion,
                        Details = quantifierResult.QuantifierInput.Changes.Select(s =>
                                                                                  new
                        {
                            s.FilePath,
                            s.QuantifiedLinesAdded,
                            s.QuantifiedLinesDeleted,
                            s.DiscardFromCounting
                        })
                    },
                                      new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                break;
            }

            case ClientOutputType.SummaryByExt:
            {
                Console.WriteLine(JsonSerializer.Serialize(
                                      new
                    {
                        quantifierResult.Label,
                        quantifierResult.QuantifiedLinesAdded,
                        quantifierResult.QuantifiedLinesDeleted,
                        Formula = quantifierResult.Formula.ToString(),
                        quantifierResult.PercentileAddition,
                        quantifierResult.PercentileDeletion,
                        Details = quantifierResult.QuantifierInput.Changes.GroupBy(c => c.FileExtension).Select(g =>
                                                                                                                new
                        {
                            FileExtension          = g.Key,
                            QuantifiedLinesAdded   = g.Sum(v => v.QuantifiedLinesAdded),
                            QuantifiedLinesDeleted = g.Sum(v => v.QuantifiedLinesDeleted)
                        })
                    },
                                      new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(clientOutputType), clientOutputType, null);
            }

            Console.ResetColor();
        }