public void addPhoto(PhotoStub photoStub) { HashSet <Tag> tagListRef = new HashSet <Tag>(); Photo photo = new Photo(photoStub, tagListRef); photoToTags.Add(photo, tagListRef); }
public List <PhotoStub> scan(string path) { if (!scanPaths.Contains(path)) { DataManagement.logger.log("Scanning a path that is not contained in the list of all sacn-paths is not possible: '" + path); } List <PhotoStub> newPhotos = new List <PhotoStub>(); IEnumerable <string> allPhotoFilePaths; try { allPhotoFilePaths = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".jpg") || s.EndsWith(".jpeg")).ToArray(); } catch (Exception e) { DataManagement.logger.log("Was not able to open folder '" + path + " || " + e.ToString()); return(null); } IEnumerable <string> newPhotoFilePaths = allPhotoFilePaths.Where(p => !scannedPhotoPaths.Contains(p)); foreach (string filePath in newPhotoFilePaths) { try { FileInfo file = new FileInfo(filePath); using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { BitmapSource img = BitmapFrame.Create(fs); BitmapMetadata md = (BitmapMetadata)img.Metadata; PhotoStub stub = new PhotoStub(filePath, DateTime.Parse(md.DateTaken)); newPhotos.Add(stub); scannedPhotoPaths.Add(filePath); } } catch (Exception e) { DataManagement.logger.log("Was not able to create photo-instance from file '" + filePath + " || " + e.ToString()); continue; } } return(newPhotos); }
public Photo(PhotoStub stub, HashSet <Tag> tagListRef) : base(stub.filePath, stub.exposureDate) { tags = tagListRef; // reference! Tags get changed in this list if changed in original list. }