private void AnalyzeFiles(object sender, DoWorkEventArgs e) { Result = new List <PhotoMetadataModel>(); foreach (var imageFile in _imageFiles) { if (Worker.CancellationPending) { e.Cancel = true; return; } var newMetadata = new PhotoMetadataModel(); newMetadata.FileName = imageFile; try { var metadata = ImageMetadataReader.ReadMetadata(imageFile); ReadGpsInformation(newMetadata, metadata); ReadSubIfInformation(newMetadata, metadata); } catch (Exception ex) { newMetadata.AnalysisErrors.Add($"Unable to read file: {ex.Message}"); } Result.Add(newMetadata); ImageFilesProcessed++; var percentCompleted = (int)(ImageFilesProcessed / ImageFileCount) * 100; Worker.ReportProgress(percentCompleted, newMetadata); } }
private static void ReadSubIfInformation(PhotoMetadataModel newMetadata, IReadOnlyList <MetadataExtractor.Directory> metadata) { try { var subIf = metadata.OfType <ExifSubIfdDirectory>().FirstOrDefault(); if (subIf != null) { DateTime photoTaken; if (subIf.TryGetDateTime(ExifDirectoryBase.TagDateTimeOriginal, out photoTaken)) { newMetadata.PhotoTaken = photoTaken; } } } catch { newMetadata.AnalysisErrors.Add("Unable to read SubIf information"); } }
private static void ReadGpsInformation(PhotoMetadataModel newMetadata, IReadOnlyList <MetadataExtractor.Directory> metadata) { try { var gps = metadata.OfType <GpsDirectory>().FirstOrDefault(); if (gps != null) { var location = gps.GetGeoLocation(); if (location != null) { newMetadata.Longitude = location.Longitude; newMetadata.Latitude = location.Latitude; } } } catch { newMetadata.AnalysisErrors.Add("Unable to read Gps information"); } }