Example #1
0
 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);
 }
Example #2
0
        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();
              }
        }
Example #3
0
 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;
 }
Example #4
0
 private void Notify(Config config, Action notifier)
 {
     try {
     notifier();
       } catch (Exception e) {
     mEventErrorHandler.Handle(config, e);
       }
 }
Example #5
0
 public void Handle(Config config, Exception exception)
 {
     switch (config.EventErrorMode) {
     case EventErrorMode.Throw:
       throw new ScanException(exception.Message, exception);
     default:
       return;
       }
 }
Example #6
0
 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);
 }
Example #7
0
 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>();
 }
Example #8
0
        private void ProcessDirectory(Config config, string currentDir)
        {
            NotifyOnDirectory(config, currentDir);

              if (mPruned)
            return;

              ProcessFilesForDir(config, currentDir);
              ProcessSubDirectoriesForDir(config, currentDir);
        }
Example #9
0
 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);
 }
Example #10
0
 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;
       }
 }
Example #11
0
 public void DoSetup()
 {
     mConfig = CA<Config>();
       mHandler = new EventErrorHandler();
 }
Example #12
0
 public void DoSetup()
 {
     mConfig = new Config("");
       mHandlers = new EventHandlers(mConfig);
 }
Example #13
0
 public void DoSetup()
 {
     mConfig = new Config("apath");
 }
Example #14
0
 private static void AskHandlers(Config config, ScanErrorSource source, string currentPath, Exception exception)
 {
     config.Handlers.HandleError(new ScanErrorEventArgs(source, currentPath, exception));
 }
Example #15
0
 public void Start(Config config)
 {
     ProcessDirectory(config, config.Root);
 }
Example #16
0
        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;
              }
        }
Example #17
0
 private IEnumerable<string> GetSubDirectories(Config config, string currentDir)
 {
     return GetItems(config, ScanErrorSource.Directory, currentDir, () => mDirectory.GetDirectories(currentDir));
 }
Example #18
0
 private IEnumerable<string> GetFile(Config config, string currentDir)
 {
     return GetItems(config, ScanErrorSource.File, currentDir, () => mDirectory.GetFiles(currentDir, "*.*"));
 }
Example #19
0
 public EventHandlers(Config config)
 {
     mConfig = config;
 }
Example #20
0
 private void ProcessSubDirectoriesForDir(Config config, string currentDir)
 {
     foreach (var dir in GetSubDirectories(config, currentDir))
     ProcessDirectory(config, dir);
 }