コード例 #1
0
        public FileHashViewModel(IDemoImageHash imageHash, IFileSystem fileSystem)
        {
            if (imageHash == null)
            {
                throw new ArgumentNullException(nameof(imageHash));
            }

            this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));

            LoadCommand = new CapturingExceptionAsyncCommand(
                async() =>
            {
                try
                {
                    Busy           = true;
                    var filename   = FileName;
                    Image          = await Task.Run(() => LoadImg(filename));
                    AverageHash    = await Task.Run(() => imageHash.CalculateAverageHash(filename));
                    DifferenceHash = await Task.Run(() => imageHash.CalculateDifferenceHash(filename));
                    PerceptualHash = await Task.Run(() => imageHash.CalculatePerceptualHash(filename));
                    Loaded         = true;
                }
                finally
                {
                    Busy = false;
                }
            },
                () => !Busy && !string.IsNullOrWhiteSpace(FileName));

            ClearCommand = new CapturingExceptionAsyncCommand(
                () =>
            {
                Initialize();
                return(Task.CompletedTask);
            },
                () => !Busy);

            PropertyChanged += (sender, args) =>
            {
                LoadCommand.OnCanExecuteChanged();
                ClearCommand.OnCanExecuteChanged();
            };
        }
コード例 #2
0
        public DemoViewModel(
            IFileSystem fileSystem,
            IDemoImageHash imageHash,
            IImageHashSimilarityCalculator calculator)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            if (imageHash == null)
            {
                throw new ArgumentNullException(nameof(imageHash));
            }

            if (calculator == null)
            {
                throw new ArgumentNullException(nameof(calculator));
            }

            FileA   = new FileHashViewModel(imageHash, fileSystem);
            FileB   = new FileHashViewModel(imageHash, fileSystem);
            Compare = new CompareHashViewModel(calculator, FileA, FileB);
        }