private Snapshot ReadPath(string path)
        {
            AnalysisRequest analysisRequest = new AnalysisRequest
            {
                RootPath = path
            };

            SnapshotAnalysisExport snapshotAnalysisExport = new SnapshotAnalysisExport();
            IDiskAnalyzer          diskReader             = diskAnalyzerFactory.Create(analysisRequest, snapshotAnalysisExport);

            diskReader.Starting += HandleDiskReaderStarting;
            diskReader.Run();

            return(snapshotAnalysisExport.Snapshot);
        }
Esempio n. 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);
            }
        }