예제 #1
0
        public static string ExtensionTypeConverter(string attributeName, Type type, object value, MatchType mt)
        {
            StringBuilder ldapFilter = new StringBuilder("(");
            string        ldapValue;

            if (typeof(bool) == type)
            {
                ldapValue = ((bool)value ? "TRUE" : "FALSE");
            }
            else if (type is ICollection)
            {
                StringBuilder collectionFilter = new StringBuilder();

                ICollection collection = (ICollection)value;

                foreach (object o in collection)
                {
                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "ExtensionTypeConverter collection filter type " + o.GetType().ToString());
                    collectionFilter.Append(ExtensionTypeConverter(attributeName, o.GetType(), o, mt));
                }
                return(collectionFilter.ToString());
            }
            else if (typeof(DateTime) == type)
            {
                ldapValue = ADUtils.DateTimeToADString((DateTime)value);
            }
            else
            {
                ldapValue = ADUtils.PAPIQueryToLdapQueryString(value.ToString());
            }

            switch (mt)
            {
            case MatchType.Equals:
                ldapFilter.Append(attributeName);
                ldapFilter.Append('=');
                ldapFilter.Append(ldapValue);
                break;

            case MatchType.NotEquals:
                ldapFilter.Append("!(");
                ldapFilter.Append(attributeName);
                ldapFilter.Append('=');
                ldapFilter.Append(ldapValue);
                ldapFilter.Append(')');
                break;

            case MatchType.GreaterThanOrEquals:
                ldapFilter.Append(attributeName);
                ldapFilter.Append(">=");
                ldapFilter.Append(ldapValue);
                break;

            case MatchType.LessThanOrEquals:
                ldapFilter.Append(attributeName);
                ldapFilter.Append("<=");
                ldapFilter.Append(ldapValue);
                break;

            case MatchType.GreaterThan:
                ldapFilter.Append('&');

                // Greater-than-or-equals (or less-than-or-equals))
                ldapFilter.Append('(');
                ldapFilter.Append(attributeName);
                ldapFilter.Append(mt == MatchType.GreaterThan ? ">=" : "<=");
                ldapFilter.Append(ldapValue);
                ldapFilter.Append(')');

                // And not-equal
                ldapFilter.Append("(!(");
                ldapFilter.Append(attributeName);
                ldapFilter.Append('=');
                ldapFilter.Append(ldapValue);
                ldapFilter.Append("))");

                // And exists (need to include because of tristate LDAP logic)
                ldapFilter.Append('(');
                ldapFilter.Append(attributeName);
                ldapFilter.Append("=*)");
                break;

            case MatchType.LessThan:
                goto case MatchType.GreaterThan;
            }

            ldapFilter.Append(')');

            return(ldapFilter.ToString());
        }
예제 #2
0
 protected static string CommaStringConverter(FilterBase filter, string suggestedAdProperty)
 {
     return(filter.Value != null ?
            $"({suggestedAdProperty}=*{ADUtils.PAPIQueryToLdapQueryString((string)filter.Value)}*)" :
            $"(!({suggestedAdProperty}=*))");
 }