Beispiel #1
0
        public void ProcessAvailableImages(IWatchedFileRepository watchedFileRepository, IImageServer server)
        {
            if (_mode.Equals(OperationMode.UploadAndClear))
            {
                throw new NotImplementedException();
            }

            var images = _directoryScanner.GetAvailableImages(watchedFileRepository, _watchPath, _acceptableExtensions, _includeSubDirectories, _sortStrategy);

            foreach (var image in images.Where(image => image != null))
            {
                try
                {
                    if (!image.UploadSuccessful &&
                        (_mode.Equals(OperationMode.UploadAndClear) || _mode.Equals(OperationMode.UploadOnly) || _mode.Equals(OperationMode.UploadAndSort)))
                    {
                        image.SendToServer(server);
                        watchedFileRepository.Save(image);
                    }

                    if (image.IsInBaseDirectory(_watchPath) &&
                        (_mode.Equals(OperationMode.SortOnly) || _mode.Equals(OperationMode.UploadAndSort)))
                    {
                        _log.Debug(string.Format("Beginning sort of file: {0}", image.FullPath));
                        image.SortFile();
                    }
                }
                catch (IOException ex)
                {
                    image.UploadSuccessful = false;
                    watchedFileRepository.Save(image);
                    _log.Error("Failed: " + image, ex);
                }
            }
        }
        public IList <IWatchedFile> GetAvailableImages(IWatchedFileRepository watchedFileRepository, string path, IList <string> acceptableExtensions, bool includeSubDirectories,
                                                       ISortStrategy sortStrategy)
        {
            _log.DebugFormat("Beginning to list available images: {0}", path);

            var imageFiles = new List <IWatchedFile>();

            _acceptableExtensions  = acceptableExtensions;
            _includeSubDirectories = includeSubDirectories;

            PopulateFilesForFolder(watchedFileRepository, imageFiles, path);

            _log.DebugFormat("Returning list of available images: {0} with count {1}", path, imageFiles.Count);

            return(imageFiles);
        }
        private void PopulateFilesForFolder(IWatchedFileRepository watchedFileRepository, List <IWatchedFile> fileList, string path)
        {
            _log.DebugFormat("populating files and subfiles in {0}", path);

            foreach (var file in _directory.GetFiles(path).Where(f => _acceptableExtensions.Contains(_path.GetExtension(f))))
            {
                var watchedFile = watchedFileRepository.LoadFileForPath(file);
                _log.DebugFormat("Processing file {0}", file);

                // If we can't find the file then create it
                if (watchedFile == null)
                {
                    watchedFile                  = watchedFileRepository.CreateNew();
                    watchedFile.FullPath         = file;
                    watchedFile.FileName         = _path.GetFileName(file);
                    watchedFile.UploadSuccessful = false;
                }
                else
                {
                    // This is a hack until I can get things fully dependency injected.
                    var tmp = watchedFile;
                    watchedFile                  = watchedFileRepository.CreateNew();
                    watchedFile.FullPath         = tmp.FullPath;
                    watchedFile.FileName         = tmp.FileName;
                    watchedFile.UploadSuccessful = tmp.UploadSuccessful;
                }


                // Ensure each file has the correct sort strategy in-case it has changed.
                watchedFile.SortStrategy = _sortStrategy;
                fileList.Add(watchedFile);
            }

            if (_includeSubDirectories)
            {
                foreach (var directory in _directory.GetDirectories(path))
                {
                    PopulateFilesForFolder(watchedFileRepository, fileList, directory);
                }
            }
        }
        public void ProcessAvailableImages(IWatchedFileRepository watchedFileRepository, IImageServer server)
        {
            if (_mode.Equals(OperationMode.UploadAndClear)) throw new NotImplementedException();

            var images = _directoryScanner.GetAvailableImages(watchedFileRepository, _watchPath, _acceptableExtensions, _includeSubDirectories, _sortStrategy);

            foreach (var image in images.Where(image => image != null))
            {
                try
                {
                    if (!image.UploadSuccessful
                        && (_mode.Equals(OperationMode.UploadAndClear) || _mode.Equals(OperationMode.UploadOnly) || _mode.Equals(OperationMode.UploadAndSort)))
                    {
                        image.SendToServer(server);
                        watchedFileRepository.Save(image);
                    }

                    if (image.IsInBaseDirectory(_watchPath)
                        && (_mode.Equals(OperationMode.SortOnly) || _mode.Equals(OperationMode.UploadAndSort)))
                    {
                        _log.Debug(string.Format("Beginning sort of file: {0}", image.FullPath));
                        image.SortFile();
                    }

                }
                catch (IOException ex)
                {
                    image.UploadSuccessful = false;
                    watchedFileRepository.Save(image);
                    _log.Error("Failed: " + image, ex);
                }
            }
        }