Пример #1
0
        public DetectViewModel(IFaceServiceClient client, IDialogService dialogService)
        {
            var fileSelector  = new ObservableFileSelector();
            var imageSelector = new ImageSelector(fileSelector.SelectFilesCommand);

            detector = new Detector(client);


            SelectFilesCommand = fileSelector.SelectFilesCommand;

            var selectFilesObs = SelectFilesCommand.Publish();

            DetectCommand = ReactiveCommand.CreateFromTask(DetectFaces, imageSelector.Images.Any());

            imagesHelper = imageSelector.Images
                           .Select(list => list.Select(data => new DetectionViewModel(data.Image, data.Source)).ToList())
                           .ToProperty(this, model => model.Images);

            DetectCommand.Subscribe(detections => SetDetections(detections));
            DetectCommand.ThrownExceptions.Subscribe(async exception => await dialogService.ShowException(exception));

            loadingHelper = DetectCommand.IsExecuting.ToProperty(this, model => model.IsBusy);

            selectFilesObs.Connect();
        }
Пример #2
0
        public RegisterViewModel(IFaceServiceClient client, IDialogService dialogService, string group)
        {
            this.client = client;
            this.group  = group;
            var fileSelector = new ObservableFileSelector();

            SelectImagesCommand = fileSelector.SelectFilesCommand;
            var imageSelector = new ImageSelector(fileSelector.SelectFilesCommand);

            imagesHelper = imageSelector.Images.ToProperty(this, r => r.Images);

            LoadPeopleCommand = ReactiveCommand.CreateFromTask(LoadPeople);
            LoadPeopleCommand.HandleErrors(dialogService);
            var canRegister = this
                              .WhenAnyValue(x => x.Name, x => x.Images, (name, images) => new { name, images })
                              .Select(x => !string.IsNullOrEmpty(x.name) && x.images != null && x.images.Any());

            RegisterPersonCommand = ReactiveCommand.CreateFromTask(RegisterPerson, canRegister);
            RegisterPersonCommand.HandleErrors(dialogService);

            peopleHelper = LoadPeopleCommand.Select(people => people.Select(person => new PersonViewModel(person, client, group, dialogService)).ToList()).ToProperty(this, r => r.People);

            busyObs = Observable
                      .Merge(new [] { RegisterPersonCommand.IsExecuting, LoadPeopleCommand.IsExecuting })
                      .ToProperty(this, model => model.IsBusy);

            MessageBus.Current.Listen <PersonDeletedMessage>()
            .Select(x => Unit.Default)
            .InvokeCommand(this, model => model.LoadPeopleCommand);

            RegisterPersonCommand
            .Select(x => Unit.Default)
            .InvokeCommand(LoadPeopleCommand);
        }
Пример #3
0
        public IdentifyViewModel(IFaceServiceClient client, IDialogService dialogService)
        {
            this.client = client;
            var fileSelector  = new ObservableFileSelector();
            var imageSelector = new ImageSelector(fileSelector.SelectFilesCommand);

            detector = new Detector(client);

            SelectFilesCommand = fileSelector.SelectFilesCommand;

            var filesObs = SelectFilesCommand.Publish();

            IdentifyCommand = ReactiveCommand.CreateFromTask(IdentifyFaces, imageSelector.Images.Any());

            imagesObs = imageSelector.Images
                        .Select(list => list.Select(data => new IdentificationViewModel(data.Image, data.Source)).ToList())
                        .ToProperty(this, model => model.Identifications);

            IdentifyCommand.Subscribe(SetIdentifications);
            IdentifyCommand.ThrownExceptions.Subscribe(async exception => await dialogService.ShowException(exception));

            isBusyObs = IdentifyCommand.IsExecuting.ToProperty(this, model => model.IsBusy);

            filesObs.Connect();
        }
Пример #4
0
        public GroupViewModel(IFaceServiceClient client, IDialogService dialogService)
        {
            this.client = client;
            var fileSelector  = new ObservableFileSelector();
            var imageSelector = new ImageSelector(fileSelector.SelectFilesCommand);

            faceDetector = new Detector(client);

            SelectFilesCommand = fileSelector.SelectFilesCommand;

            var selectFilesObs = SelectFilesCommand.Publish();

            GroupCommand = ReactiveCommand.CreateFromTask(GroupImages, imageSelector.Images.Any());
            GroupCommand.ThrownExceptions.Subscribe(async exception => await dialogService.ShowException(exception));

            imagesHelper = imageSelector.Images.ToProperty(this, model => model.Images);
            groupsHelper = GroupCommand.ToProperty(this, model => model.Groups);

            loadingHelper = GroupCommand.IsExecuting.ToProperty(this, model => model.IsBusy);

            selectFilesObs.Connect();
        }