public bool IsFileNameCorrect(GenericPhotoEnums.FilenameFormats fileFormat, string fileNamePrefix) { // Throw Exception if date is not read if (this.InternalPhotoMetadata == null || this.InternalPhotoMetadata.DateTaken == new DateTime()) { throw new Exception("Metadata has not been read or it is invalid"); } string fileDatePart = this.InternalPhotoMetadata.DateTaken.ToString("yyyyMMdd"); string fileSequencePart = string.Empty; // Calculate yyyymmddSequence if (fileFormat == GenericPhotoEnums.FilenameFormats.yyyymmddSequence) { // Add Prefix if one is defined // Return true of the date part is correct // TODO Should also try and validate the last part is a number if (string.IsNullOrEmpty(fileNamePrefix)) { return(this.FileName.StartsWith(fileDatePart + "_")); } else { return(this.FileName.StartsWith(fileNamePrefix + "_" + fileDatePart + "_")); } } else if (fileFormat == GenericPhotoEnums.FilenameFormats.yyyymmddHoursMinutesSeconds) { // Generate fileSequencePart based on HHMMss fileSequencePart = this.InternalPhotoMetadata.DateTaken.ToString("HHmmss"); } else if (fileFormat == GenericPhotoEnums.FilenameFormats.yyyymmddSecondsSinceMidnight) { // Generate fileSequencePart based on seconds part // Pad to 5 digits fileSequencePart = this.InternalPhotoMetadata.DateTaken.TimeOfDay.TotalSeconds.ToString().PadLeft(5, '0'); } // Check filename starts with the the correct pattern if (string.IsNullOrEmpty(fileNamePrefix)) { return(this.FileName.StartsWith(fileDatePart + "_" + fileSequencePart)); } else { return(this.FileName.StartsWith(fileNamePrefix + "_" + fileDatePart + "_" + fileSequencePart)); } }
public string RecommendedFileName(GenericPhotoEnums.FilenameFormats fileFormat, string fileNamePrefix) { // Throw Exception if date is not read if (this.InternalPhotoMetadata == null || this.InternalPhotoMetadata.DateTaken == null || this.InternalPhotoMetadata.DateTaken == new DateTime()) { throw new Exception("Metadata has not been read or it is invalid"); } string fileDatePart = this.InternalPhotoMetadata.DateTaken.ToString("yyyyMMdd"); string fileSequencePart = string.Empty; int fileIncrement = 0; // File name is blank which should fail the first Exists check string newFileName = string.Empty; // Calculate yyyymmddSequence if (fileFormat == GenericPhotoEnums.FilenameFormats.yyyymmddSequence) { // Generate fileSequencePart based on sequence, try looping until filename doesn't exist while (true) { fileIncrement++; // Add Prefix if one is defined if (string.IsNullOrEmpty(fileNamePrefix)) { newFileName = fileDatePart + "_" + fileIncrement; } else { newFileName = fileNamePrefix + "_" + fileDatePart + "_" + fileIncrement; } if (!File.Exists(this.FileFullName.Replace(this.FileName, newFileName))) { break; } } return(newFileName); } // Set the right SequencePart if (fileFormat == GenericPhotoEnums.FilenameFormats.yyyymmddHoursMinutesSeconds) { // Generate fileSequencePart based on HHMMss fileSequencePart = this.InternalPhotoMetadata.DateTaken.ToString("HHmmss"); } else if (fileFormat == GenericPhotoEnums.FilenameFormats.yyyymmddSecondsSinceMidnight) { // Generate fileSequencePart based on seconds part // Pad to 5 digits fileSequencePart = this.InternalPhotoMetadata.DateTaken.TimeOfDay.TotalSeconds.ToString().PadLeft(5, '0'); } // Generate filename and loop until no file exists with the same name while (true) { // Add Prefix if one is defined if (string.IsNullOrEmpty(fileNamePrefix)) { newFileName = fileDatePart + "_" + fileSequencePart + fileIncrement; } else { newFileName = fileNamePrefix + "_" + fileDatePart + "_" + fileSequencePart + fileIncrement; } if (!File.Exists(this.FileFullName.Replace(this.FileName, newFileName))) { break; } fileIncrement++; } return(newFileName); }
public string RecommendedFileName(GenericPhotoEnums.FilenameFormats fileFormat) { return(this.RecommendedFileName(fileFormat)); }
public bool IsFileNameCorrect(GenericPhotoEnums.FilenameFormats fileFormat) { return(this.IsFileNameCorrect(fileFormat, string.Empty)); }