コード例 #1
0
        public async Task UpdateSiteInfoAsync()
        {
            if (string.IsNullOrWhiteSpace(ApiEndpoint))
            {
                _ErrorsContainer.SetErrors(nameof(ApiEndpoint), Tx.T("errors.field is required"));
                return;
            }
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            Status = Tx.T("wiki site.validating api endpoint");
            var urlToValidate = ApiEndpoint;

            try
            {
                // Search for API endpoint URL
                var endPoint = await Site.SearchApiEndpointAsync(_SessionService.WikiClient, urlToValidate);

                if (endPoint == null)
                {
                    _ErrorsContainer.SetErrors(nameof(ApiEndpoint), Tx.T("errors.invalid api endpoint"));
                    Status = Tx.T("errors.invalid api endpoint");
                    return;
                }
                Status = Tx.T("please wait");
                // Gather site information
                var site = await _SessionService.CreateSiteAsync(endPoint);

                SiteName = site.SiteInfo.SiteName;
                UserName = site.UserInfo.Name;
                // Clear validation errors
                _ErrorsContainer.ClearErrors(null);
                _ErrorsContainer.ClearErrors(nameof(ApiEndpoint));
                Status = null;
                if (urlToValidate == ApiEndpoint)
                {
                    SetValidatedApiEndpoint(endPoint);
                    _NeedValidateApiEndpoint = false;
                }
            }
            catch (Exception ex)
            {
                Status = Utility.GetExceptionMessage(ex);
                _ErrorsContainer.SetErrors(null, ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #2
0
        public void ValidateObject()
        {
            ErrorsContainer.ClearErrors("");
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(this, new ValidationContext(this, null, null), validationResults);
            ErrorsContainer.SetErrors("", validationResults);
        }
コード例 #3
0
        public void WhenClearingErrorsWithNullPropertyName_ThenHasErrors()
        {
            List <string> validatedProperties = new();
            var           validation          = new ErrorsContainer <string>(pn => validatedProperties.Add(pn));

            validation.SetErrors("property1", new[] { "message" });
            validation.ClearErrors(null);
            Assert.True(validation.HasErrors);
            Assert.True(validation.GetErrors("property1").Any());
        }
コード例 #4
0
ファイル: Demo1.xaml.cs プロジェクト: DinoChan/Wpf_Focus_Demo
 protected virtual void Submit()
 {
     ErrorsContainer.ClearErrors();
     if (string.IsNullOrEmpty(Name))
     {
         ErrorsContainer.SetErrors(nameof(Name), new List <string> {
             "Please Input Username"
         });
     }
 }
コード例 #5
0
        public void WhenClearingErrorsWithNullPropertyname_ThenHasErrors()
        {
            List<string> validatedProperties = new List<string>();

            var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn));

            validation.SetErrors("property1", new[] { "message" });

            validation.ClearErrors(null);

            Assert.IsTrue(validation.HasErrors);
            Assert.IsTrue(validation.GetErrors("property1").Any());
        }
コード例 #6
0
        public void WhenClearingErrorsForPropertyWithErrors_ThenPropertyHasNoErrors()
        {
            List <string> validatedProperties = new List <string>();

            var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn));

            validation.SetErrors("property1", new[] { "message" });
            validation.SetErrors("property2", new[] { "message2" });

            validation.ClearErrors("property1");

            Assert.True(validation.HasErrors);
            Assert.False(validation.GetErrors("property1").Any());
            Assert.True(validation.GetErrors("property2").Any());
        }
コード例 #7
0
        public void WhenClearingErrorsForPropertyWithErrors_ThenPropertyHasNoErrors()
        {
            List<string> validatedProperties = new List<string>();

            var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn));

            validation.SetErrors("property1", new[] { "message" });
            validation.SetErrors("property2", new[] { "message2" });

            validation.ClearErrors("property1");

            Assert.IsTrue(validation.HasErrors);
            Assert.IsFalse(validation.GetErrors("property1").Any());
            Assert.IsTrue(validation.GetErrors("property2").Any());
        }
コード例 #8
0
        public void InsertSingleAndClear(string property)
        {
            var called    = 0;
            var container = new ErrorsContainer <int>(_ => called++);

            container.SetErrors(property, new[] { 1 });
            container.ClearErrors(property);

            called
            .Should().Be(2);

            container.HasErrors
            .Should().BeFalse();

            container.GetErrors(property)
            .Should().BeEmpty();
        }
コード例 #9
0
ファイル: ValidateableBase.cs プロジェクト: tianvan/Prism
        protected virtual void ValidateProperty(object value, [CallerMemberName] string propertyName = null)
        {
            var context = new ValidationContext(this)
            {
                MemberName = propertyName
            };
            var validationErrors = new List <ValidationResult>();

            if (!Validator.TryValidateProperty(value, context, validationErrors))
            {
                IEnumerable <string> errors = validationErrors.Select(x => x.ErrorMessage);
                _errorsContainer.SetErrors(propertyName, errors);
            }
            else
            {
                _errorsContainer.ClearErrors(propertyName);
            }
        }
コード例 #10
0
ファイル: EditWaypointViewModel.cs プロジェクト: em7/PlgToFp
        private bool ValidateLatitude(string val)
        {
            var valid = _latConverter.ValidateString(val);

            if (valid)
            {
                ErrorsContainer.ClearErrors(() => Latitude);
            }
            else
            {
                ErrorsContainer.ClearErrors(() => Latitude);
                ErrorsContainer.SetErrors(() => Latitude, new[] { new ValidationResult(false, "Please use the N23°45.6 or S2345.6 format."), });
            }

            RaiseErrorsChanged(() => Latitude);
            _saveCommand?.RaiseCanExecuteChanged();
            OnPropertyChanged(() => LatitudeErrors);
            return(valid);
        }
コード例 #11
0
        /// <summary>
        /// プロパティの値を検証します。
        /// </summary>
        /// <typeparam name="T">プロパティの型</typeparam>
        /// <param name="propertyName">プロパティ名</param>
        /// <param name="value">変更されたプロパティの値</param>
        /// <remarks>
        /// このメソッドは、属性による検証にのみ対応しています。
        /// </remarks>
        private void ValidateProperty <T>(string propertyName, T value)
        {
            var context = new ValidationContext(this)
            {
                MemberName = propertyName
            };
            var errors   = new List <ValidationResult>();
            var validate = Validator.TryValidateProperty(value, context, errors);

            if (validate)
            {
                // エラーなし
                _errorsContainer.ClearErrors(propertyName);
            }
            else
            {
                // エラーあり
                _errorsContainer.SetErrors(propertyName, errors.Select(x => x.ErrorMessage));
            }
        }
コード例 #12
0
ファイル: EditWaypointViewModel.cs プロジェクト: em7/PlgToFp
        private bool ValidateIdentifier(string val)
        {
            var valid = (!string.IsNullOrWhiteSpace(val)) &&
                        (val.Length > 1) &&
                        (val.Length < 6);

            if (valid)
            {
                ErrorsContainer.ClearErrors(() => Identifier);
            }
            else
            {
                ErrorsContainer.ClearErrors(() => Identifier);
                ErrorsContainer.SetErrors(() => Identifier, new [] { new ValidationResult(false,
                                                                                          "Identifier is mandatory. Should contain 2-5 letters and numbers.") });
            }

            RaiseErrorsChanged(() => Identifier);
            _saveCommand?.RaiseCanExecuteChanged();
            OnPropertyChanged(() => IdentifierErrors);
            return(valid);
        }
コード例 #13
0
 internal void ClearMockPropertyErrors()
 {
     _errorsContainer.ClearErrors <int>(() => MockProperty);
 }