public override File Add(File fileToAdd)
 {
     fileToAdd.FileId = fileIndex++;
       using (var indexService = new IndexService(directoryIndexWriter)) {
     IndexResult indexResult = indexService.IndexEntity(fileToAdd, new FileIndexDefinition());
       }
       return fileToAdd;
 }
 public override File Add(File fileToAdd)
 {
     fileToAdd.FileId = fileIndex++;
       string fileJson = JsonConvert.SerializeObject(fileToAdd);
       using (var stream = new System.IO.StreamWriter(pathToJsonFile, append: true)) {
     stream.WriteLine(fileJson);
     stream.Close();
       }
       return fileToAdd;
 }
 public override File Add(File fileToAdd)
 {
     fileToAdd.FileId = fileIndex++;
       files.Add(fileToAdd);
       if (reachedBatchSize != null) {
     numberOfFilesInCurrentBatch++;
     if (batchSize != 0 && numberOfFilesInCurrentBatch >= batchSize) {
       reachedBatchSize(files);
       numberOfFilesInCurrentBatch = 0;
       files.Clear();
     }
       }
       return fileToAdd;
 }
Exemple #4
0
        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);
              }
        }
 public abstract File Add(File fileToAdd);