void InitializeValidation() { var nonNullRepositoryName = this.WhenAny( x => x.RepositoryName, x => x.Value) .WhereNotNull(); RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) .IfNullOrEmpty("Please enter a repository name") .IfTrue(x => x.Length > 100, "Repository name must be fewer than 100 characters"); SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) .Add(repoName => { var parsedReference = GetSafeRepositoryName(repoName); return(parsedReference != repoName ? "Will be created as " + parsedReference : null); }); this.WhenAny(x => x.SafeRepositoryNameWarningValidator.ValidationResult, x => x.Value) .WhereNotNull() // When this is instantiated, it sends a null result. .Select(result => result?.Message) .Subscribe(message => { if (!string.IsNullOrEmpty(message)) { vsServices.ShowWarning(message); } else { vsServices.ClearNotifications(); } }); }
void InitializeValidation() { var nonNullRepositoryName = this.WhenAny( x => x.RepositoryName, x => x.Value) .WhereNotNull(); RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty) .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong); SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName) .Add(repoName => { var parsedReference = GetSafeRepositoryName(repoName); return(parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null); }); this.WhenAny(x => x.SafeRepositoryNameWarningValidator.ValidationResult, x => x.Value) .WhereNotNull() // When this is instantiated, it sends a null result. .Select(result => result?.Message) .Subscribe(message => { if (!string.IsNullOrEmpty(message)) { vsServices.ShowWarning(message); } else { vsServices.ClearNotifications(); } }); }