コード例 #1
0
        public string GetDefaultValue(string name, ServiceKey sk)
        {
            Attributes.TryGetValue(name, out var ad);
            if (ad != null && !string.IsNullOrEmpty(ad.DefaultValue))
            {
                try
                {
                    if (ad.Type == AttributeType.Related)
                    {
                        return(sk.GetAttributeValue(ad.DefaultValue, SearchOptions.ALL_TRUE));
                    }

                    var rule = ValueRuleParser.ParseRule(ad.DefaultValue);
                    if (rule != null && !(rule is RuleValue))
                    {
                        RuleValue value;
                        string    error;
                        var       rs = sk.ToValueHolder();
                        if (rule.TryGetValue(rs, SearchOptions.ALL_TRUE, out value, out error))
                        {
                            return(value?.ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    return("Error getting default");
                }

                if (ad.DefaultValue != null && ad.DefaultValue.StartsWith("'") && ad.DefaultValue.EndsWith("'"))
                {
                    return(ad.DefaultValue.Substring(1, ad.DefaultValue.Length - 2));
                }
                else if (ad.DefaultValue.Contains("."))
                {
                    return(sk.GetAttributeValue(ad.DefaultValue, SearchOptions.ALL_TRUE));
                }
                else
                {
                    return(ad.DefaultValue);
                }
            }
            return(null);
        }
コード例 #2
0
 public string GetRuletValue(string name, ServiceKey sk)
 {
     //See if it is a rule first...
     try
     {
         var rule = ValueRuleParser.ParseRule(name);
         if (rule != null && !(rule is RuleValue))
         {
             RuleValue value;
             string    error;
             var       rs = sk.ToValueHolder();
             if (rule.TryGetValue(rs, SearchOptions.ALL_TRUE, out value, out error))
             {
                 return(value?.ToString());
             }
         }
     }
     catch (Exception e)
     {
         return(name);
     }
     return(name);
 }