Ejemplo n.º 1
0
        public IdSelectionViewModel(IMarkerRegistrationService registrationService)
        {
            _registrationService = registrationService;

            var selectableIds = _registrationService.AvailableIds
                                .Select(id => new SelectableIdViewModel(id));

            SelectableIds = new ObservableCollection <SelectableIdViewModel>(selectableIds);

            SelectedId = SelectableIds.Select(
                selectable => selectable.SelectedCommand.Select(_ => selectable.Id)
                )
                         .Merge();
        }
        public MarkerRegistrationViewModel(
            IMarkerRegistrationService registrationService,
            IMarkerRegistrationField registrationField,
            ScaleAdapter scaleAdapter
            )
        {
            IdSelectionPanel = new IdSelectionViewModel(registrationService);

            FieldPosition = Observable.Return(registrationField.FieldPosition)
                            .ScaleToScreen(scaleAdapter)
                            .ToReactiveProperty();

            FieldSize = Observable.Return(registrationField.FieldSize)
                        .ScaleToScreen(scaleAdapter)
                        .ToReactiveProperty();

            IsCandidatePlaced = Observable.FromEvent <MarkerCandidateState>(
                h => registrationService.OnMarkerCandidateUpdated += h,
                h => registrationService.OnMarkerCandidateUpdated -= h
                )
                                .Do(value => Debug.WriteLine($"-> Candidate update = {value}"))
                                .Select(state => state == MarkerCandidateState.Detected)
                                .ToReactiveProperty();

            IsSelectingId = IsCandidatePlaced
                            .SelectMany(async isSelecting =>
            {
                if (isSelecting)
                {
                    await IdSelectionPanel.UpdateRegisteredIdsAsync();
                    return(IsCandidatePlaced.Value);
                }
                return(false);
            })
                            .ToReactiveProperty();

            _disposable = IdSelectionPanel.SelectedId
                          .Subscribe(id =>
            {
                registrationService.RegisterCandidate(id);
                IsSelectingId.Value = false;
                IsCandidatePlaced.ForceNotify();
            });
        }