mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 20:06:33 +00:00
Added dialog system
Added surface delete
This commit is contained in:
1 parent
c7790c1d82
commit
89bd76387b
24 files changed
+470
-96
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Stylet
|
||||
{
|
||||
public class FluentValidationAdapter<T> : IModelValidator<T>
|
||||
{
|
||||
private readonly IValidator<T> _validator;
|
||||
private T _subject;
|
||||
|
||||
public FluentValidationAdapter(IValidator<T> validator)
|
||||
{
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
public void Initialize(object subject)
|
||||
{
|
||||
_subject = (T) subject;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<string>> ValidatePropertyAsync(string propertyName)
|
||||
{
|
||||
// If someone's calling us synchronously, and ValidationAsync does not complete synchronously,
|
||||
// we'll deadlock unless we continue on another thread.
|
||||
return (await _validator.ValidateAsync(_subject, CancellationToken.None, propertyName).ConfigureAwait(false))
|
||||
.Errors.Select(x => x.ErrorMessage);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, IEnumerable<string>>> ValidateAllPropertiesAsync()
|
||||
{
|
||||
// If someone's calling us synchronously, and ValidationAsync does not complete synchronously,
|
||||
// we'll deadlock unless we continue on another thread.
|
||||
return (await _validator.ValidateAsync(_subject).ConfigureAwait(false))
|
||||
.Errors.GroupBy(x => x.PropertyName)
|
||||
.ToDictionary(x => x.Key, x => x.Select(failure => failure.ErrorMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user