public IDiskAnalyzer Create(AnalysisRequest request, IAnalysisExport analysisExport)
 {
     return(new DiskAnalyzer
     {
         RootPath = request.RootPath,
         AnalysisExport = analysisExport,
         BlackList = request.BlackList
     });
 }
Example #2
0
        protected override void Handle(CreateSnapshotRequest request)
        {
            blackList = ReadBlackList(request.BlackListFilePath);

            if (request.SourcePath == null)
            {
                throw new Exception("SourcePath was not provided.");
            }

            if (!Directory.Exists(request.SourcePath))
            {
                throw new Exception("The SourcePath does not exist.");
            }

            logger.Info("Scanning path: {0}", request.SourcePath);
            logger.Info("Results file: {0}", request.DestinationFilePath);
            logger.Info("Black List:");

            if (blackList != null)
            {
                foreach (string blackListItem in blackList)
                {
                    logger.Info(blackListItem);
                }
            }

            using (StreamWriter streamWriter = new StreamWriter(request.DestinationFilePath))
            {
                AnalysisRequest analysisRequest = new AnalysisRequest
                {
                    RootPath  = request.SourcePath,
                    BlackList = blackList
                };
                IAnalysisExport jsonAnalysisExport = analysisExportFactory.Create(streamWriter);
                IDiskAnalyzer   diskAnalyzer       = diskAnalyzerFactory.Create(analysisRequest, jsonAnalysisExport);
                diskAnalyzer.Starting         += HandleDiskReaderStarting;
                diskAnalyzer.ErrorEncountered += HandleDiskReaderErrorEncountered;

                Stopwatch stopwatch = Stopwatch.StartNew();
                diskAnalyzer.Run();
                stopwatch.Stop();

                logger.Info("Finished scanning path {0}", stopwatch.Elapsed);
            }
        }