示例#1
0
        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);
            }
        }
示例#2
0
        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" + ";";
                }
            }
        }