private bool ShouldProcess(PhotoModel item) { switch (item.State) { case ProcessingStateType.Retry: if (item.RetryCount <= MaxTries) { item.State = ProcessingStateType.Pending; item.AddMessage("Retrying"); return true; } item.State = ProcessingStateType.Failed; return false; case ProcessingStateType.Completed: case ProcessingStateType.Failed: return false; case ProcessingStateType.Duplicate: return UpdateDuplicates; default: //case ProcessingStateType.Pending: //case ProcessingStateType.ReadyToUpload: //case ProcessingStateType.Uploading: //case ProcessingStateType.Uploaded: return true; } }
public static void SetDateTaken(PhotoModel item) { var path = item.LocalPath; try { item.DateTaken = GetDateTaken(path); item.HasDateTakenExifProp = true; } catch (ArgumentException) //Property cannot be found. { //Log($"Date-Taken EXIF Property (36867) for '{path}' could not be found. Using Date-Modified instead"); item.DateTaken = GetDateModified(path); item.HasDateTakenExifProp = false; } if (!item.HasDateTakenExifProp) item.AddMessage("Using date-modified of file as date-taken"); //Log($"Date-Taken EXIF Property (36867) for '{path}' could not be found. Using Date-Modified instead"); }
private bool CheckIsDuplicate(PhotoModel item) { try { var f = _mgr.Surrogate; var title = item.Title ?? item.Filename; var crcTag = BuildMachineTagExpression(CrcMachineTag, item.Crc32); var query = new PhotoSearchOptions(_mgr.AccountDetails.UserId) { Extras = PhotoSearchExtras.Tags | PhotoSearchExtras.DateTaken, MachineTagMode = MachineTagMode.AnyTag, MachineTags = // ReSharper disable once PossibleNullReferenceException BuildMachineTagExpression(FilenameMachineTag, Path.GetFileName(item.LocalPath).ToLowerInvariant()) + " " + crcTag }; var result = f.PhotosSearch(query); if (result.Count == 0) { query = new PhotoSearchOptions(_mgr.AccountDetails.UserId) { Text = title }; result = f.PhotosSearch(query); } if (!result.Any()) { return false; } var dlm = item.DateTaken; var dupItem = result.Count == 1 ? result[0] : result.FirstOrDefault( d => !d.DateTakenUnknown && dlm.HasValue && d.DateTaken.Subtract(dlm.Value).TotalSeconds < 1) ?? result.FirstOrDefault(d => d.DateTakenUnknown); if (dupItem != null) { var r = dupItem; var rCrcTag = r.Tags.FirstOrDefault(t => t.StartsWith(CrcMachineTag)); if (rCrcTag != null && crcTag.Replace("\"", "").Equals(rCrcTag, StringComparison.InvariantCultureIgnoreCase)) { item.AddMessage("Duplicate matched by CRC"); item.PhotoId = dupItem.PhotoId; return true; } if (rCrcTag == null && dupItem.Title.Equals(item.Title, StringComparison.InvariantCultureIgnoreCase)) { item.AddMessage("Duplicate matched by Title"); item.PhotoId = dupItem.PhotoId; return true; } } } catch (OperationCanceledException) { } catch (Exception ex) { throw new InvalidOperationException($"Error executing search-query. {ex.Message}", ex); } return false; }
private void Log(string msg, PhotoModel item = null) { Debug.WriteLine(msg); LogAction?.Invoke(msg); item?.AddMessage(msg); }