예제 #1
0
        /// <summary>
        /// Invokes named rule in a specified rulePointPath.
        /// </summary>
        /// <typeparam name="T">Return type</typeparam>
        /// <param name="rulePointPath">The path of rule point which contains the named rule.</param>
        /// <param name="ruleName">The name of the rule</param>
        /// <param name="arguments">The arguments required by this rule</param>
        /// <returns>The execution result of the named rule, or default(T) if the rule does not exist"/></returns>
        public T InvokeNamedRule <T>(string rulePointPath, string ruleName, Dictionary <string, object> arguments)
        {
            if (String.IsNullOrEmpty(rulePointPath))
            {
                throw new ArgumentNullException("rulePointPath"); // NOXLATE
            }
            if (String.IsNullOrEmpty(ruleName))
            {
                throw new ArgumentNullException("ruleName"); // NOXLATE
            }
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments"); // NOXLATE
            }

            RulePoint parentRulePoint = GetRulePoint(rulePointPath);

            if (parentRulePoint == null)
            {
                return(default(T));
            }
            NamedRule namedRule = parentRulePoint.GetNamedRule(ruleName);

            if (namedRule == null)
            {
                return(default(T));
            }
            return(InvokeRule <T>(namedRule, arguments));
        }
예제 #2
0
        /// <summary>
        /// Finds named rules which can be accepted by given rule signature
        /// </summary>
        /// <param name="signature">The rule signature</param>
        /// <returns>Named rules which can be accepted by given rule signature</returns>
        public IEnumerable <NamedRule> FindNamedRulesBySignature(RuleSignature signature)
        {
            if (signature == null)
            {
                throw new ArgumentNullException("signature");  // NOXLATE
            }
            Queue <RulePoint> workingQueue = new Queue <RulePoint>();

            workingQueue.Enqueue(RootRulePoint);
            while (workingQueue.Count > 0)
            {
                RulePoint theRulePoint = workingQueue.Dequeue();

                if (signature.IsRuleAvailable(theRulePoint))
                {
                    // The named rules of this rule point are all availabe for this signature.
                    // Also add sub-rule points into queue
                    foreach (var namedRule in theRulePoint.GetNamedRules())
                    {
                        yield return(namedRule);
                    }
                }
                // Ignore all its named rules(subrules) and add its sub-rule points
                // to the working queue.
                foreach (var rulePoint in theRulePoint.SubRulePoints)
                {
                    workingQueue.Enqueue(rulePoint);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Adds the rule signature extension to a particular rule point's signature.
        /// </summary>
        /// <param name="path">The rule point path for which the rule signature extension should be applied.</param>
        /// <param name="signatureExtension">The rule signature extension to register.</param>
        public void AddRuleSignatureExtension(string path, IRuleSignatureExtension signatureExtension)
        {
            RulePoint rulePoint = this.GetRulePoint(path);

            if (null != rulePoint)
            {
                AddRuleSignatureExtension(rulePoint, signatureExtension);
            }
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of Autodesk.IM.Rule.NamedRule class with specified owner, name and parent Rule Point.
        /// </summary>
        /// <param name="owner">The specified RuleManager object as its owner.</param>
        /// <param name="name">The specified name.</param>
        /// <param name="parent">The Rule Point object as its parent.</param>
        public NamedRule(RuleManager owner, string name, RulePoint parent)
        {
            RuleName = name;
            if (parent != null)
            {
                ParentRulePointPath = parent.Path;
            }

            Initialize(owner);
        }
예제 #5
0
        /// <summary>
        /// Adds a sub rule point.
        /// </summary>
        /// <param name="item">sub rule point to add</param>
        public void AddRulePoint(RulePoint item)
        {
            if (HasChild(item.Name))
            {
                throw new ArgumentException(String.Format(Properties.Resources.NamedRuleAlreadyExists, item.Name));
            }

            item._parent = this;
            subRulePoints.Add(item);
        }
예제 #6
0
        /// <summary>
        /// Gets a rule point by a given path.
        /// </summary>
        /// <param name="rulePointPath">The path of the rule point you want to get</param>
        /// <returns>The rule point if it exists; otherwise, null.</returns>
        public RulePoint GetRulePoint(string rulePointPath)
        {
            RulePoint iter = RootRulePoint;

            string[] pathItems = RulePathHelper.GetRulePathComponents(rulePointPath);
            foreach (string item in pathItems)
            {
                iter = iter.GetSubRulePoint(item);
                if (iter == null)
                {
                    return(null);
                }
            }
            return(iter);
        }
예제 #7
0
        /// <summary>
        /// Gets all registered rule points
        /// </summary>
        /// <returns>Rule points</returns>
        public IEnumerable <RulePoint> GetAllRulePoints()
        {
            Queue <RulePoint> workingQueue = new Queue <RulePoint>();

            workingQueue.Enqueue(RootRulePoint);
            while (workingQueue.Count > 0)
            {
                RulePoint theRulePoint = workingQueue.Dequeue();
                yield return(theRulePoint);

                foreach (var rulePoint in theRulePoint.SubRulePoints)
                {
                    workingQueue.Enqueue(rulePoint);
                }
            }
        }
예제 #8
0
        private void AddRuleSignatureExtension(RulePoint rulePoint, IRuleSignatureExtension signatureExtension)
        {
            RuleSignature signature = rulePoint.Signature;

            if (null != signature)
            {
                signature.AddExtension(signatureExtension);
            }
            foreach (RuleBase rule in rulePoint.Children)
            {
                if (rule is RulePoint)
                {
                    AddRuleSignatureExtension((rule as RulePoint), signatureExtension);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Invokes a Rule Point, run its routine with given arguments.
        /// </summary>
        /// <param name="rulePointPath">Path of Rule Point</param>
        /// <param name="arguments">Arguments required to run the Rule Point</param>
        /// <returns>Result of rule execution, or null if the rule does not exist.</returns>
        public IDictionary <string, object> InvokeRulePoint(string rulePointPath, Dictionary <string, object> arguments)
        {
            RulePoint theRulePoint = GetRulePoint(rulePointPath);

            // loop until get to the root or rule point has no signature
            // (which means cannot create rule for it and its parents)
            while (theRulePoint != null && theRulePoint.Signature != null)
            {
                if (theRulePoint.HasActivity)
                {
                    return(InvokeRule(theRulePoint, arguments));
                }
                else
                {
                    theRulePoint = theRulePoint.Parent;
                }
            }
            return(null);
        }
예제 #10
0
        /// <summary>
        /// Gets a named rule by a given path.
        /// </summary>
        /// <param name="rulePath">The path of the named rule you want to get</param>
        /// <returns>The named rule if it exists; otherwise, null.</returns>
        public NamedRule GetNamedRule(string rulePath)
        {
            if (String.IsNullOrEmpty(rulePath))
            {
                throw new ArgumentNullException("rulePath"); // NOXLATE
            }

            string rulePointPath;
            string ruleName;

            if (RulePathHelper.ExtractNamedRulePath(rulePath, out rulePointPath, out ruleName))
            {
                RulePoint theRulePoint = GetRulePoint(rulePointPath);
                if (theRulePoint != null)
                {
                    return(theRulePoint.GetNamedRule(ruleName));
                }
            }
            return(null);
        }
예제 #11
0
        /// <summary>
        /// Gets a rule point by a given path. Returns the lowest level sub rule point in
        /// the heirarchy which has a valid activity defined.
        /// </summary>
        /// <param name="rulePointPath">The path of the rule point you want to get</param>
        /// <returns>The lowest level rule point in the path that has an activity; otherwise, null.</returns>
        public RulePoint GetRulePointWithActivity(string rulePointPath)
        {
            RulePoint activityPoint = null;
            RulePoint iter          = RootRulePoint;

            string[] pathItems = RulePathHelper.GetRulePathComponents(rulePointPath);
            foreach (string item in pathItems)
            {
                iter = iter.GetSubRulePoint(item);
                if (iter == null)
                {
                    return(activityPoint);
                }
                else if (iter.HasActivity)
                {
                    activityPoint = iter;
                }
            }
            return(activityPoint);
        }
예제 #12
0
        /// <summary>
        /// Registers a new rule point with specified position.
        /// </summary>
        /// <param name="parentPath">A string representing the position where the rule point goes.</param>
        /// <param name="name">The name of rule point.</param>
        /// <param name="displayName">The display name of rule point.</param>
        /// <param name="signature">The signature of rule point.</param>
        public void RegisterRulePoint(string parentPath, string name, string displayName, RuleSignature signature)
        {
            RulePoint rulePoint = new RulePoint(this, name, signature, displayName);

            // Create rule points recursively.
            RulePoint iter = RootRulePoint;

            string[] pathItems = RulePathHelper.GetRulePathComponents(parentPath);
            foreach (string item in pathItems)
            {
                if (!iter.HasChild(item))
                {
                    iter.AddRulePoint(new RulePoint(this, item));
                }
                iter = iter.GetSubRulePoint(item);
                if (iter == null)
                {
                    throw new InvalidOperationException(Properties.Resources.CannotRegisterRulePoint);
                }
            }

            iter.AddRulePoint(rulePoint);
        }
예제 #13
0
 public void RemoveRulePointWorkflow(RulePoint rulePoint)
 {
     throw new NotImplementedException();
 }
예제 #14
0
 public void SetRulePointWorkflow(RulePoint rulePoint, System.Activities.DynamicActivity workflow)
 {
     throw new NotImplementedException();
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of Autodesk.IM.Rule.RuleManager.
 /// </summary>
 public RuleManager()
 {
     _rootRulePoint       = new RulePoint(this, String.Empty, null, String.Empty);
     this.ActivityManager = new RuleActivityManager();
 }