10using System.Collections.Generic;
28 private int _errorCount;
29 private int _warnCount;
30 private int _infoCount;
32 private object _syncRoot =
new object();
48 internal void ClearRules()
54 _errorCount = _warnCount = _infoCount = 0;
65 var propertyName =
property ==
null ? null :
property.Name;
66 for (
int i = 0, n = Count; i < n; i++)
69 if (x.OriginProperty == propertyName)
81 internal void SetBrokenRules(List<RuleResult> results,
string originPropertyName)
87 ISet<string> rulesDone =
new HashSet<string>();
89 for(
int i = 0, n = results.Count; i < n; i++)
91 var result = results[i];
92 var resultRuleName = result.RuleName;
94 if(!rulesDone.Contains(resultRuleName))
96 rulesDone.Add(resultRuleName);
98 ClearRules(resultRuleName, originPropertyName);
104 var resultDescription = result.Description;
106 if(
string.IsNullOrEmpty(resultDescription))
110 var resultPrimaryProperty = result.PrimaryProperty;
112 BrokenRule broken =
new BrokenRule
114 RuleName = resultRuleName,
115 Description = resultDescription,
116 Property = resultPrimaryProperty ==
null
117 ? null : resultPrimaryProperty.Name,
118 Severity = result.Severity,
119 OriginProperty = originPropertyName
132 private void ClearRules(
string ruleName,
string originProperty)
134 for(
int i = 0, n = Count; i < n; i++)
138 if(x.RuleName == ruleName && x.OriginProperty == originProperty)
147 new void RemoveAt(
int i)
149 CountOne(
this[i].Severity, -1);
154 new void Add(BrokenRule item)
158 CountOne(item.Severity, 1);
175 throw new Exception(
"unhandled severity=" + severity);
187 get {
return _errorCount; }
198 get {
return _warnCount; }
209 get {
return _infoCount; }
266 return this.Where(c => c.Property == property.Name).FirstOrDefault();
298 return this.Where(c => c.Property == property && c.Severity == severity).FirstOrDefault();
308 return ToString(Environment.NewLine);
322 return ToString(Environment.NewLine, severity);
334 System.Text.StringBuilder result =
new System.Text.StringBuilder();
341 result.Append(separator);
344 return result.ToString();
360 System.Text.StringBuilder result =
new System.Text.StringBuilder();
369 result.Append(separator);
373 return result.ToString();
390 System.Text.StringBuilder result =
new System.Text.StringBuilder();
392 foreach (
BrokenRule item
in this.Where(r => r.Property == propertyName))
399 result.Append(separator);
403 return result.ToString();
414 return this.Select(c => c.Description).ToArray();
427 return this.Where(c => c.Severity == severity).Select(c => c.Description).ToArray();
436 foreach (var item
in list)
449 info.
AddValue(
"_errorCount", _errorCount);
450 info.
AddValue(
"_warnCount", _warnCount);
451 info.
AddValue(
"_infoCount", _infoCount);
452 base.OnGetState(info);
464 _errorCount = info.GetValue<
int>(
"_errorCount");
465 _warnCount = info.GetValue<
int>(
"_warnCount");
466 _infoCount = info.GetValue<
int>(
"_infoCount");
467 base.OnSetState(info);
bool IsReadOnly
Gets or sets a value indicating whether the list is readonly.
A strongly-typed resource class, for looking up localized strings, etc.
static string RuleMessageRequired
Looks up a localized string similar to Message for broken rule is required.
Stores details about a specific broken business rule.
string Description
Provides access to the description of the broken rule.
RuleSeverity Severity
Gets the severity of the broken rule.
A collection of currently broken rules.
int InformationCount
Gets the number of broken rules in the collection that have a severity of Information.
BrokenRule GetFirstMessage(Csla.Core.IPropertyInfo property, RuleSeverity severity)
Returns the first BrokenRule object corresponding to the specified property and severity.
BrokenRule GetFirstBrokenRule(Csla.Core.IPropertyInfo property)
Returns the first BrokenRule object corresponding to the specified property.
string[] ToArray(RuleSeverity severity)
Returns a string array containing all broken rule descriptions.
string ToString(string separator)
Returns the text of all broken rule descriptions.
int ErrorCount
Gets the number of broken rules in the collection that have a severity of Error.
override void OnSetState(SerializationInfo info)
Override this method to retrieve your field values from the MobileFormatter serialzation stream.
BrokenRule GetFirstBrokenRule(string property)
Returns the first BrokenRule object corresponding to the specified property.
string ToString(RuleSeverity severity)
Returns the text of all broken rule descriptions for a specific severity, each separated by a Environ...
void AddRange(List< BrokenRule > list)
Merges a list of items into the collection.
string ToString(string separator, RuleSeverity severity)
Returns the text of all broken rule descriptions for a specific severity.
int WarningCount
Gets the number of broken rules in the collection that have a severity of Warning.
BrokenRule GetFirstMessage(Csla.Core.IPropertyInfo property)
Returns the first BrokenRule object corresponding to the specified property.
override string ToString()
Returns the text of all broken rule descriptions, each separated by a Environment....
BrokenRule GetFirstMessage(string property, RuleSeverity severity)
Returns the first BrokenRule object corresponding to the specified property and severity.
override void OnGetState(SerializationInfo info)
Override this method to insert your field values into the MobileFormatter serialzation stream.
BrokenRulesCollection()
Creates a read-write instance of the collection.
string[] ToArray()
Returns a string array containing all broken rule descriptions.
string ToString(string separator, RuleSeverity severity, string propertyName)
Returns the text of all broken rule descriptions for a specific severity and property.
Object containing the serialization data for a specific object.
void AddValue(string name, object value)
Adds a value to the serialization stream.
Maintains metadata about a property.
RuleSeverity
Values for validation rule severities.
@ Serializable
Prevents updating or inserting until the transaction is complete.