private static void Main() { var config = new Config(@"c:\") { ScanErrorMode = ScanErrorMode.Ignore }; config.OnDirectory += (o, a) => Console.WriteLine(a.Path); config.OnFile += (o, a) => Console.WriteLine(a.Path); Snarfzer.NewScanner().Start(config); }
private void CompressUsingMemory() { var item = GetNextItem(); while (item != null) { using (var strm = new MemoryStream()) { using (var archive = new ZipArchive(strm, ZipArchiveMode.Create, true)) { var cfg = new Config(item.Source) {ScanType = ScanType.FilesOnly}; cfg.OnFile += (o, a) => { var entryPath = a.Path.Replace(item.Source + "\\", ""); var entry = archive.CreateEntry(entryPath, CompressionLevel.Fastest); using (var entryStream = entry.Open()) { using (var fileStream = File.OpenRead(a.Path)) { fileStream.CopyTo(entryStream); fileStream.Close(); } entryStream.Flush(); entryStream.Close(); } }; Snarfzer.NewScanner().Start(cfg); } strm.Position = 0; using (var outstream = File.OpenWrite(item.Dest)) strm.CopyTo(outstream); } item = GetNextItem(); } }
private void NotifyOnDirectory(Config config, string currentDir) { if (config.ScanType == ScanType.FilesOnly) return; var args = new DirectoryVisitEventArgs(currentDir); Notify(config, () => config.Handlers.HandleDirectory(args)); mPruned = args.Prune; }
private void Notify(Config config, Action notifier) { try { notifier(); } catch (Exception e) { mEventErrorHandler.Handle(config, e); } }
public void Handle(Config config, Exception exception) { switch (config.EventErrorMode) { case EventErrorMode.Throw: throw new ScanException(exception.Message, exception); default: return; } }
private static void Execute(IEnumerable<string> args) { var root = ExtractArg(args, "/dir:"); Console.WriteLine("Scanning {0}", root); Console.WriteLine("----"); var config = new Config(root) {ScanType = ScanType.DirectoriesOnly}; config.OnDirectory += ReviewDirectory; Snarfzer.NewScanner().Start(config); }
private IEnumerable<string> GetItems(Config config, ScanErrorSource source, string currentPath, Func<IEnumerable<string>> getter) { try { return getter(); } catch (Exception e) { mScanErrorHandler.Handle(config, source, currentPath, e); } return Enumerable.Empty<string>(); }
private void ProcessDirectory(Config config, string currentDir) { NotifyOnDirectory(config, currentDir); if (mPruned) return; ProcessFilesForDir(config, currentDir); ProcessSubDirectoriesForDir(config, currentDir); }
public void DoSetup() { mDirSeen = new List<DirectoryVisitEventArgs>(); mFileSeen = new List<FileVisitEventArgs>(); mConfig = new Config(_Root); mConfig.OnDirectory += (o, a) => mDirSeen.Add(a); mConfig.OnFile += (o, a) => mFileSeen.Add(a); mDirectory = Mok<IDirectory>(); mScanErrorHandler = Mok<IScanErrorHandler>(); mEventErrorHandler = Mok<IEventErrorHandler>(); mScanner = new Scanner(mDirectory.Object, mScanErrorHandler.Object, mEventErrorHandler.Object); }
public void Handle(Config config, ScanErrorSource source, string currentPath, Exception exception) { switch (config.ScanErrorMode) { case ScanErrorMode.Ask: AskHandlers(config, source, currentPath, exception); break; case ScanErrorMode.Throw: throw new ScanException(exception.Message, exception); default: return; } }
public void DoSetup() { mConfig = CA<Config>(); mHandler = new EventErrorHandler(); }
public void DoSetup() { mConfig = new Config(""); mHandlers = new EventHandlers(mConfig); }
public void DoSetup() { mConfig = new Config("apath"); }
private static void AskHandlers(Config config, ScanErrorSource source, string currentPath, Exception exception) { config.Handlers.HandleError(new ScanErrorEventArgs(source, currentPath, exception)); }
public void Start(Config config) { ProcessDirectory(config, config.Root); }
private void ProcessFilesForDir(Config config, string dir) { if (config.ScanType == ScanType.DirectoriesOnly) return; foreach (var file in GetFile(config, dir)) { var args = new FileVisitEventArgs(file); Notify(config, () => config.Handlers.HandleFile(args)); if (args.Prune) break; } }
private IEnumerable<string> GetSubDirectories(Config config, string currentDir) { return GetItems(config, ScanErrorSource.Directory, currentDir, () => mDirectory.GetDirectories(currentDir)); }
private IEnumerable<string> GetFile(Config config, string currentDir) { return GetItems(config, ScanErrorSource.File, currentDir, () => mDirectory.GetFiles(currentDir, "*.*")); }
public EventHandlers(Config config) { mConfig = config; }
private void ProcessSubDirectoriesForDir(Config config, string currentDir) { foreach (var dir in GetSubDirectories(config, currentDir)) ProcessDirectory(config, dir); }