コード例 #1
0
ファイル: DngImageFile.cs プロジェクト: Caleb9/camera-utility
 private DngImageFile(
     CameraFilePath fullName,
     DateTime created)
     : base(fullName)
 {
     Created = created;
 }
コード例 #2
0
    private Result <ICameraFile> GetCameraFile(
        CameraFilePath cameraFilePath)
    {
        var metadataTags = _metadataReader.ExtractTags(cameraFilePath);

        return(_cameraFileFactory.Create(cameraFilePath, metadataTags));
    }
コード例 #3
0
    internal Result TransferFile(Args args)
    {
        var convertResult = _cameraFileNameConverter.Convert(args);

        if (convertResult.IsFailure)
        {
            return(convertResult);
        }

        var(destinationDirectory, destinationFileName) = convertResult.Value;
        if (!_fileSystem.Directory.Exists(destinationDirectory) && !args.DryRun)
        {
            _fileSystem.Directory.CreateDirectory(destinationDirectory);
            OnDirectoryCreated(this, destinationDirectory);
        }

        var destinationFilePath =
            new CameraFilePath(_fileSystem.Path.Combine(destinationDirectory, destinationFileName));
        var destinationAlreadyExists = _fileSystem.File.Exists(destinationFilePath);

        if (destinationAlreadyExists && !args.Overwrite)
        {
            OnFileSkipped(this, (args.CameraFilePath, destinationFilePath));
            return(Result.Success());
        }

        if (!args.DryRun)
        {
            _transferFiles(args.CameraFilePath, destinationFilePath, args.Overwrite);
        }

        OnFileTransferred(this, (args.CameraFilePath, destinationFilePath, args.DryRun));
        return(Result.Success());
    }
コード例 #4
0
ファイル: VideoFile.cs プロジェクト: Caleb9/camera-utility
 private VideoFile(
     CameraFilePath fullName,
     DateTime created)
     : base(fullName)
 {
     Created = created;
 }
コード例 #5
0
 internal void HandleException(
     CameraFilePath sourceCameraFilePath,
     Exception exception)
 {
     WriteLine(
         $"Failed {sourceCameraFilePath}: {exception.Message}",
         ConsoleColor.Red);
 }
コード例 #6
0
 internal void HandleFileSkipped(
     CameraFilePath sourcePath,
     CameraFilePath destinationPath)
 {
     WriteLine(
         $"Skipped {sourcePath} ({destinationPath} already exists)",
         ConsoleColor.Yellow);
 }
コード例 #7
0
    protected AbstractCameraFile(
        CameraFilePath fullName)
    {
        if (string.IsNullOrWhiteSpace(fullName))
        {
            throw new ArgumentException("Value cannot be null or whitespace.", nameof(fullName));
        }

        FullName  = fullName;
        Extension = fullName.GetExtension();
        if (string.IsNullOrWhiteSpace(Extension))
        {
            throw new ArgumentException($"File {fullName} has no extension", nameof(fullName));
        }
    }
コード例 #8
0
    internal Result <ICameraFile> Create(
        CameraFilePath filePath,
        IEnumerable <ITag> metadata)
    {
        switch (filePath.GetExtension().ToLowerInvariant())
        {
        case ".jpg":
        case ".jpeg":
        case ".cr2":
            return(ImageFile.Create(filePath, metadata));

        case ".dng":
            return(DngImageFile.Create(filePath, metadata));

        case ".mp4":
        case ".mov":
            return(VideoFile.Create(filePath, metadata));

        default:
            throw new InvalidPathException($"Unknown file type {filePath}");
        }
    }
コード例 #9
0
ファイル: DngImageFile.cs プロジェクト: Caleb9/camera-utility
    internal static Result <ICameraFile> Create(
        CameraFilePath fullName,
        IEnumerable <ITag> exifTags)
    {
        var dateTimeOriginal = exifTags.FirstOrDefault(t => t.Type == DateTimeOriginalTagType);

        if (dateTimeOriginal is null)
        {
            return(Result.Failure <ICameraFile>("Metadata not found"));
        }

        if (DateTime.TryParseExact(
                dateTimeOriginal.Value,
                "yyyy:MM:dd HH:mm:ss",
                CultureInfo.InvariantCulture,
                DateTimeStyles.None,
                out var parsedDateTime))
        {
            return(new DngImageFile(fullName, parsedDateTime));
        }

        return(Result.Failure <ICameraFile>("Invalid metadata"));
    }
コード例 #10
0
    public static Result <ICameraFile> Create(
        CameraFilePath fullName,
        IEnumerable <ITag> exifTags)
    {
        var enumeratedExifTags     = exifTags.ToList();
        var dateTimeOriginalResult = FindCreatedDateTimeTag(enumeratedExifTags);

        if (dateTimeOriginalResult.IsFailure)
        {
            return(Result.Failure <ICameraFile>(dateTimeOriginalResult.Error));
        }

        var parsedDateTimeResult = ParseCreatedDateTime(dateTimeOriginalResult.Value);

        if (parsedDateTimeResult.IsFailure)
        {
            return(Result.Failure <ICameraFile>(parsedDateTimeResult.Error));
        }

        return(new ImageFile(
                   fullName,
                   parsedDateTimeResult.Value.Add(FindSubSeconds(enumeratedExifTags))));
    }
コード例 #11
0
ファイル: VideoFile.cs プロジェクト: Caleb9/camera-utility
    internal static Result <ICameraFile> Create(
        CameraFilePath fullName,
        IEnumerable <ITag> exifTags)
    {
        var createdTag =
            exifTags.FirstOrDefault(t => t.Directory == "QuickTime Movie Header" && t.Type == QuickTimeCreatedTag);

        if (createdTag is null)
        {
            return(Result.Failure <ICameraFile>("Metadata not found"));
        }

        if (DateTime.TryParseExact(
                createdTag.Value,
                "ddd MMM dd HH.mm.ss yyyy",
                CultureInfo.InvariantCulture,
                DateTimeStyles.None,
                out var parsedDateTime))
        {
            return(new VideoFile(fullName, parsedDateTime));
        }

        return(Result.Failure <ICameraFile>("Invalid metadata"));
    }
コード例 #12
0
 IEnumerable <ITag> IMetadataReader.ExtractTags(CameraFilePath filePath)
 {
     return(ImageMetadataReader.ReadMetadata(filePath)
            .SelectMany(tagDirectory => tagDirectory.Tags)
            .Select(tag => new MetadataExtractorTagAdapter(tag)));
 }
コード例 #13
0
 internal void HandleFileMoved(
     CameraFilePath sourcePath,
     CameraFilePath destinationPath)
 {
     WriteLine($"{sourcePath} -> {destinationPath}");
 }