コード例 #1
0
 internal SemanticVersion(
     int major, int minor, int patch,
     IEnumerable <string> identifiers, IEnumerable <string> metadata,
     ParseMetadata parseInfo)
     : this(major, minor, patch, identifiers, metadata)
 {
     _parseInfo = parseInfo;
 }
コード例 #2
0
        /// <summary>
        /// Runs the organizer by recursively searching every directory from the given <paramref name="inputDirectory" />.
        /// </summary>
        /// <param name="inputDirectory">Path to initial directory to search for media files.</param>
        /// <param name="database">Indicates whether a database is used.</param>
        public async Task RunOrganizerAsync(string inputDirectory)
        {
            // if input directory does not exist, throw exception and end run
            inputDirectory.EnsureDirectoryExists();

            // preliminary setup
            var hashAlgorithm = _configuration.GetValue <Algorithm>("hash-algorithm");
            var checksum      = new Checksum(hashAlgorithm);

            var photoCounter = 0;

            if (!(_context is null))
            {
                await _context.Database.EnsureCreatedAsync();
            }

            _logger.LogInformation($"Begin organizing in { inputDirectory }");

            await foreach (var photo in PhotoHandler.FindPhotosAsync(inputDirectory))
            {
                using var fs = File.OpenRead(photo.FilePath);

                // Compute checksum
                photo.Checksum = checksum.ComputeChecksum(fs);

                // Reset filestream position
                fs.Position = 0;

                // Fetch metadata directories using MetadataExctractor and parse metadata to the Photo object
                var metadataDirectories = ImageMetadataReader.ReadMetadata(fs);
                ParseMetadata.Parse(photo, metadataDirectories);

                // Rename and sort photos
                _sortService.SortPhoto(photo);

                // Add photo to database context if it does not exist already
                if (!(_context is null) && !await _context.Photos.AnyAsync(p => p.Name == photo.Name))
                {
                    await _context.Photos.AddAsync(photo);
                }

                photoCounter++;
            }

            if (!(_context is null))
            {
                // Save all additions to the database
                await _context.SaveChangesAsync();
            }

            _logger.LogInformation($"End organizing. Organized { photoCounter } photos.");
        }
コード例 #3
0
        public void ParseDirectories()
        {
            // Align the data formatting for testing
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

            // SubIFD
            float fNumber          = 12;
            short iso              = 1200;
            var   apexValue        = 1;
            var   dateTimeOriginal = DateTime.Today;
            float focalLength      = 30;

            // JPEG
            var height = 32;
            var width  = 32;

            var directories = new List <Directory>
            {
                CreateSubIfdDirectory(fNumber, iso, apexValue, dateTimeOriginal, focalLength),
                CreateJpegDirectory(height, width)
            };
            var photo = new Photo("");

            ParseMetadata.Parse(photo, directories);

            // Assert JPEG metadata
            Assert.Equal(height, photo.Height);
            Assert.Equal(width, photo.Width);

            // Assert SubIFD metadata
            Assert.Equal(fNumber, photo.FNumber);
            Assert.Equal(iso, photo.Iso);
            Assert.Equal("0.5 sec", photo.ShutterSpeed); // round((1 / exp(1 * log(2))) * 10) / 10 = 0.5
            Assert.Equal(dateTimeOriginal, photo.DateTimeOriginal);
            Assert.Equal(focalLength, photo.FocalLength);
        }
コード例 #4
0
        public void ParseNullDirectories()
        {
            var photo = new Photo("");

            ParseMetadata.Parse(photo, null);
        }