Ejemplo n.º 1
0
        public RawImage ReadRawImageFromDatabase(ThumbnailEntryModel thumbnail)
        {
            lock (_fileOperationLock)
            {
                if (_fileStream == null)
                {
                    _fileStream = File.Open(_fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                }


                _fileStream.Lock(thumbnail.FilePosition, thumbnail.Length);
                _fileStream.Position = thumbnail.FilePosition;

                var ms = new MemoryStream();
                _fileStream.CopyTo(ms, thumbnail.Length);

                ms.Flush();
                byte[] imageData = ms.ToArray();
                ms.Close();
                ms.Dispose();

                _fileStream.Unlock(thumbnail.FilePosition, thumbnail.Length);

                return(new RawImage(imageData));
            }
        }
Ejemplo n.º 2
0
        private RawImage LoadImageFromDatabase(string filename)
        {
            ThumbnailEntryModel thumbnail = _thumbnailRepository.GeThumbnailEntry(filename);

            try
            {
                return(_fileManager.ReadRawImageFromDatabase(thumbnail));
            }
            catch (Exception ex)
            {
                using (LogContext.PushProperty("Data", thumbnail))
                {
                    Log.Error(ex, "LoadImageFromDatabase failed");
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        private int PerformThumbnailScan(string path, IProgress <ThumbnailScanProgress> progress)
        {
            var files = Directory.GetFiles(path);

            if (!Directory.Exists(path))
            {
                return(0);
            }

            if (!path.EndsWith("\\"))
            {
                path += "\\";
            }

            int filesToScan  = files.Length;
            int scannedFiles = 0;

            if (_abortScan)
            {
                return(0);
            }

            foreach (string fullPath in files)
            {
                string fileName = GeneralConverters.GetFileNameFromPath(fullPath);
                if (_abortScan)
                {
                    break;
                }

                if (!_fileNameRegExp.IsMatch(fileName) || _thumbnailRepository.IsCached(fullPath))
                {
                    continue;
                }
                Image img = null;

                try
                {
                    img = _thumbnailRepository.GetThumbnailImage(fullPath);
                }
                catch (Exception exception)
                {
                    Log.Error(exception, "Error loading file: " + fullPath);
                }

                if (img == null)
                {
                    continue;
                }

                var fileInfo = new FileInfo(fullPath);

                var thumbnail = new ThumbnailEntryModel
                {
                    Date              = DateTime.Now,
                    SourceImageDate   = fileInfo.LastWriteTime,
                    FileName          = fileName,
                    Directory         = path,
                    SourceImageLength = fileInfo.Length,
                };



                IsModified = true;

                // Update progress
                scannedFiles++;
                progress?.Report(new ThumbnailScanProgress {
                    TotalAmountOfFiles = filesToScan, ScannedFiles = scannedFiles
                });
            }

            return(scannedFiles);
        }