public void Dispose()
        {
            TestText?.Dispose();
            Keyword?.Dispose();

            IsValidKeyword?.Dispose();
            IsInvalidKeyword?.Dispose();
        }
        public NGKeywordViewModel(NGKeyword ngTitleInfo, Action <NGKeyword> onRemoveAction)
        {
            NGKeywordInfo   = ngTitleInfo;
            _OnRemoveAction = onRemoveAction;

            Label    = NGKeywordInfo.Keyword;
            TestText = new ReactiveProperty <string>(NGKeywordInfo.TestText);
            Keyword  = new ReactiveProperty <string>(NGKeywordInfo.Keyword);

            TestText.Subscribe(x =>
            {
                NGKeywordInfo.TestText = x;
            });

            Keyword.Subscribe(x =>
            {
                NGKeywordInfo.Keyword = x;
            });

            IsValidKeyword =
                Observable.CombineLatest(
                    TestText,
                    Keyword
                    )
                .Where(x => x[0].Length > 0)
                .Select(x =>
            {
                var result = -1 != TestText.Value.IndexOf(Keyword.Value);
                return(result);
            })
                .ToReactiveProperty();

            IsInvalidKeyword = IsValidKeyword.Select(x => !x)
                               .ToReactiveProperty();

            RemoveCommand = new DelegateCommand(() =>
            {
                _OnRemoveAction(this.NGKeywordInfo);
            });
        }
示例#3
0
        public VideoFilteringTitleViewModel(
            VideoTitleFilteringEntry ngTitleInfo,
            Action <VideoTitleFilteringEntry> onRemoveAction,
            VideoFilteringSettings videoFilteringRepository,
            IObservable <string> testKeyword
            )
        {
            NGKeywordInfo             = ngTitleInfo;
            _OnRemoveAction           = onRemoveAction;
            _videoFilteringRepository = videoFilteringRepository;
            Label   = NGKeywordInfo.Keyword;
            Keyword = new ReactiveProperty <string>(NGKeywordInfo.Keyword);

            Keyword.Subscribe(x =>
            {
                NGKeywordInfo.Keyword = x;
            })
            .AddTo(_disposables);

            IsValidKeyword =
                Keyword
                .Where(x => !string.IsNullOrWhiteSpace(x))
                .Select(x =>
            {
                try
                {
                    _ = new Regex(x);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            })
                .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe)
                .AddTo(_disposables);

            IsInvalidKeyword = IsValidKeyword.Select(x => !x)
                               .ToReactiveProperty()
                               .AddTo(_disposables);

            IsValidKeyword.Where(x => x).Subscribe(_ =>
            {
                _videoFilteringRepository.UpdateVideoTitleFiltering(NGKeywordInfo);
            })
            .AddTo(_disposables);

            IsTestPassed = testKeyword
                           .Where(x => !string.IsNullOrWhiteSpace(x))
                           .Where(_ => IsValidKeyword.Value)
                           .Select(x =>
            {
                return(Regex.IsMatch(Keyword.Value, x));
            })
                           .ToReadOnlyReactivePropertySlim();

            RemoveCommand = new RelayCommand(() =>
            {
                _OnRemoveAction(this.NGKeywordInfo);
            });
        }