public void CreatePhoto(FileExtendedInfo finfo) { var creationDate = DateHelper.LowestDate(finfo.Creation, finfo.LastWriteDateTimeUtc); if (!DateHelper.IsValidDate(creationDate)) { creationDate = finfo.LastAccessTimeUtc; // todo try get date from filename } var photo = Photo.NewPhoto(_photoRepo.Content.NewId++, finfo.FilePath, finfo.FileKey, creationDate); if (finfo.ExifInfo != null) { if (finfo.ExifInfo.GPS_Latitude.HasValue && finfo.ExifInfo.GPS_Longitude.HasValue) { photo.Position = new GeoPosition(finfo.ExifInfo.GPS_Latitude.Value, finfo.ExifInfo.GPS_Longitude.Value); photo.Location = _locationService.GetLocation(photo.Position); } if (finfo.ExifInfo.DateTime.HasValue) { photo.ExifDate = finfo.ExifInfo.DateTime.Value; } } if (_lastPhoto == null || (_lastPhoto.Creation.DayOfYear != finfo.Creation.DayOfYear)) { //Debug.WriteLine($"New Photo Date: {finfo.Creation.ToShortDateString()} {finfo.LastWriteDateTimeUtc} "); //Debug.WriteLine($"{JsonConvert.SerializeObject(finfo)} "); } if (photo.Location == null && _lastPhoto?.Location != null && (_locationService.GetSearchPath(photo.PhotoUrl) == _locationService.GetSearchPath(_lastPhoto.PhotoUrl)) && ((photo.Creation.DayOfYear - _lastPhoto.Creation.DayOfYear) <= 3) ) { // No GPS info nut photo has same search path as previous... photo.Location = _lastPhoto.Location; } if (photo.Location == null) { photo.Location = _locationService.GetLocation(finfo.RelativePath); } _lastPhoto = photo; if (photo.IsValid && !photo.Location.Excluded) { _photoRepo.Content.Photos.Add(photo); } else { NewPhotosNotAddedToLibrary.Add(photo); } }
private DateTime GetDateForPhoto(FileExtendedInfo finfo) { var creationDate = DateHelper.LowestDate(finfo.Creation, finfo.LastWriteDateTimeUtc); if (!DateHelper.IsValidDate(creationDate)) { creationDate = DateHelper.LowestDate(finfo.LastAccessTimeUtc, finfo.LastAccessTimeUtc);; } if (finfo?.ExifInfo.DateTime != null) { creationDate = DateHelper.LowestDate(creationDate, finfo.ExifInfo.DateTime.Value); } return(creationDate); }
public FileExtendedInfo ObtainFileExtendedInfo(FileInfo fileInfo, DateTime detectedTime) { var key = GetFileKey(fileInfo); var existingInfo = _localFileRepo.GetFileInfo(key); var exifInfo = _exifReader.GetExifInformation(fileInfo.FullName); if (existingInfo != null) { return(existingInfo); } var newFInfo = new FileExtendedInfo(fileInfo, key, exifInfo, detectedTime); _localFileRepo.Add(newFInfo); return(newFInfo); }
public Photo CreatePhoto(FileExtendedInfo finfo) { var creationDate = GetDateForPhoto(finfo); var photo = Photo.NewPhoto(_photoRepo.GetNewId(), finfo.FilePath, finfo.FileKey, creationDate); GetLocationForPhoto(finfo, photo); photo.DisplayName = (photo.Location != null) ? photo.Location.GetShortDisplay() : "Unknown Place"; photo.Excluded = photo.Location == null || photo.Location.Excluded || !photo.IsValid; photo.FileInfoContent = finfo.Serialize(pretty: true); if (photo.IsValid) { _lastBuildedPhoto = photo; } return(photo); }
private void GetLocationForPhoto(FileExtendedInfo finfo, Photo photo) { if (finfo.ExifInfo != null && finfo.ExifInfo.GPS_Latitude.HasValue && finfo.ExifInfo.GPS_Longitude.HasValue) { photo.Position = new GeoPosition(finfo.ExifInfo.GPS_Latitude.Value, finfo.ExifInfo.GPS_Longitude.Value); photo.Location = _locationService.GetLocation(photo.Position); if (photo.Location != null) { photo.DebugInfo += "LocFromPos" + ";"; photo.PositionFromGps = CheckForValidGeoPosition(photo); var place = _locationService.GetNearbyPlace(photo.Position, photo.Location.Id); photo.PlaceId = place?.Id ?? 0; } } if (photo.Location == null && _lastBuildedPhoto?.Location != null && (_locationService.GetSearchPath(photo.PhotoUrl) == _locationService.GetSearchPath(_lastBuildedPhoto.PhotoUrl)) && ((photo.Creation.DayOfYear - _lastBuildedPhoto.Creation.DayOfYear) <= 3) ) { // No GPS info nut photo has same search path as previous... photo.Location = _lastBuildedPhoto.Location; photo.Position = photo.Location.Position; photo.PositionFromGps = false; photo.DebugInfo += "LocFromPhoto" + _lastBuildedPhoto.Id + ";"; } if (photo.Location == null) { photo.DebugInfo += "FromPath" + ";"; photo.Location = _locationService.GetLocation(finfo.RelativePath); if (photo.Location != null) { photo.DebugInfo += "LocFromPath" + ";"; } } }
public Location FindPhotoLocation(FileExtendedInfo finfo) { Location location = null; if (finfo.ExifInfo == null) { return(null); } if (finfo.ExifInfo.GPS_Latitude.HasValue && finfo.ExifInfo.GPS_Longitude.HasValue) { var position = new GeoPosition(finfo.ExifInfo.GPS_Latitude.Value, finfo.ExifInfo.GPS_Longitude.Value); location = _locationService.GetLocation(position); } if (location == null) { location = _locationService.GetLocation(finfo.RelativePath); } return(location); }
public void Add(FileExtendedInfo info) { FileInfos.Add(info); }