/// <summary> /// Check the consistency of the property template. /// Return the number of problems. /// cases: /// -key prop must exists (not null), /// -a null prop value -> a rule PropValueSetOnInstance must exists. /// </summary> /// <param name="entityTempl"></param> /// <param name="propTemplBase"></param> /// <returns></returns> private int CheckConsistencyPropTempl(EntityTempl entityTempl, PropTemplBase propTemplBase, List <PropTemplRuleBase> listRuleToExec) { int pbCount = 0; // is the property a group? PropGroupTempl propGroupTempl = propTemplBase as PropGroupTempl; if (propGroupTempl != null) { // get rules // TODO: strategie instancier child: Single, Several,... // check properties childs foreach (PropTemplBase propTemplChild in propGroupTempl.ListProperty) { pbCount += CheckConsistencyPropTempl(entityTempl, propTemplChild, listRuleToExec); } return(pbCount); } // is the property a final one? PropTempl propTempl = propTemplBase as PropTempl; if (propTempl != null) { return(CheckConsistencyPropTempl(entityTempl, propTempl, listRuleToExec)); } throw new Exception("PropTempl type not implemented!"); }
/// <summary> /// create missing rules id of the property. /// </summary> /// <param name="propTemplBase"></param> private void SetRulesId(PropTemplBase propTemplBase) { foreach (PropTemplRuleBase rule in propTemplBase.ListRule) { if (rule.Id == null) { rule.Id = Guid.NewGuid().ToString(); } } }
/// <summary> /// create missing rules id of the property. /// </summary> /// <param name="propTemplBase"></param> private void SetRulesId(PropTemplBase propTemplBase) { foreach (PropTemplRuleBase rule in propTemplBase.ListRule) { if (rule.Id == null) { rule.Id = NewObjectId(); } } }
// is the property key a textCode? private bool IsKeyMatchProperty(PropTemplBase property, string key, TextCode tcKey) { PropKeyTemplTextCode keyTextCode = property.Key as PropKeyTemplTextCode; if (keyTextCode != null) { if (tcKey != null) { // the key to find is a TextCode if (keyTextCode.TextCodeId.Equals(tcKey.Id)) { return(true); } } else { // the property key is a textCode, load it to get the code, because the key is a string TextCode tcPropKey = _reposit.Finder.FindTextCodeById(keyTextCode.TextCodeId); if (tcPropKey.Code.Equals(key)) { return(true); } } } // is the property key a string? PropKeyTemplString keyString = property.Key as PropKeyTemplString; if (keyString != null) { // compare strings if (keyString.Key.Equals(key)) { return(true); } } // the property doesn't match the key (string or TextCode) return(false); }
/// <summary> /// Create a property key, based on the template. /// </summary> /// <param name="propTempl"></param> /// <returns></returns> public PropertyKeyBase CreatePropKeyFromTempl(PropTemplBase propTempl) { // create the key of the property, from the template PropKeyTemplTextCode templKeyTextCode = propTempl.Key as PropKeyTemplTextCode; if (templKeyTextCode != null) { PropertyKeyTextCode propKey = new PropertyKeyTextCode(); propKey.TextCodeId = templKeyTextCode.TextCodeId; return(propKey); } PropKeyTemplString templKeyString = propTempl.Key as PropKeyTemplString; if (templKeyString != null) { PropertyKeyString propKey = new PropertyKeyString(); propKey.Key = templKeyString.Key; return(propKey); } throw new Exception("Property Key templ not yet implemented!"); }