|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Technewlogic.ObjectLounge.Framework.Proxy;
using Technewlogic.ObjectLounge.Framework.MetaModel;
using Technewlogic.ObjectLounge.Framework.BaseConcerns;
using Technewlogic.ObjectLounge.Framework.Transactions;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace Technewlogic.ObjectLounge.Framework.Validation
{
public class ValidationConcern
: ConcernBase<IValidationConcern, IUnitOfWorkConcern>, IValidated, INotifyPropertyChanged
{
internal ValidationConcern(
Type classType,
TransactionManager transactionManager)
{
_transactionManager = transactionManager;
_classType = classType;
}
private readonly TransactionManager _transactionManager;
private readonly Type _classType;
private readonly List<Rule> _rules = new List<Rule>();
private readonly ObservableCollection<BrokenRule> _brokenRules = new ObservableCollection<BrokenRule>();
#region IValidated Member
public IEnumerable<BrokenRule> BrokenRules
{
get { return _brokenRules; }
}
public bool IsValid
{
get { return _brokenRules.Count == 0; }
}
#endregion
// wird vom Proxy aufgerufen
internal void RegisterValidationMethod(
string validationMethodName,
Func<ValidationResult> validationMethod)
{
var ruleID = _classType.Name + "." + validationMethodName;
//var rule = Rule.TriggersAlways(ruleID, validationMethod);
var rule = new Rule(ruleID, validationMethod);
_rules.Add(rule);
}
private void TriggerRules(string propertyName) // Parameter for further use
{
TriggerRules();
}
internal void TriggerRules()
{
_brokenRules.Clear();
var brokenRules = _transactionManager
.ValidationTransactionService.Trigger(this.Parent, _rules);
foreach (var it2 in brokenRules)
_brokenRules.Add(it2);
OnPropertyChanged("IsValid");
}
internal void OnPropertyChanging(string propertyName, object newValue, object oldVvalue)
{
// nothing
}
internal void OnPropertyChanged(string propertyName, object newValue, object oldVvalue)
{
// IMP: Transaction Lock
TriggerRules(propertyName);
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.