Пример #1
0
        /// <summary>
        /// Constructs the filter from an array of arguments passed from console parameters
        /// -from
        /// -to
        /// -location
        /// -runLongerThan
        /// -trans (a comma separated list if expected transactions)
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static LogFilter FromArgs(string[] args)
        {
            var filter = new LogFilter();

            for (var i = 0; i < args.Length - 1; i++)
            {
                var current = args[i].ToLowerInvariant();
                var next    = args[i + 1];
                switch (current)
                {
                case "-from":
                    if (!string.IsNullOrWhiteSpace(next))
                    {
                        filter.From = DateTime.ParseExact(next, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    }
                    break;

                case "-to":
                    if (!string.IsNullOrWhiteSpace(next))
                    {
                        filter.To = DateTime.ParseExact(next, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    }
                    break;

                case "-location":
                    filter.Location = next;
                    break;

                case "-pattern":
                    filter.SearchPattern = next;
                    break;

                case "-runlongerthan":
                    if (!string.IsNullOrWhiteSpace(next))
                    {
                        filter.RunLongerThan = TimeSpan.Parse(next);
                    }
                    break;

                case "-trans":
                    if (!string.IsNullOrWhiteSpace(next))
                    {
                        filter.Transactions = next.Split(new[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    break;
                }
            }
            if (string.IsNullOrWhiteSpace(filter.SearchPattern))
            {
                filter.SearchPattern = "*.*";
            }
            return(filter);
        }
Пример #2
0
        private static bool IsMatched(PipelineResult result, LogFilter filer)
        {
            bool matched = true;

            if (filer.RunLongerThan != TimeSpan.Zero)
            {
                matched = TimeSpan.FromMilliseconds(result.TotalExecutionTime) >= filer.RunLongerThan;
            }
            if (filer.Transactions.Count > 0)
            {
                matched = matched && filer.Transactions.Any(t => result.TransactionType.IndexOf(t, StringComparison.InvariantCultureIgnoreCase) != -1);
            }
            return(matched);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var filter = LogFilter.FromArgs(args);

            if (string.IsNullOrWhiteSpace(filter.Location))
            {
                filter.Location = AppDomain.CurrentDomain.BaseDirectory;
            }
            var files = Directory.GetFiles(filter.Location, filter.SearchPattern, SearchOption.AllDirectories);

            if (filter.From.HasValue)
            {
                files = files.Where(x => new FileInfo(x).LastWriteTime.Date >= filter.From.Value).ToArray();
            }
            if (filter.To.HasValue)
            {
                files = files.Where(x => new FileInfo(x).LastWriteTime.Date <= filter.To.Value).ToArray();
            }

            var result = BuildExpression(filter, files);

            var sw = Stopwatch.StartNew();

            Console.WriteLine("Hold on .... and smile!");
            var    defaultColor     = Console.ForegroundColor;
            int    totalTransaction = 0;
            int    totalExecution   = 0;
            double totalTime        = 0;

            foreach (var r in result)
            {
                totalExecution         += r.NumberOfExecution;
                totalTime              += r.TotalExecutionTime;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(r.TransactionType);
                Console.ForegroundColor = defaultColor;
                Console.WriteLine("      {0} times - in {1}", r.NumberOfExecution, TimeSpan.FromMilliseconds(r.TotalExecutionTime));
                Console.WriteLine("");
                totalTransaction++;
            }
            sw.Stop();
            Console.WriteLine("Total transaction: {0}. Average: {2}. Done in: {1}",
                              totalTransaction, sw.Elapsed,
                              TimeSpan.FromMilliseconds(totalTime / totalExecution));
            Console.WriteLine("Press any key to exit ...");
        }