Exemple #1
0
        public ProjectViewModel(string name, string path, [NotNull] ICommandDispatcher commandDispatcher)
        {
            Guard.NotNull(commandDispatcher, nameof(commandDispatcher));
            Guard.NotNullOrWhiteSpace(name, nameof(name));
            Guard.NotNullOrWhiteSpace(path, nameof(path));

            Name = name;
            Path = path;

            Progress = new ProgressViewModel();

            FixCsProjectFiles = new CapturingExceptionAsyncCommand(
                async _ => await commandDispatcher.ExecuteAsync(
                    new UpdateProjectFilesCommand(Path),
                    new Progress <ProgressData>(data => (Progress as ProgressViewModel)?.Update(data))),
                _ => TaskRunning == false);

            RemoveNewAppConfig = new CapturingExceptionAsyncCommand(
                async _ => await commandDispatcher.ExecuteAsync(
                    new CleanAppConfigCommand(Path),
                    new Progress <ProgressData>(data => (Progress as ProgressViewModel)?.Update(data))),
                _ => TaskRunning == false);

            commandWatch = new ExecutingAsyncCommandsComposition();
            commandWatch.WatchCommand(FixCsProjectFiles);
            commandWatch.WatchCommand(RemoveNewAppConfig);
            commandWatch.RegisterAction(value => TaskRunning = value);
        }
        public MainWindowViewModel(
            [NotNull] IStatusViewModel statusViewModel,
            [NotNull] IProjectCollectionViewModel projectCollectionViewModel,
            [NotNull] IConfigurationService configurationService,
            [NotNull] IModelEditor showInDialog)
        {
            Guard.NotNull(configurationService, nameof(configurationService));
            Guard.NotNull(showInDialog, nameof(showInDialog));
            Guard.NotNull(projectCollectionViewModel, nameof(projectCollectionViewModel));
            Guard.NotNull(statusViewModel, nameof(statusViewModel));

            ProjectCollection = projectCollectionViewModel;
            StatusViewModel   = statusViewModel;

            WorkingDirectory = string.Empty;
            Logger.Info("ctor");

            OpenSettings = new OpenSettingsCommand(showInDialog, configurationService, WorkingDirectory);
            Initialize   = new CapturingExceptionAsyncCommand(async() =>
            {
                await Task.WhenAll(
                    ProjectCollection.Initialize.ExecuteAsync(null),
                    StatusViewModel.Initialize.ExecuteAsync(null))
                .ConfigureAwait(false);
            });
        }
Exemple #3
0
        public void WatchCommand(CapturingExceptionAsyncCommand command)
        {
            if (command == null)
            {
                return;
            }

            commands.Add(command);
            command.PropertyChanged += CommandOnPropertyChanged;
        }
Exemple #4
0
        public StatusViewModel(
            [NotNull] IUserInterfaceSynchronizationContextProvider uiContextProvider,
            [NotNull] IStatusReadModel statusModel)
        {
            Guard.NotNull(uiContextProvider, nameof(uiContextProvider));
            Guard.NotNull(statusModel, nameof(statusModel));

            this.uiContextProvider = uiContextProvider;
            this.statusModel       = statusModel;
            observableModel        = new CompositeDisposable(1);
            registered             = false;
            Initialize             = new CapturingExceptionAsyncCommand(_ =>
            {
                Register();
                return(Task.CompletedTask);
            });
        }
Exemple #5
0
        public CompareHashViewModel(
            IImageHashSimilarityCalculator calculator,
            FileHashViewModel fileA,
            FileHashViewModel fileB)
        {
            if (calculator == null)
            {
                throw new ArgumentNullException(nameof(calculator));
            }

            this.fileA = fileA ?? throw new ArgumentNullException(nameof(fileA));
            this.fileB = fileB ?? throw new ArgumentNullException(nameof(fileB));

            CalculateCommand = new CapturingExceptionAsyncCommand(
                async() =>
            {
                Busy = true;

                try
                {
                    var a1      = fileA.AverageHash;
                    var a2      = fileB.AverageHash;
                    AverageHash = await Task.Run(() => calculator.Calculate(a1, a2));

                    var d1         = fileA.DifferenceHash;
                    var d2         = fileB.DifferenceHash;
                    DifferenceHash = await Task.Run(() => calculator.Calculate(d1, d2));

                    var p1         = fileA.PerceptualHash;
                    var p2         = fileB.PerceptualHash;
                    PerceptualHash = await Task.Run(() => calculator.Calculate(p1, p2));
                }
                finally
                {
                    Busy = false;
                }
            },
                () => fileA.Loaded && fileB.Loaded && !Busy);

            PropertyChanged       += OnPropertyChanged;
            fileA.PropertyChanged += OnPropertyChanged;
            fileB.PropertyChanged += OnPropertyChanged;
        }
        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();
            };
        }
Exemple #7
0
        public ProjectCollectionViewModel(
            [NotNull] IProjectViewModelFactory projectViewModelFactory,
            [NotNull] IStatusFullModel statusModel,
            [NotNull] IFileSearch fileSearch,
            [NotNull] IConfigurationService configurationService,
            [NotNull] IDelayService delayService)
        {
            Guard.NotNull(statusModel, nameof(statusModel));
            Guard.NotNull(projectViewModelFactory, nameof(projectViewModelFactory));
            Guard.NotNull(fileSearch, nameof(fileSearch));
            Guard.NotNull(configurationService, nameof(configurationService));
            Guard.NotNull(delayService, nameof(delayService));

            this.statusModel             = statusModel;
            this.projectViewModelFactory = projectViewModelFactory;
            this.fileSearch           = fileSearch;
            this.configurationService = configurationService;
            this.delayService         = delayService;

            Projects   = new ObservableCollection <ProjectViewModel>();
            Initialize = new CapturingExceptionAsyncCommand(async _ => await LoadProjectsAsync());
        }
Exemple #8
0
        public ApplicationSettingsViewModel([NotNull] IQueryProcessor queryProcessor, [NotNull] IDelayService delayService)
        {
            Guard.NotNull(queryProcessor, nameof(queryProcessor));
            Guard.NotNull(delayService, nameof(delayService));

            SearchProviderNames       = new ObservableCollection <string>();
            getSearchProvidersCommand = new CapturingExceptionAsyncCommand(async() =>
            {
                if (entity?.DelayExecution.Enabled ?? true)
                {
                    await delayService.DelayAsync();
                }

                var result = await queryProcessor.ExecuteQueryAsync(GetAllSearchProvidersQuery.Instance);

                var tmp = SearchProviderName;

                SearchProviderNames.Clear();

                foreach (var item in result.OrderBy(x => x.Priority))
                {
                    SearchProviderNames.Add(item.Name);
                }

                if (SearchProviderNames.Contains(tmp))
                {
                    SearchProviderName = tmp;
                    return;
                }

                SearchProviderName = result
                                     .OrderBy(x => x.Priority)
                                     .FirstOrDefault()
                                     ?.Name;
            });

            VersionControlProviderNames       = new ObservableCollection <string>();
            getVersionControlProvidersCommand = new CapturingExceptionAsyncCommand(async() =>
            {
                if (entity?.DelayExecution.Enabled ?? true)
                {
                    await delayService.DelayAsync();
                }

                var result = await queryProcessor.ExecuteQueryAsync(GetAllVersionControlProvidersQuery.Instance);

                var tmp = VersionControlProviderName;
                VersionControlProviderNames.Clear();

                foreach (var item in result.OrderBy(x => x.Priority))
                {
                    VersionControlProviderNames.Add(item.Name);
                }

                if (VersionControlProviderNames.Contains(tmp))
                {
                    VersionControlProviderName = tmp;
                    return;
                }

                VersionControlProviderName = result
                                             .OrderBy(x => x.Priority)
                                             .FirstOrDefault()
                                             ?.Name;
            });
        }