public TermDependency(Template template, XmlNode termDependencyNode) { _template = template; string dependentTerm = Utility.XMLHelper.GetAttributeString(termDependencyNode, XMLNames._A_DependentTerm); Guid dependentTermID; if (!string.IsNullOrEmpty(dependentTerm)) { dependentTermID = _template.FindTerm(dependentTerm).ID; } else { dependentTermID = Term.CreateID(termDependencyNode, XMLNames._A_DependentTermID); } string idString = Utility.XMLHelper.GetAttributeString(termDependencyNode, XMLNames._A_ID); _id = new Guid(idString); _quantifier = (DependencyQuantifier)Enum.Parse(typeof(DependencyQuantifier), Utility.XMLHelper.GetAttributeString(termDependencyNode, XMLNames._A_Quantity)); string sTarget = Utility.XMLHelper.GetAttributeString(termDependencyNode, XMLNames._A_Target); if (string.IsNullOrEmpty(sTarget)) _target = DependencyTarget.Term; else _target = (DependencyTarget)Enum.Parse(typeof(DependencyTarget), sTarget); if (_target == DependencyTarget.Term) { //Add dependent terms. If this is the 'old' structure, then the dependentTermID is defined. If not, then the DependentTerms collection is defined. _dependentTermIDs = new List<Guid>(); XmlNode nodeDependentTerms = termDependencyNode.SelectSingleNode(Utility.XMLHelper.GetXPath(false, XMLNames._E_DependentTerms)); if (nodeDependentTerms != null) { XmlNodeList nodelistDependentTerms = termDependencyNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_DependentTerms, XMLNames._E_DependentTerm)); foreach (XmlNode nodeDependentTerm in nodelistDependentTerms) { _dependentTermIDs.Add(Term.CreateID(nodeDependentTerm, XMLNames._A_ID)); } } else { if (!Term.ValidID(dependentTermID)) { throw new Exception(string.Format("Dependent term not defined for Term Dependency {0}", _id.ToString())); } else { _dependentTermIDs.Add(dependentTermID); } } } //Add Conditions XmlNodeList nodelistConditions = termDependencyNode.SelectNodes(Utility.XMLHelper.GetXPath(false, XMLNames._E_TermDependencyConditions, XMLNames._E_TermDependencyCondition)); if (nodelistConditions != null && nodelistConditions.Count > 0) { _conditions = new List<TermDependencyCondition>(nodelistConditions.Count); foreach (XmlNode nodeCondition in nodelistConditions) _conditions.Add(new TermDependencyCondition(_template, nodeCondition)); } else { _conditions = new List<TermDependencyCondition>(); } //Add Action XmlNode nodeAction = termDependencyNode.SelectSingleNode(Utility.XMLHelper.GetXPath(false, XMLNames._E_TermDependencyAction)); if (nodeAction != null) _action = new TermDependencyAction(nodeAction); else _action = new TermDependencyAction(TermDependencyActionValue.Default, TermDependencyActionValue.Default); //Is Active try { _isActive = Utility.XMLHelper.GetAttributeBool(termDependencyNode, XMLNames._A_IsActive); if (!_isActive.HasValue) _isActive = true; } catch { } }
public TermDependency(Template template, DependencyTarget target) { _id = Guid.NewGuid(); //_dependentTermID = Guid.Empty; _dependentTermIDs = new List<Guid>(); _quantifier = DependencyQuantifier.All; _target = target; _conditions = new List<TermDependencyCondition>(); _action = new TermDependencyAction(TermDependencyActionValue.Default, TermDependencyActionValue.Default); _template = template; }