Beispiel #1
0
        public void CompareCurrentWithPrevious()
        {
            var files = _directoryReader.GetFiles(_directoryReader.GetCurrentDirectory(), "log_*.txt");

            if (files.Length < 2)
            {
                throw new ArgumentOutOfRangeException($"{nameof(files.Length)}={files.Length}", "Not enough log files in the the directory to do a comparison. Expecting 2 or more files.");
            }

            var mostRecentLog = (from file in files
                                 orderby DateTime.ParseExact(_pathReader.GetFileNameWithoutExtension(file).Replace("log_", ""),
                                                             "yyyy_MM_d__HH_mm_ss", CultureInfo.InvariantCulture) descending
                                 select file).Take(1).First();


            const string errorKey = "[ERR]";

            foreach (var file in files)
            {
                if (file == mostRecentLog)
                {
                    continue;
                }

                foreach (var line in _fileReader.ReadAllLines(file))
                {
                    if (line.Contains(errorKey))
                    {
                        var indexOf     = line.IndexOf(errorKey, StringComparison.Ordinal);
                        var trimmedLine = line.Remove(0, indexOf + 1 + errorKey.Length).Trim();
                        _previousScan.Add(trimmedLine);
                    }
                }
            }

            foreach (var line in _fileReader.ReadAllLines(mostRecentLog))
            {
                if (line.Contains(errorKey))
                {
                    var indexOf     = line.IndexOf(errorKey, StringComparison.Ordinal);
                    var trimmedLine = line.Remove(0, indexOf + 1 + errorKey.Length).Trim();
                    _currentScan.Add(trimmedLine);
                }
            }

            _currentScan.ExceptWith(_previousScan);

            var totalProblems = 0;

            foreach (var line in _currentScan)
            {
                _logger.Error(line);
                totalProblems++;
            }

            if (totalProblems > 0)
            {
                _logger.Info($"Total problems found: {totalProblems}.");
            }
        }
Beispiel #2
0
 public static void exInfo(this Ninject.Extensions.Logging.ILogger logger, ExternalServices serviceName, string message, params object[] argument)
 {
     NLog.LogManager.Configuration.Variables["serviceName"] = serviceName.ToString();
     logger.Info(message, argument);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            Console.WriteLine("############ STARTING UP... ############");
            IKernel kernel = new StandardKernel(new ScanningModule());
            ILogger logger = kernel.Get <ILogger>();

            Console.WriteLine("############ SCANNING FILES... ############");
            var fileVisitor = kernel.Get <RepositoryVisitor>();

            fileVisitor.Visit();

            var codeBase = fileVisitor.GetCodeBase();

            var problemFinder = kernel.Get <ProblemFinder>();

            Console.WriteLine("############ ANALYZING... ############");
            var totalProblems = 0;

            foreach (var problem in problemFinder.FindProblems(codeBase))
            {
                logger.Error($"{problem.Name} => {problem.Description}");
                totalProblems++;
            }
            stopwatch.Stop();

            if (totalProblems > 0)
            {
                logger.Info($"Total problems found: {totalProblems}.");
                logger.Info($"Found in: {stopwatch.Elapsed.TotalSeconds}s.");
            }

            Console.WriteLine("############ DONE ############");
            Console.WriteLine($"############ EXECUTION TIME : {stopwatch.Elapsed.TotalSeconds}s ############");

            Console.ReadLine();


            #region OLD

            //    //TODO : Take those from user (cmd args or Winforms)
            //    const string commonRepositoryName = "Common";
            //    const string commonRepositoryFolderPath = @"D:\iBWave\src\Common";
            //    const string designRepositoryName = "Design";
            //    const string designRepositoryFolderPath = @"D:\iBWave\src\Design";
            //    const string unityRepositoryName = "Unity";
            //    const string unityRepositoryFolderPath = @"D:\iBWave\src\Unity";
            //    const string outputFolderPath = @"C:\Users\averbuk\Documents\iBwave\General Business\2019\Repositories mess";

            //    TryCleanOutput(outputFolderPath);

            //    var commonScanResult = V1.RepositoryScanner.ScanRepository(commonRepositoryName, commonRepositoryFolderPath);
            //    var designScanResult = V1.RepositoryScanner.ScanRepository(designRepositoryName, designRepositoryFolderPath);
            //    var unityScanResult = V1.RepositoryScanner.ScanRepository(unityRepositoryName, unityRepositoryFolderPath);
            //    var scanResults = new[] {commonScanResult, designScanResult, unityScanResult};

            //    V1.RepositoryScanner.SetFileInProjectRepositoryProperties(scanResults);

            //    V1.RepositoryScanner.SaveRawResults(commonScanResult, outputFolderPath);
            //    V1.RepositoryScanner.SaveRawResults(designScanResult, outputFolderPath);
            //    V1.RepositoryScanner.SaveRawResults(unityScanResult, outputFolderPath);

            //    V1.RepositoryScanner.SaveSolutionResults(scanResults, outputFolderPath);
            //    V1.RepositoryScanner.SaveProjectsReport(scanResults, outputFolderPath);
            //    V1.RepositoryScanner.SaveFilesReport(scanResults, outputFolderPath);

            //    Console.WriteLine("Press any key to quit");
            //    Console.ReadKey();
            //}

            //private static void TryCleanOutput(string directoryToClean)
            //{
            //    try
            //    {
            //        var di = new DirectoryInfo(directoryToClean);

            //        foreach (var file in di.GetFiles())
            //        {
            //            file.Delete();
            //        }

            //        foreach (var dir in di.GetDirectories())
            //        {
            //            dir.Delete(true);
            //        }
            //    }
            //    catch{}

            #endregion
        }