protected ImageMetaData GetExifMetaData(MagickImage image) { // No need to check file format as GetExifProfile is safe operation var profile = image.GetExifProfile(); if (profile == null) { return(null); } var makeTag = profile.GetValue(ExifTag.Make); var dateOriginalTag = profile.GetValue(ExifTag.DateTimeOriginal); var originalOffsetTag = profile.GetValue(ExifTag.OffsetTimeOriginal); var originalDateTimeOffset = DateTimeOffsetUtils.TryParse(dateOriginalTag?.Value, originalOffsetTag?.Value); var imageExifData = new ImageMetaData { Make = makeTag?.Value, OriginalDateTimeOffset = originalDateTimeOffset }; return(imageExifData); }
private static async Task <IActionResult> ExecuteLaunchRequestAsync(CEKRequest request, CloudTable locationLogs, AppConfiguration config) { var response = new CEKResponse(); var taskForSettings = MessagingChatSettings.GetSettingsByUserIdAsync(locationLogs, request.Session.User.UserId); var taskForLocationLog = LocationLog.GetLocationLogByUserIdAsync(locationLogs, request.Session.User.UserId); await Task.WhenAll(taskForSettings, taskForLocationLog); var settings = taskForSettings.Result ?? new MessagingChatSettings { RowKey = request.Session.User.UserId }; var locationLog = taskForLocationLog.Result; try { if (!settings.IsLineFrend) { response.AddText(ClovaMessages.GetAddingLineFrendMessage()); return(new OkObjectResult(response)); } AddHistory(settings); response.AddText(ClovaMessages.GetGuideMessage(settings.YourName)); if (locationLog == null || !DateTimeOffsetUtils.IsToday(locationLog.Timestamp)) { // データが無い response.AddText(ClovaMessages.GetNoLogMessage(settings.YourName)); await AskCurrentLocationAsync(request, config, settings); return(new OkObjectResult(response)); } if (DateTimeOffsetUtils.IsBefore(locationLog.Timestamp, TimeSpan.Parse(config.Cek.IsBeforeThreshold ?? Clova.IsBeforeThresholdDefaultValue))) { // 古いデータ response.AddText(ClovaMessages.GetOldLocationMessage(settings.YourName, locationLog)); await AskCurrentLocationAsync(request, config, settings); return(new OkObjectResult(response)); } // データがある response.AddText(ClovaMessages.GetLocationMessage(settings.YourName, locationLog)); if (!string.IsNullOrEmpty(locationLog.Comment)) { response.AddText(ClovaMessages.GetCommentMessage(settings.YourName, locationLog)); } else if (!string.IsNullOrEmpty(locationLog.AudioCommentUrl)) { response.AddText(ClovaMessages.GetVoiceMessagePrefixMessage(settings.YourName)); response.AddUrl(locationLog.AudioCommentUrl); } return(new OkObjectResult(response)); } finally { await locationLogs.ExecuteAsync(TableOperation.InsertOrReplace(settings)); } }
public void TryParse_InvalidDateAndOffset_ReturnsNull() { // arrange var dateStr = "invalidString"; var offset = "invalidString"; // act var result = DateTimeOffsetUtils.TryParse(dateTimeStr: dateStr, offsetStr: offset); // assert Assert.Null(result); }
public void TryParse_ParseValidDateWithValidOffset_Success() { // arrange var dateStr = "2021-03-23T02:01:28"; var offsetStr = "02:00"; var expectedResult = new DateTimeOffset( year: 2021, month: 03, day: 23, hour: 2, minute: 1, second: 28, offset: new TimeSpan(hours: 2, minutes: 0, seconds: 0)); // act var result = DateTimeOffsetUtils.TryParse(dateTimeStr: dateStr, offsetStr: offsetStr); // assert Assert.Equal(expected: expectedResult, actual: result); }
public void ExtractImageMetadata_ExtractJpgMetadata_ReturnPredifinedMetadata() { // arrange var sut = new ImageMetadataProviderService(); var jpgFileStream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("FSyncCli.Tests.TestFiles.TestJpgWithMetadata.JPG"); var make = "NIKON CORPORATION"; var original = DateTimeOffsetUtils.TryParse("2021:02:24 22:27:11", "-04:00"); // act var result = sut.ExtractImageMetadata(jpgFileStream); // assert Assert.Equal(expected: make, result.Make); Assert.Equal(expected: original, result.OriginalDateTimeOffset); }
public static IList <ISendMessage> GetHistoriesMessage(IEnumerable <DateTimeOffset> histories) { if (!histories.Any()) { return(new List <ISendMessage> { new TextMessage("Clova からの確認履歴はありません。"), }); } var historiesTexts = histories.Select(x => DateTimeOffsetUtils.ToJstDateTimeOffset(x)) .Select(x => $"- {x.ToString("yyyy年MM月dd日 HH時mm分")}") .Reverse(); return(new List <ISendMessage> { new TextMessage($@"以下の時間に Clova から確認がありました。 {string.Join(Environment.NewLine, historiesTexts)}"), }); }
protected ImageMetaData GetRawFormatMetaData(MagickImage image) { var originalDateTimeStr = image.GetAttribute("exif:DateTimeDigitized") ?? image.GetAttribute("xmp:CreateDate"); var originalOffsetStr = image.GetAttribute("exif:Tag 36881") //ExifTag.OffsetTimeOriginal ?? image.GetAttribute("exif:OffsetTimeOriginal"); var make = image.GetAttribute("exif:make") ?? image.GetAttribute("tiff:make") ?? image.GetAttribute("dng:make"); var originalDateTimeOffset = DateTimeOffsetUtils.TryParse(originalDateTimeStr, originalOffsetStr); var imageExifData = new ImageMetaData { Make = make, OriginalDateTimeOffset = originalDateTimeOffset }; return(imageExifData); }
public static string GetOldLocationMessage(string name, LocationLog locationLog) => $"{name}は、きょう、{DateTimeOffsetUtils.ToJstDateTimeOffset(locationLog.Timestamp).ToString("HH時")}に、{locationLog.Name ?? locationLog.Address}にいました。今どこにいるか、もう一度 LINE で聞いてみますね。少ししたら、また、聞いてください。";