Encapsulates result of a validation. Contains a boolean IsValid and a collection of errors ErrorList.
コード例 #1
0
        internal ValidationResultChangedEventArgs(object target, ValidationResult newResult)
        {
            Guard.NotNull(newResult, nameof(newResult));

            Target = target;
            NewResult = newResult;
        }
コード例 #2
0
        public async void discover_monitor_action()
        {
            MvvmValidation.ValidationResult validationResult = Validator.Validate(() => Asset_tag);
            string message = "Please Check the following input: \n\r";

            foreach (var item in validationResult.ErrorList)
            {
                message += item.ErrorText + "\n\r";
            }
            if (validationResult.IsValid == false)
            {
                await _dialogCoordinator.ShowMessageAsync(this, "Error", message);

                return;
            }
            Monitor_list = new List <string>();
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_MonitorDetails");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    Monitor_list.Add(queryObj["Model"].ToString());
                }
            }
            catch (ManagementException e)
            {
                //  ("An error occurred while querying for WMI data: " + e.Message);
            }
        }
コード例 #3
0
		public string Format(ValidationResult validationResult)
		{
			Contract.Requires(validationResult != null);
			Contract.Ensures(Contract.Result<string>() != null);

			throw new NotImplementedException();
		}
コード例 #4
0
ファイル: LanguageViewModel.cs プロジェクト: mohaEs/SignCol
        private Action UpdateInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid)
                {
                    try
                    {
                        LanguageInfo.lang_id = lang_id;
                        LanguageInfo.Name = Name;

                        language.Update(LanguageInfo);
                        MessageBox.Show("Successful: language is updated");
                        RefreshProducts();
                        Messenger.Default.Send(AllLanguages, "InsertedService");
                        Validator.Reset();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #5
0
        public static ValidationResult Combine([NotNull] this ValidationResult firstResult, [NotNull] ValidationResult secondResult)
        {
            Contract.Requires(firstResult != null);
            Contract.Requires(secondResult != null);
            Contract.Ensures(Contract.Result<ValidationResult>() != null);

            var result = new ValidationResult();

            foreach (ValidationError error in firstResult.ErrorList)
            {
                result.AddError(error.Target, error.ErrorText);
            }

            foreach (ValidationError error in secondResult.ErrorList)
            {
                if (result.ErrorList.Contains(error))
                {
                    continue;
                }

                result.AddError(error.Target, error.ErrorText);
            }

            return result;
        }
コード例 #6
0
        public static ValidationResult Combine([NotNull] this ValidationResult firstResult,
            [NotNull] ValidationResult secondResult)
        {
            Guard.NotNull(firstResult, nameof(firstResult));
            Guard.NotNull(secondResult, nameof(secondResult));

            var result = new ValidationResult();

            foreach (ValidationError error in firstResult.ErrorList)
            {
                result.AddError(error.Target, error.ErrorText);
            }

            foreach (ValidationError error in secondResult.ErrorList)
            {
                if (result.ErrorList.Contains(error))
                {
                    continue;
                }

                result.AddError(error.Target, error.ErrorText);
            }

            return result;
        }
コード例 #7
0
        private System.Action saveInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid) //!IsValid.GetValueOrDefault(true))
                {
                    try
                    {
                        if (string.IsNullOrEmpty(Name))
                        {
                            MessageBox.Show("Please fill the fields.");
                            return;
                        }
                        else
                        {
                            //if (!string.IsNullOrEmpty(destinationFile))
                            //{
                            //    if (!Directory.Exists(mypath))
                            //    {
                            //        Directory.CreateDirectory(app.FileUrl);
                            //        File.Copy(selectedpic, destinationFile, true);
                            //    }
                            //    else
                            //    {
                            //        File.Copy(selectedpic, destinationFile, true);
                            //    }
                            //    WordsInfo.FilePath = destinationFile.Remove(0, app.FileUrl.Length);
                            //}
                            WordsInfo.WordType = wordType;//UtilityClass.ParseEnum<WordType>(SelectedWordType.ID.Value.ToString());//wordType;
                            //        WordsInfo.User_id = User_id;
                            WordsInfo.Name = Name;
                            //WordsInfo.Languages = elang;
                            WordsInfo.lang_id = SelectedLanguage.ID.Value;

                            word.Create(WordsInfo);
                            MessageBox.Show("Successful: Item is created");
                            RefreshProducts();
                            Messenger.Default.Send(AllWords, "InsertedService");
                            Validator.Reset();
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #8
0
 private void OnValidationResultChanged(object sender, ValidationResultChangedEventArgs e)
 {
     if (!_isValid.Equals(true))
     {
         MvvmValidation.ValidationResult validationResult = Validator.GetResult();
         Debug.WriteLine(" validation updated: " + validationResult);
         UpdateValidationSummary(validationResult);
     }
 }
コード例 #9
0
 private void OnValidationResultChanged(object sender, ValidationResultChangedEventArgs e)
 {
     if (!IsValid.GetValueOrDefault(true))
     {
         ValidationResult validationResult = Validator.GetResult();
         Debug.WriteLine(" validation updated: " + validationResult);
         UpdateValidationSummary(validationResult);
     }
 }
コード例 #10
0
ファイル: LanguageViewModel.cs プロジェクト: mohaEs/SignCol
        private void OnValidationResultChanged(object sender, ValidationResultChangedEventArgs e)
        {
            if (!IsValid.GetValueOrDefault(true))
            {
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();

                UpdateValidationSummary(validationResult);
            }
        }
コード例 #11
0
        private System.Action UpdateInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(Name) && SelectedLanguage.ID.HasValue && SelectedWordType.ID.HasValue)
                        {
                            MessageBox.Show("Please fill the fields.");
                            return;
                        }
                        else
                        {
                            WordsInfo.word_id = word_id;

                            WordsInfo.Name = Name;
                            WordsInfo.lang_id = SelectedLanguage.ID.Value;
                            //WordsInfo.lang_id = SelectedLanguage.ID.Value;
                            WordsInfo.WordType = UtilityClass.IntToWordType(SelectedWordType.ID.Value);
                            //         WordsInfo.User_id = User_id;


                            word.Update(WordsInfo);
                            MessageBox.Show("Successful: Item is Updated");
                            RefreshProducts();
                            Messenger.Default.Send(AllWords, "InsertedService");
                            Validator.Reset();
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #12
0
        private Action saveInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid) //!IsValid.GetValueOrDefault(true))
                {
                    try
                    {
                        if (string.IsNullOrEmpty(Name))
                        {
                            MessageBox.Show("لطفا فیلدها را پر نمایید");
                            return;
                        }
                        else
                        {
                            UserInfo.Age = Age;
                            UserInfo.Name = Name;
                            UserInfo.Phone = Phone;

                            user.Create(UserInfo);
                            MessageBox.Show("Successful: Performer is created.");
                            RefreshProducts();
                            Messenger.Default.Send(AllUser, "InsertedService");
                            Validator.Reset();
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #13
0
        /// <summary>
        /// Converts the specified validation result object to a string.
        /// </summary>
        /// <param name="validationResult">The validation result to format.</param>
        /// <returns>
        /// A string representation of <paramref name="validationResult"/>
        /// </returns>
        public string Format(ValidationResult validationResult)
        {
            if (validationResult.IsValid)
            {
                return string.Empty;
            }

            var distinctErrorMessages = validationResult.ErrorList.Select(e => e.ErrorText).Distinct().ToArray();

            if (distinctErrorMessages.Length == 1)
            {
                return distinctErrorMessages[0];
            }

            var result = new StringBuilder();
            for (int i = 1; i < distinctErrorMessages.Length + 1; i++)
            {
                result.AppendFormat(CultureInfo.InvariantCulture, "{0}. {1}", i, distinctErrorMessages[i - 1]);
                result.AppendLine();
            }

            return result.ToString().Trim();
        }
コード例 #14
0
        private Action UpdateInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid)
                {
                    try
                    {
                        //OptionInfo.option_Id = option_Id;
                        OptionInfo.FileUrl = FileUrl;

                        ops.Update(OptionInfo);
                        _uow.SaveChanges();
                        System.Windows.Forms.MessageBox.Show("Successful: Setting is updated.");
                        RefreshProducts();
                        Messenger.Default.Send(AllOptions, "InsertedService");


                        Validator.Reset();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        System.Windows.Forms.MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #15
0
        private Action UpdateInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid)
                {
                    try
                    {
                        UserInfo.User_id = User_id;
                        UserInfo.Age = Age;
                        UserInfo.Name = Name;
                        UserInfo.Phone = Phone;

                        user.Update(UserInfo);
                        MessageBox.Show("Successful: Performer is updated.");
                        RefreshProducts();
                        Messenger.Default.Send(AllUser, "InsertedService");
                        Validator.Reset();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #16
0
        private async Task<ValidationResult> ExecuteValidationRulesAsync(IEnumerable<ValidationRule> rulesToExecute, SynchronizationContext syncContext = null)
        {
            var result = new ValidationResult();
            var failedTargets = new HashSet<object>();

            foreach (var rule in rulesToExecute.ToArray())
            {
                var isValid = await ExecuteRuleAsync(rule, failedTargets, result, syncContext).ConfigureAwait(false);

                if (!isValid)
                {
                    break;
                }
            }

            return result;
        }
コード例 #17
0
ファイル: LanguageViewModel.cs プロジェクト: mohaEs/SignCol
 private void OnValidateAllCompleted(MvvmValidation.ValidationResult validationResult)
 {
     UpdateValidationSummary(validationResult);
 }
コード例 #18
0
        private async Task<bool> ExecuteRuleAsync(ValidationRule rule, ISet<object> failedTargets, ValidationResult validationResultAccumulator, SynchronizationContext syncContext)
        {
            // Skip rule if the target is already invalid and the rule is not configured to execute anyway
            if (failedTargets.Contains(rule.Target) && !ShouldExecuteOnAlreadyInvalidTarget(rule))
            {
                // Assume that the rule is valid at this point because we are not interested in this error until
                // previous rule is fixed.
                SaveRuleValidationResultAndNotifyIfNeeded(rule, RuleResult.Valid(), syncContext);

                return true;
            }

            var ruleResult = !rule.SupportsSyncValidation
                ? await rule.EvaluateAsync().ConfigureAwait(false)
                : rule.Evaluate();

            SaveRuleValidationResultAndNotifyIfNeeded(rule, ruleResult, syncContext);

            AddErrorsFromRuleResult(validationResultAccumulator, rule, ruleResult);

            if (!ruleResult.IsValid)
            {
                failedTargets.Add(rule.Target);
            }

            return true;
        }
コード例 #19
0
        private void NotifyResultChanged(object target, ValidationResult newResult, SynchronizationContext syncContext,
            bool useSyncContext = true)
        {
            if (useSyncContext && syncContext != null)
            {
                syncContext.Post(_ => NotifyResultChanged(target, newResult, syncContext, useSyncContext: false), null);
                return;
            }

            ResultChanged?.Invoke(this, new ValidationResultChangedEventArgs(target, newResult));
        }
コード例 #20
0
        public static IAsyncValidationRule AddChildValidatableCollection([NotNull] this ValidationHelper validator,
                                                                         [NotNull] Expression <Func <IEnumerable <IValidatable> > > validatableCollectionGetter)
        {
            Contract.Requires(validator != null);
            Contract.Requires(validatableCollectionGetter != null);
            Contract.Ensures(Contract.Result <IAsyncValidationRule>() != null);

            Func <IEnumerable <IValidatable> > getter = validatableCollectionGetter.Compile();

            return(validator.AddAsyncRule(PropertyName.For(validatableCollectionGetter), () =>
            {
                IEnumerable <IValidatable> items = getter();

                if (items == null)
                {
                    return Task.Factory.StartNew(() => RuleResult.Valid());
                }

                return Task.Factory.StartNew(() =>
                {
                    var result = new RuleResult();

                    // Execute validation on all items at the same time, wait for all
                    // to fininish and combine the results.

                    var results = new List <ValidationResult>();

                    var syncEvent = new ManualResetEvent(false);

                    var itemsArray = items as IValidatable[] ?? items.ToArray();
                    int[] numerOfThreadsNotYetCompleted = { itemsArray.Length };

                    foreach (var item in itemsArray)
                    {
#if SILVERLIGHT_4
                        item.Validate(r =>
                        {
                            Exception ex = null;
#else
                        item.Validate().ContinueWith(tr =>
                        {
                            ValidationResult r = tr.Result;
                            AggregateException ex = tr.Exception;
#endif
                            lock (results)
                            {
                                // ReSharper disable ConditionIsAlwaysTrueOrFalse
                                if (ex == null && r != null)
                                // ReSharper restore ConditionIsAlwaysTrueOrFalse
                                {
                                    results.Add(r);
                                }

                                if (Interlocked.Decrement(ref numerOfThreadsNotYetCompleted[0]) == 0)
                                {
                                    syncEvent.Set();
                                }
                            }
                        });
                    }

                    if (numerOfThreadsNotYetCompleted[0] > 0)
                    {
                        // Wait for all items to finish validation
                        syncEvent.WaitOne();

                                          // Add errors from all validation results
                                          foreach (ValidationResult itemResult in results)
                        {
                            foreach (ValidationError error in itemResult.ErrorList)
                            {
                                result.AddError(error.ErrorText);
                            }
                        }
                    }

                    return result;
                });
            }));
        }
コード例 #21
0
ファイル: LocationViewModel.cs プロジェクト: amigobv/UFO
 private void UpdateValidationSummary(ValidationResult validationResult)
 {
     IsValid = validationResult.IsValid;
     ValidationErrorsString = validationResult.ToString();
 }
コード例 #22
0
        private Task<ValidationResult> ExecuteValidationRulesAsync(IEnumerable<ValidationRule> rulesToExecute, SynchronizationContext syncContext = null)
        {
            syncContext = syncContext ?? SynchronizationContext.Current;

            var resultTcs = new TaskCompletionSource<ValidationResult>();
            var result = new ValidationResult();
            var failedTargets = new HashSet<object>();
            var rulesQueue = new Queue<ValidationRule>(rulesToExecute.ToArray());

            Action executeRuleFromQueueRecursive = null;

            executeRuleFromQueueRecursive = () =>
            {
                ExecuteNextRuleFromQueueAsync(rulesQueue, failedTargets, result, syncContext).ContinueWith(t =>
                {
                    if (t.Exception != null)
                    {
                        resultTcs.TrySetException(t.Exception);
                        return;
                    }

                    if (t.IsCanceled)
                    {
                        resultTcs.TrySetCanceled();
                        return;
                    }

                    if (t.Result)
                    {
                        executeRuleFromQueueRecursive();
                        return;
                    }

                    resultTcs.TrySetResult(result);
                });
            };

            executeRuleFromQueueRecursive();

            return resultTcs.Task;
        }
コード例 #23
0
        private async Task ValidateAsync()
        {
            MvvmValidation.ValidationResult result = await Validator.ValidateAllAsync();

            UpdateValidationSummary(result);
        }
コード例 #24
0
        private static void AddErrorsFromRuleResult(ValidationResult resultToAddTo, ValidationRule validationRule,
            RuleResult ruleResult)
        {
            if (!ruleResult.IsValid)
            {
                IEnumerable<object> errorTargets = validationRule.Target.UnwrapTargets();

                foreach (object errorTarget in errorTargets)
                {
                    foreach (string ruleError in ruleResult.Errors)
                    {
                        resultToAddTo.AddError(errorTarget, ruleError);
                    }
                }
            }
        }
コード例 #25
0
ファイル: WordVideoVM.cs プロジェクト: mohaEs/SignCol
        private System.Action UpdateInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid)
                {
                    try
                    {
                        VideoInfo.video_id = video_id;
                        if (!string.IsNullOrEmpty(destinationFile))
                        {
                            if (string.IsNullOrEmpty(prevpic))
                            {
                                if (!Directory.Exists(mypath))
                                {
                                    Directory.CreateDirectory(app.FileUrl /*FilesPath + @"\Fe" + FirstExam_id.Value.ToString()*/);
                                    File.Copy(selectedpic, destinationFile, true);
                                }
                                else
                                {
                                    File.Copy(selectedpic, destinationFile, true);
                                }
                                if (videotype == 1)
                                {
                                    VideoInfo.KinnectFilePath = destinationFile.Remove(0, app.FileUrl.Length);
                                }
                                else
                                {
                                    VideoInfo.LeapFilePath = destinationFile.Remove(0, app.FileUrl.Length);
                                }
                            }
                            else
                            {
                                string n = ((destinationFile.Contains(@"\")) ? destinationFile.Substring(
                                                destinationFile.LastIndexOf(@"\") + 1) : destinationFile);
                                if (n != prevpic)
                                {
                                    System.GC.Collect();
                                    System.GC.WaitForPendingFinalizers();

                                    File.Delete(app.FileUrl + prevpic);
                                    //documents.Delete(DocumentInfo.doc_id);
                                    File.Copy(selectedpic, destinationFile, true);
                                    if (videotype == 1)
                                    {
                                        VideoInfo.KinnectFilePath = destinationFile.Remove(0, app.FileUrl.Length);
                                    }
                                    else
                                    {
                                        VideoInfo.LeapFilePath = destinationFile.Remove(0, app.FileUrl.Length);
                                    }
                                }
                            }
                        }

                        if (euser == null)
                        {
                            MessageBox.Show("Please fill the fields.");
                            return;
                        }
                        else
                        {
                            //VideoInfo.User = euser;
                            VideoInfo.User_id = User_id;
                            VideoInfo.LeapKinnectType = leapkinnecttype;

                            VideoInfo.word_id = eword.word_id;

                            //VideoInfo.VideoType = VideoType;
                            video.UpdateVideo(VideoInfo);
                            MessageBox.Show("Successful: Video is updated.");
                            RefreshProducts();
                            Messenger.Default.Send(AllVideos, "InsertedService");
                            Validator.Reset();
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #26
0
ファイル: WordVideoVM.cs プロジェクト: mohaEs/SignCol
        private System.Action saveInfo()
        {
            return(() =>
            {
                Validate();
                MvvmValidation.ValidationResult validationResult = Validator.GetResult();
                if (validationResult.IsValid) //!IsValid.GetValueOrDefault(true))
                {
                    try
                    {
                        if (string.IsNullOrEmpty(destinationFile))
                        {
                            MessageBox.Show("لطفا فیلدها را پر نمایید");
                            return;
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(destinationFile))
                            {
                                if (!Directory.Exists(mypath))
                                {
                                    Directory.CreateDirectory(app.FileUrl);
                                    File.Copy(selectedpic, destinationFile, true);
                                }
                                else
                                {
                                    File.Copy(selectedpic, destinationFile, true);
                                }
                                if (videotype == 1)
                                {
                                    VideoInfo.KinnectFilePath = destinationFile.Remove(0, app.FileUrl.Length);
                                }
                                else
                                {
                                    VideoInfo.LeapFilePath = destinationFile.Remove(0, app.FileUrl.Length);
                                }
                            }
                            VideoInfo.User_id = User_id;
                            //VideoInfo.word_id = eword.word_id;
                            VideoInfo.LeapKinnectType = leapkinnecttype;

                            VideoInfo.word_id = eword.word_id;

                            video.Create(VideoInfo);
                            MessageBox.Show("Successful: Video is created.");
                            RefreshProducts();
                            Messenger.Default.Send(AllVideos, "InsertedService");
                            Validator.Reset();
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (var sdc in ex.EntityValidationErrors)
                        {
                            foreach (var ssd in sdc.ValidationErrors)
                            {
                                sb.Append(ssd.ErrorMessage);
                            }
                        }
                        MessageBox.Show(sb.ToString());
                    }
                }
            });
        }
コード例 #27
0
        private ValidationResult ExecuteValidationRules(IEnumerable<ValidationRule> rulesToExecute, SynchronizationContext syncContext = null)
        {
            var result = new ValidationResult();

            var failedTargets = new HashSet<object>();

            foreach (ValidationRule validationRule in rulesToExecute)
            {
                // Skip rule if the target is already invalid
                if (failedTargets.Contains(validationRule.Target))
                {
                    // Assume that the rule is valid at this point because we are not interested in this error until
                    // previous rule is fixed.
                    SaveRuleValidationResultAndNotifyIfNeeded(validationRule, RuleResult.Valid(), syncContext);

                    continue;
                }

                RuleResult ruleResult = ExecuteRuleCore(validationRule);

                SaveRuleValidationResultAndNotifyIfNeeded(validationRule, ruleResult, syncContext);

                AddErrorsFromRuleResult(result, validationRule, ruleResult);

                if (!ruleResult.IsValid)
                {
                    failedTargets.Add(validationRule.Target);
                }
            }

            return result;
        }
コード例 #28
0
ファイル: LanguageViewModel.cs プロジェクト: mohaEs/SignCol
 private void UpdateValidationSummary(MvvmValidation.ValidationResult validationResult)
 {
     IsValid = validationResult.IsValid;
     ValidationErrorsString = validationResult.ToString();
 }
コード例 #29
0
 private void OnValidateAllCompleted(ValidationResult validationResult)
 {
     UpdateValidationSummary(validationResult);
 }
コード例 #30
0
        private Task<bool> ExecuteNextRuleFromQueueAsync(Queue<ValidationRule> rulesQueue, ISet<object> failedTargets, ValidationResult validationResultAccumulator, SynchronizationContext syncContext)
        {
            if (rulesQueue.Count == 0)
            {
                return TaskEx.FromResult(false);
            }

            var rule = rulesQueue.Dequeue();

            // Skip rule if the target is already invalid
            if (failedTargets.Contains(rule.Target))
            {
                // Assume that the rule is valid at this point because we are not interested in this error until
                // previous rule is fixed.
                SaveRuleValidationResultAndNotifyIfNeeded(rule, RuleResult.Valid(), syncContext);

                return TaskEx.FromResult(true);
            }

            return ExecuteRuleCoreAsync(rule).ContinueWith(t =>
            {
                RuleResult ruleResult = t.Result;

                SaveRuleValidationResultAndNotifyIfNeeded(rule, ruleResult, syncContext);

                AddErrorsFromRuleResult(validationResultAccumulator, rule, ruleResult);

                if (!ruleResult.IsValid)
                {
                    failedTargets.Add(rule.Target);
                }

                return true;
            });
        }
コード例 #31
0
        private void NotifyResultChanged(object target, ValidationResult newResult, SynchronizationContext syncContext, bool useSyncContext = true)
        {
            syncContext = syncContext ?? SynchronizationContext.Current;

            if (useSyncContext && syncContext != null)
            {
                syncContext.Post(_ => NotifyResultChanged(target, newResult, syncContext, useSyncContext: false), null);
                return;
            }

            var handler = ResultChanged;
            if (handler != null)
            {
                handler(this, new ValidationResultChangedEventArgs(target, newResult));
            }
        }