GetValue() public static method

public static GetValue ( object obj, string prop ) : string
obj object
prop string
return string
Exemplo n.º 1
0
        public Return Process(Instance instance)
        {
            bool conditionsMet = false;

            // Set Result to Default Value (in case nothing changes)
            Return result = Default;

            foreach (Value value in Values)
            {
                conditionsMet = false;

                foreach (var trigger in value.Triggers)
                {
                    var instanceValue = instance.Values.Find(x => FindTrigger(x, trigger));
                    if (instanceValue != null)
                    {
                        conditionsMet = trigger.Process(instanceValue);
                    }

                    // if any triggers are not met then break
                    if (!conditionsMet)
                    {
                        break;
                    }
                }

                if (conditionsMet || value.Triggers.Count == 0)
                {
                    foreach (MultiTrigger multiTrigger in value.MultiTriggers)
                    {
                        foreach (Trigger trigger in multiTrigger.Triggers)
                        {
                            var instanceValue = instance.Values.Find(x => FindTrigger(x, trigger));
                            if (instanceValue != null)
                            {
                                conditionsMet = trigger.Process(instanceValue);
                            }

                            // if any trigger is met then break (only one has to be met)
                            if (conditionsMet)
                            {
                                break;
                            }
                        }

                        // if none of the triggers were met then break (at least one has to be met)
                        if (!conditionsMet)
                        {
                            break;
                        }
                    }
                }

                if (conditionsMet)
                {
                    result = value.Result;

                    // Break from loop since it shouldn't be able to meet any more Value's conditions
                    break;
                }
            }

            // Get CaptureItems
            foreach (var captureItem in CaptureItems)
            {
                captureItem.PreviousValue = captureItem.Value;

                var instanceValue = instance.Values.ToList().Find(x => Tools.GetValue(x, "Id") == Tools.GetValue(captureItem, "Link"));
                if (instanceValue != null)
                {
                    if (instanceValue.Value != captureItem.Value)
                    {
                        captureItem.Value = instanceValue.Value;
                    }

                    captureItem.Sequence = instanceValue.ChangedSequence;
                }
                else
                {
                    captureItem.Value = "";
                }

                result.CaptureItems = CaptureItems.ToList();
            }

            return(result);
        }
Exemplo n.º 2
0
        public bool Process(Instance.DataItemValue instanceValue)
        {
            if (Modifier == TriggerModifier.NOT)
            {
                if (Tools.GetValue(instanceValue, "Value") != Tools.GetValue(this, "Value"))
                {
                    return(true);
                }
            }
            else if (Modifier == TriggerModifier.GREATER_THAN)
            {
                double trigger_val = double.MinValue;
                double val         = double.MinValue;
                if (double.TryParse(instanceValue.Value, out val) && double.TryParse(Value, out trigger_val))
                {
                    if (val > trigger_val)
                    {
                        return(true);
                    }
                }
            }
            else if (Modifier == TriggerModifier.LESS_THAN)
            {
                double trigger_val = double.MinValue;
                double val         = double.MinValue;
                if (double.TryParse(instanceValue.Value, out val) && double.TryParse(Value, out trigger_val))
                {
                    if (val < trigger_val)
                    {
                        return(true);
                    }
                }
            }
            else if (Modifier == TriggerModifier.CONTAINS)
            {
                if (Regex.IsMatch(instanceValue.Value, "^(?=.*" + Value + ").+$", RegexOptions.IgnoreCase))
                {
                    return(true);
                }
            }
            else if (Modifier == TriggerModifier.CONTAINS_MATCH_CASE)
            {
                if (Regex.IsMatch(instanceValue.Value, "^(?=.*" + Value + ").+$"))
                {
                    return(true);
                }
            }
            else if (Modifier == TriggerModifier.CONTAINS_WHOLE_WORD)
            {
                if (Regex.IsMatch(instanceValue.Value, Value + "\\b", RegexOptions.IgnoreCase))
                {
                    return(true);
                }
            }
            else if (Modifier == TriggerModifier.CONTAINS_WHOLE_WORD_MATCH_CASE)
            {
                if (Regex.IsMatch(instanceValue.Value, Value + "\\b"))
                {
                    return(true);
                }
            }
            else
            {
                if (Tools.GetValue(instanceValue, "Value") == Tools.GetValue(this, "Value"))
                {
                    return(true);
                }
            }

            return(false);
        }