예제 #1
0
 public override FolderToScan Add(FolderToScan folderToScan)
 {
     folderToScan.FolderToScanId = folderToScanIndex++;
       StringBuilder jsonString = new StringBuilder();
       jsonString.AppendLine(JsonSerializer.SerializeToString<FolderToScan>(folderToScan));
       System.IO.File.AppendAllText(pathToJsonFile, jsonString.ToString());
       return folderToScan;
 }
예제 #2
0
 public override FolderToScan Add(FolderToScan folderToScan)
 {
     folderToScan.FolderToScanId = folderToScanIndex++;
       string folderToScanJson = JsonConvert.SerializeObject(folderToScan);
       using (var stream = new StreamWriter(pathToJsonFile, append: true)) {
     stream.WriteLine(folderToScanJson);
       }
       return folderToScan;
 }
 public void AddFolderToScan_ShouldAddFolderAndSetID()
 {
     System.IO.File.Delete(sampleJsonFile);
       JsonFolderToScanRepository jsonFolderToScanRepository = new JsonFolderToScanRepository(sampleJsonFile);
       FolderToScan folderToScan = new FolderToScan {
     AbsolutePath = System.Environment.CurrentDirectory,
     PathAlias = "TestFolder"
       };
       FolderToScan addedFolder = jsonFolderToScanRepository.Add(folderToScan);
       Assert.True(jsonFolderToScanRepository.GetFoldersToScan().Single().FolderToScanId == 1);
 }
 public void GetFolderById_GetsFolderById()
 {
     System.IO.File.Delete(sampleJsonFile);
       JsonFolderToScanRepository jsonFolderToScanRepository = new JsonFolderToScanRepository(sampleJsonFile);
       for (int i = 0; i < 10; i++) {
     FolderToScan folderToScan = new FolderToScan {
       AbsolutePath = System.Environment.CurrentDirectory,
       PathAlias = "TestFolder" + i
     };
     jsonFolderToScanRepository.Add(folderToScan);
       }
       IEnumerable<FolderToScan> foldersToScan = jsonFolderToScanRepository.GetFoldersToScan();
       FolderToScan folder = foldersToScan.ToArray()[4];
       Assert.True(folder.PathAlias == "TestFolder4");
 }
 public void AddFoldersToScan_ShouldAddFolders()
 {
     int numberOfFoldersToAddToTheRepository = 10;
       List<FolderToScan> foldersToAdd = new List<FolderToScan>();
       for (int i = 0; i < numberOfFoldersToAddToTheRepository; i++) {
     FolderToScan folderToScan = new FolderToScan {
       AbsolutePath = System.Environment.CurrentDirectory,
       PathAlias = "TestFolder" + i
     };
     foldersToAdd.Add(folderToScan);
       }
       System.IO.File.Delete(sampleJsonFile);
       JsonFolderToScanRepository jsonFolderToScanRepository = new JsonFolderToScanRepository(sampleJsonFile);
       jsonFolderToScanRepository.Add(foldersToAdd);
       Assert.True(foldersToAdd.Count == numberOfFoldersToAddToTheRepository);
 }
예제 #6
0
파일: Scanner.cs 프로젝트: andyjmay/Gopher
        public void ScanFolder(System.IO.DirectoryInfo directoryInfo, FolderToScan folderToScan, int? parentFolderId = null)
        {
            try {
            var folder = new Folder {
              Name = directoryInfo.Name,
              Path = directoryInfo.FullName.Replace(folderToScan.AbsolutePath, folderToScan.PathAlias),
              ParentFolderId = parentFolderId
            };
            folderRepository.Add(folder);
            Logger.Trace("Added folder " + folder.Path);

            var fileInfos = directoryInfo.EnumerateFiles("*", System.IO.SearchOption.TopDirectoryOnly);
            var files = new List<Models.File>();

            foreach (var fileInfo in fileInfos) {
              try {
            var file = new Models.File {
              Name = fileInfo.Name,
              Path = fileInfo.FullName.Replace(folderToScan.AbsolutePath, folderToScan.PathAlias),
              Size = fileInfo.Length,
              FolderId = folder.FolderId,
              CreatedTime = fileInfo.CreationTime,
              LastAccessTime = fileInfo.LastAccessTime,
              LastWriteTime = fileInfo.LastWriteTime
            };
            files.Add(file);
            Logger.Trace("Added file " + file.Name);
              } catch (System.IO.PathTooLongException ex) {
            // TODO: Handle these (very common) errors
              } catch (Exception ex) {
            Logger.ErrorException("Error scanning file " + fileInfo.FullName, ex);
              }
            }
            fileRepository.Add(files);

            foreach (var subDirectory in directoryInfo.EnumerateDirectories("*", System.IO.SearchOption.TopDirectoryOnly)) {
              ScanFolder(subDirectory, folderToScan, parentFolderId = folder.FolderId);
            }
              } catch (System.IO.PathTooLongException ex) {
            // TODO: Handle these (very common) errors
              } catch (Exception ex) {
            Logger.ErrorException("Error scanning directory " + directoryInfo.FullName, ex);
              }
        }
예제 #7
0
 private void indexFolder(FolderToScan folderToScan)
 {
     try {
     var folderStopwatch = Stopwatch.StartNew();
     var scanner = new Scanner(context.SelectedFileRepository, context.SelectedFolderRepository, logger);
     scanner.ScanFolder(new DirectoryInfo(folderToScan.AbsolutePath), folderToScan);
     output.WriteLine(string.Format("Took {0} milliseconds to scan {1} (Alias: {2})", folderStopwatch.ElapsedMilliseconds, folderToScan.AbsolutePath, folderToScan.PathAlias));
     folderStopwatch.Stop();
       } catch (Exception ex) {
      logger.ErrorException("Exception encountered while scanning " + folderToScan.AbsolutePath, ex);
       }
 }
예제 #8
0
        private void handleAdd(string[] args)
        {
            if (args.Length < 2) {
            ShowHelp();
            return;
              }

              if (context.SelectedFolderToScanRepository == null) {
            output.WriteLine("You must first set a FolderToScan Repository");
            return;
              }

              var folderToScan = new FolderToScan();
              folderToScan.AbsolutePath = args[1];

              if (args.Length == 3) {
            folderToScan.PathAlias = args[2];
              } else {
            folderToScan.PathAlias = folderToScan.AbsolutePath;
              }

              IEnumerable<FolderToScan> existingFoldersToScan = context.SelectedFolderToScanRepository.GetFoldersToScan();

              if(existingFoldersToScan.Any(f => f.AbsolutePath == folderToScan.AbsolutePath)) {
            output.WriteLine("This folder has already been added to the repository");
            return;
              }

              context.SelectedFolderToScanRepository.Add(folderToScan);
              output.WriteLine("Added {0} to the repository", folderToScan);
        }
 public override void Remove(FolderToScan folderToScan)
 {
     foldersToScan.RemoveAll(f => f.AbsolutePath.ToLower() == folderToScan.AbsolutePath.ToLower());
 }
 public override FolderToScan Add(FolderToScan folderToScan)
 {
     folderToScan.FolderToScanId = folderToScanIndex++;
       foldersToScan.Add(folderToScan);
       return folderToScan;
 }
예제 #11
0
 public override void Remove(FolderToScan folderToScan)
 {
     List<FolderToScan> existingFoldersToScan = GetFoldersToScan().ToList();
       existingFoldersToScan.RemoveAll(f => f.AbsolutePath.ToLower() == folderToScan.AbsolutePath.ToLower());
       if (existingFoldersToScan.Count > 0) {
     StringBuilder jsonString = new StringBuilder();
     foreach (FolderToScan folder in existingFoldersToScan) {
       jsonString.AppendLine(JsonSerializer.SerializeToString<FolderToScan>(folder));
     }
     System.IO.File.WriteAllText(pathToJsonFile, jsonString.ToString());
       } else {
     System.IO.File.Delete(pathToJsonFile);
     folderToScanIndex = 0;
       }
 }
 public void GetFoldersToScan_GetsSerializesFoldersToScan()
 {
     System.IO.File.Delete(sampleJsonFile);
       JsonFolderToScanRepository jsonFolderToScanRepository = new JsonFolderToScanRepository(sampleJsonFile);
       for (int i = 0; i < 10; i++) {
     FolderToScan folderToScan = new FolderToScan {
       AbsolutePath = System.Environment.CurrentDirectory,
       PathAlias = "TestFolder" + i
     };
     jsonFolderToScanRepository.Add(folderToScan);
       }
       IEnumerable<FolderToScan> foldersToScan = jsonFolderToScanRepository.GetFoldersToScan();
       Assert.True(foldersToScan.Count() == 10);
 }
예제 #13
0
 public override void Remove(FolderToScan folderToScan)
 {
     List<FolderToScan> existingFoldersToScan = GetFoldersToScan().ToList();
       existingFoldersToScan.RemoveAll(f => f.AbsolutePath.ToLower() == folderToScan.AbsolutePath.ToLower());
       string json = JsonConvert.SerializeObject(existingFoldersToScan);
       System.IO.File.WriteAllText(pathToJsonFile, json);
 }
예제 #14
0
 public abstract void Remove(FolderToScan folderToScan);
예제 #15
0
 public abstract FolderToScan Add(FolderToScan folderToScan);