예제 #1
0
        private void Watcher_Created(object sender, FileSystemEventArgs e)
        {
            if (!ImageExtensions.Any() || !ImageFilter(e.Name))
            {
                return;
            }

            lock (_locker)
            {
                if (_imagesNames.Any())
                {
                    var prevFileName = Path.GetFileNameWithoutExtension(_imagesNames.Last());
                    var newFileName  = Path.GetFileNameWithoutExtension(e.Name);
                    if (IsNumericGapDetected(prevFileName, newFileName))
                    {
                        EndOfFileEventDetected?.Invoke(_imagesNames.ToArray());
                        _imagesNames.Clear();
                    }
                }

                _imagesNames.Add(e.FullPath);
                _timer.Stop();
                _timer.Start();
            }
        }
        public async Task <IndexResult> Index(string id, ClassificationModel existing)
        {
            var zipFile = await NgaDataAccess.GetHighResImageZipFile(id);

            if (zipFile == null)
            {
                return(null);
            }
            byte[] imageBytes;
            using (MemoryStream zipFileStream = new MemoryStream(zipFile))
                using (ZipArchive archive = new ZipArchive(zipFileStream))
                {
                    ZipArchiveEntry imgArchive = archive.Entries
                                                 .Single(x => ImageExtensions.Any(
                                                             imgExt => x.FullName.EndsWith(imgExt, StringComparison.OrdinalIgnoreCase)));
                    using (var memoryStream = new MemoryStream())
                        using (var imgStream = imgArchive.Open())
                        {
                            imgStream.CopyTo(memoryStream);
                            imageBytes = memoryStream.ToArray();
                        }
                    if (!imgArchive.FullName.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase))
                    {
                        imageBytes = new IndexingHttpClient().ConvertToJpeg(imageBytes).Result;
                    }
                }
            var classification = new ClassificationModel
            {
                Source = Source,
                PageId = id
            };

            SetMetaData(classification);
            if (imageBytes == null)
            {
                return(null);
            }
            return(new IndexResult
            {
                Model = classification,
                ImageJpeg = Image.Load <Rgba64>(imageBytes)
            });
        }
예제 #3
0
 public static bool IsImage(this MediaFile file)
 {
     return(file != null && ImageExtensions.Any(s => s.Equals(file.FileExtension, StringComparison.InvariantCultureIgnoreCase)));
 }