Ejemplo n.º 1
0
        internal void PrintTables(LogStatsParams statsParams, Totals totals)
        {
            foreach (CompareMethod method in statsParams.Options.Keys)
            {
                int tot = statsParams.Options[method];

                foreach (Total table in totals.GetTotals())
                {
                    Sorter sorter = new Sorter(table.GetValues());

                    ArrayList values = sorter.SortBy(method);
                    values.Reverse(); // maximum to minimum

                    if (tot < int.MaxValue)
                    {
                        if (values.Count > tot)
                            values = values.GetRange(0, tot);
                    }

                    Console.WriteLine();
                    Console.WriteLine("{0} {1}", table.GetName(), method.ToString());
                    PrintTable(values);
                }
            }
        }
Ejemplo n.º 2
0
        internal Totals Parse(LogStatsParams logParams, InputReader inputReader)
        {
            int lineCount = 0;
            Totals totals = new Totals(logParams.GroupByMode);

            string line;

            while ((line = inputReader.ReadLine()) != null)
            {
                ++lineCount;
                try
                {
                    LogEntry entry = ReadEntry(line, logParams.HasToFailOnError);
                    totals.SumEntry(entry);
                }
                catch (Exception e)
                {
                    string msg = string.Format("(line {0}) {1}", lineCount, e.Message);
                    if (logParams.HasToFailOnError)
                        throw new Exception(msg);
                    else
                        LogError(msg);
                }
            }

            Console.WriteLine("{0} lines read", lineCount);
            return totals;
        }
Ejemplo n.º 3
0
        private static InputReader InitializeInput(LogStatsParams statsParams)
        {
            if (statsParams.HasToReadFromFile)
                return InputReader.FromFile(statsParams.InputFile);

            return InputReader.FromStdIn();
        }
Ejemplo n.º 4
0
        private static void Start(LogStatsParams statsParams)
        {
            InputReader inputReader = InitializeInput(statsParams);

            Totals totals;

            try
            {
                InputParser inputParser = new InputParser();

                totals = inputParser.Parse(statsParams, inputReader);
            }
            finally
            {
                inputReader.Close();
            }

            StatsPrinter statsPrinter = new StatsPrinter();
            statsPrinter.PrintTables(statsParams, totals);
            statsPrinter.PrintTotals(totals);
        }
Ejemplo n.º 5
0
        static int Main(string[] args)
        {
            try
            {
                LogStatsParams statsParams = new LogStatsParams(args);

                if (statsParams.HasToShowHelp)
                {
                    ShowHelp();
                    return 0;
                }

                Start(statsParams);

                return 0;
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occurred when executing plasticlogstats:");
                Console.WriteLine(string.Format("\t{0}", ex.Message));

                return -1;
            }
        }