示例#1
0
        public ImageFileIndexResponse ReadImageFileIndex(string indexedLocation)
        {
            var request = new ImageFileIndexRequest()
            {
                IndexedLocation = indexedLocation
            };
            var response = new ImageFileIndexService.ImageFileIndex().ReadAllImageFileIndex(request);

            return(response);
        }
示例#2
0
        public async Task <ImageFileIndexUpdateResponse> UpdateImageFileIndex(string indexedLocation)
        {
            var request = new ImageFileIndexRequest()
            {
                IndexedLocation = indexedLocation
            };
            var response = await new ImageFileIndexService.ImageFileIndex().AnalyseImageFileIndex(request);

            return(response);
        }
示例#3
0
        public async Task AllFilesInDirectoryImportedIntoCollection()
        {
            var indexedLocation = "C:\\Users\\Tom_m\\OneDrive\\Pictures\\Test7Images";
            await Task.Run(async() =>
            {
                // Actual test code here.
                var request = new ImageFileIndexRequest()
                {
                    IndexedLocation = indexedLocation
                };
                var service = new ImageFileIndex("TestMosaicDatabase");
                await service.AnalyseImageFileIndex(request);
            });

            var result = new MongoImageFileIndex().ReadAll(database, indexedLocation);

            Assert.AreEqual(7, result.Files.Count);
        }
        // Analyse all files in current directory and update collection to reflect directory
        public async Task <ImageFileIndexUpdateResponse> AnalyseImageFileIndex(ImageFileIndexRequest request)
        {
            try
            {
                await Task.Run(() => {
                    // Store all files in indexed location
                    var indexedDirectory = new DirectoryInfo(request.IndexedLocation);
                    // Returns filenames in all sub directories as well
                    var directoryFiles = indexedDirectory.GetFiles("*.png", SearchOption.AllDirectories).ToList();

                    // Get exisiting files in location
                    var existingFiles = ReadAllImageFileIndex(request).Files.ToList();

                    // Get new files
                    var newFiles = directoryFiles.Where(f => !existingFiles.Any(f2 => f2.FilePath == f.FullName));
                    var newTask  = newFiles.Select(async x => await AnalyseNewFiles(x));

                    // Get updated files
                    var updatedFiles = directoryFiles.Where(f => existingFiles.Any(f2 => f2.FilePath == f.FullName && f.LastWriteTime.ToString() != f2.LastWriteTime));
                    var updatedTask  = updatedFiles.Select(async x => await AnalyseUpdatedFiles(x));

                    // Get deleted files
                    var deletedFiles = existingFiles.Where(f => !directoryFiles.Any(f2 => f2.FullName == f.FilePath));
                    var deleteTask   = deletedFiles.Select(async x => await AnalyseDeletedFiles(x.Id));

                    Task.WhenAll(newTask.Concat(updatedTask.Concat(deleteTask)));
                });

                return(new ImageFileIndexUpdateResponse()
                {
                    FilePath = request.IndexedLocation
                });
            }
            catch (Exception ex)
            {
                return(new ImageFileIndexUpdateResponse()
                {
                    FilePath = request.IndexedLocation, Error = ex.Message
                });
            }
        }
 public ImageFileIndexResponse ReadAllImageFileIndex(ImageFileIndexRequest request)
 {
     return(new MongoImageFileIndex().ReadAll(database, request.IndexedLocation));
 }