Пример #1
0
 private void Prepare(T[] targets)
 {
     for (var i = 0; i < targets.Length; i++)
     {
         _Targets[i] = new DependencyTarget(this, targets[i]);
         _Index.Add(targets[i].RuleId, _Targets[i]);
     }
 }
Пример #2
0
        /// <summary>
        /// The Evaluate
        /// </summary>
        /// <param name="path">The <see cref="PropertyPath" /></param>
        /// <param name="source">The <see cref="object" /></param>
        /// <returns>The <see cref="object" /></returns>
        public static object Evaluate(PropertyPath path, object source)
        {
            var target  = new DependencyTarget();
            var binding = new System.Windows.Data.Binding {
                Path = path, Source = source, Mode = BindingMode.OneTime
            };

            BindingOperations.SetBinding(target, DependencyTarget.ValueProperty, binding);

            return(target.Value);
        }
        public static object?Evaluate(PropertyPath path, object source)
        {
            var target  = new DependencyTarget();
            var binding = new Binding()
            {
                Path = path, Source = source, Mode = BindingMode.OneTime, FallbackValue = s_fallbackValue
            };

            BindingOperations.SetBinding(target, DependencyTarget.ValueProperty, binding);

            if (target.Value == s_fallbackValue)
            {
                throw new ArgumentException($"Could not resolve property path '{path.Path}' on source object type '{source.GetType()}'.");
            }

            return(target.Value);
        }
Пример #4
0
		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
            {
            }
		}
Пример #5
0
		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;
		}
Пример #6
0
 protected override void Dispose(bool explicitDispose)
 {
     _dependencyTarget = null;
     base.Dispose(explicitDispose);
 }
Пример #7
0
 public List<TermDependency> FilterDependency(DependencyTarget target)
 {
     List<TermDependency> termdependencies = new List<TermDependency>();
     foreach (TermDependency termDependency in TermDependencies)
     {
         if (termDependency.Target == target)
             termdependencies.Add(termDependency);
     }
     return termdependencies;
 }