private string FindPhotoPathByTriggerDateTime(DateTime triggerDateTime) { var photoMaxDelay = _properietes.PhotoMaxDelay; var dateTimeRangeDelay = new DateTimeRangeDelay { Min = triggerDateTime, Max = triggerDateTime.AddMilliseconds(photoMaxDelay) }; var photoPath = TryChooseBestDateTimePhoto(dateTimeRangeDelay); return(photoPath); }
private string TryChooseBestDateTimePhoto(DateTimeRangeDelay dateTimeRangeDelay) { var pathToDirectory = _properietes.PhotoDirectoryPath; var photoPaths = GetAllPhotoNameFromDirectory(pathToDirectory); foreach (var path in photoPaths) { var name = path.Split('\\').Last(); var splittedName = name.Split('_'); var date = splittedName[0]; var time = splittedName[1]; var nameDateTime = DataTimeHelper.CreateDateTimeFromText(date, time); if (nameDateTime >= dateTimeRangeDelay.Min || nameDateTime <= dateTimeRangeDelay.Max) { return(path); } } throw new PhotoFileNotFoundException(); }