Ejemplo n.º 1
0
        }                                            //Cost calculation formula defined as expression

        public Rule(RulePriority priority, string category, ExpressionString condition, ExpressionString costExpression)
        {
            this.Priority     = priority;
            this.RuleCategory = category;
            this.Condition    = condition;
            this.Cost         = costExpression;
        }
Ejemplo n.º 2
0
 public Rule(RulePriority priority, string category, ExpressionString condition, ExpressionString costExpression)
 {
     this.Priority = priority;
     this.RuleCategory = category;
     this.Condition = condition;
     this.Cost = costExpression;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialized the rule with all of the provided information set.
        /// </summary>
        /// <param name="queueName">The name of the queue.</param>
        /// <param name="value">The value that will be added to the queue.</param>
        /// <param name="priority">The priority that the rule will have.</param>
        /// <param name="isApplicable">The function that will be run to determine if the value will be added.</param>
        public Rule(string queueName, int value, RulePriority priority, Func<Dictionary<string, Queue<object>>, bool> isApplicable)
        {
            QueueName = queueName;
            Value = value;
            Priority = priority;

            IsApplicable = isApplicable;
        }
Ejemplo n.º 4
0
 public void Add(Product product, IPricingRule rule, RulePriority rulePriority = RulePriority.High)
 {
     if (_dict.TryGetValue(product.Code.Trim(), out List <IPricingRule> rls))
     {
         rls.Add(rule);
         _dict.Remove(product.Code.Trim());
         _dict.Add(product.Code.Trim(), rls);
     }
     else
     {
         _dict.Add(product.Code.Trim(), new List <IPricingRule> {
             rule
         });
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Determines the next queue that will be called,
        /// </summary>
        /// <param name="priority">The priority that will be used to determine the rules.</param>
        /// <returns>Returns null if there is a rule tie.  Returns the queue name if possible.</returns>
        private string DetermineNextQueue(RulePriority priority)
        {
            Dictionary<string, int> priorities = new Dictionary<string, int>();

            // Initialize all queues with the same priority

            foreach (KeyValuePair<string, Queue<object>> pair in Queues)
            {
                priorities.Add(pair.Key, 0);
            }

            // Run through all high priority rules first

            foreach (Rule rule in Rules[priority])
            {
                if (rule.IsApplicable(Queues))
                {
                    // Add the value of the rule to the queue

                    priorities[rule.QueueName] += rule.Value;
                }
            }

            // Get the queue with the highest priority

            string highestQueue = null;

            foreach (KeyValuePair<string, int> queue in priorities)
            {
                // Skip the queue if it is empty

                if (Queues[queue.Key].Count > 0)
                {
                    // Set the first queue

                    if (highestQueue == null)
                    {
                        highestQueue = queue.Key;
                    }
                    else
                    {
                        // Check for a tie

                        if (queue.Value == priorities[highestQueue])
                        {
                            highestQueue = null;

                            break;
                        }

                        // Check if the current queue has a higher value than the previous highest

                        if (queue.Value > priorities[highestQueue])
                        {
                            highestQueue = queue.Key;
                        }
                    }
                }
            }

            // Check for a tie

            if (highestQueue == null)
            {
                return null;
            }
            else
            {
                return highestQueue;
            }
        }
 public static string Enum_RulePriority_ToString(RulePriority v)
 {
     switch (v) {
      case RulePriority.aVerification: return "Verification";
      case RulePriority.aUpdateINTERNAL: return "UpdateINTERNAL";
      case RulePriority.aProcessing: return "Processing";
      case RulePriority.aUpdateOUT: return "UpdateOUT";
      case RulePriority.aCleanUp: return "CleanUp";
     } return "";
 }
Ejemplo n.º 7
0
 public static T WithPriority <T>(this T rule, RulePriority priority)
     where T : Rule
 {
     return(rule.WithPriority((int)priority));
 }