// Returns: // - the list of files whose dates have changed // - a collection of feedback information for each file whose dates were changed, each row detailing the file name and how the dates were changed // - the number of missing Files, if any private List <ImageRow> GetImageRowsWithChangedDates(IProgress <ProgressBarArguments> progress, int count, TimeZoneInfo imageSetTimeZone, ObservableCollection <DateTimeFeedbackTuple> feedbackRows, out int missingFiles) { List <ImageRow> filesToAdjust = new List <ImageRow>(); missingFiles = 0; for (int fileIndex = 0; fileIndex < count; ++fileIndex) { if (Token.IsCancellationRequested) { // A cancel was requested. Clear all pending changes and abort feedbackRows.Clear(); break; } // We will store the various times here ImageRow file = this.fileDatabase.FileTable[fileIndex]; DateTimeOffset originalDateTime = file.DateTimeIncorporatingOffset; string feedbackMessage = string.Empty; try { // Get the image (if its there), get the new dates/times, and add it to the list of images to be updated // Note that if the image can't be created, we will just to the catch. bool usingMetadataTimestamp = true; if (file.FileExists(this.fileDatabase.FolderPath) == false) { // The file does not exist. Generate a feedback message missingFiles++; } else { // Read the date from the file, and check to see if its different from the recorded date DateTimeAdjustmentEnum dateTimeAdjustment = file.TryReadDateTimeOriginalFromMetadata(this.fileDatabase.FolderPath, imageSetTimeZone); if (dateTimeAdjustment == DateTimeAdjustmentEnum.MetadataNotUsed) { // We couldn't read the metadata, so get a candidate date/time from the file info instead file.SetDateTimeOffsetFromFileInfo(this.fileDatabase.FolderPath); usingMetadataTimestamp = false; } DateTimeOffset rescannedDateTime = file.DateTimeIncorporatingOffset; bool sameDate = rescannedDateTime.Date == originalDateTime.Date; bool sameTime = rescannedDateTime.TimeOfDay == originalDateTime.TimeOfDay; bool sameUTCOffset = rescannedDateTime.Offset == originalDateTime.Offset; if (!(sameDate && sameTime && sameUTCOffset)) { // Date has been updated - add it to the queue of files to be processed, and generate a feedback message. filesToAdjust.Add(file); feedbackMessage = "\x2713"; // Checkmark feedbackMessage += DateTimeHandler.ToStringDisplayDateTime(originalDateTime) + " \x2192 " + DateTimeHandler.ToStringDisplayDateTime(rescannedDateTime); feedbackMessage += usingMetadataTimestamp ? " (read from metadata)" : " (read from file)"; feedbackRows.Add(new DateTimeFeedbackTuple(file.File, feedbackMessage)); } } } catch (Exception exception) { // This shouldn't happen, but just in case. TracePrint.PrintMessage(string.Format("Unexpected exception processing '{0}' in DateTimeReread. {1}", file.File, exception.ToString())); feedbackMessage += string.Format("\x2716 skipping: {0}", exception.Message); feedbackRows.Add(new DateTimeFeedbackTuple(file.File, feedbackMessage)); break; } // Update the progress bar every time interval to indicate what file we are working on TimeSpan intervalFromLastRefresh = DateTime.Now - this.lastRefreshDateTime; if (intervalFromLastRefresh > Constant.ThrottleValues.ProgressBarRefreshInterval) { int percentDone = Convert.ToInt32(fileIndex / Convert.ToDouble(count) * 100.0); progress.Report(new ProgressBarArguments(percentDone, String.Format("Pass 1: Checking dates for {0} / {1} files", fileIndex, count), true, false)); Thread.Sleep(Constant.ThrottleValues.RenderingBackoffTime); this.lastRefreshDateTime = DateTime.Now; } } return(filesToAdjust); }