/// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value. 
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, int value, SearchConditionOperation operation)
        {
            PropVariant propVar = new PropVariant();
            propVar.SetInt(value);

            return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Integer", operation);
        }
 /// <summary>
 /// Creates a leaf condition node that represents a comparison of property value and constant value. 
 /// </summary>
 /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
 /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
 /// <param name="value">The constant value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
 /// the properties that are indexed, look for the specific property's property description and 
 /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
 {
     using (PropVariant propVar = new PropVariant(value))
     {
         return CreateLeafCondition(propertyName, propVar, null, operation);
     }
 }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and constant value. 
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The constant value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
        {
            PropVariant propVar = new PropVariant();
            propVar.SetString(value);

            return CreateLeafCondition(propertyName, propVar, null, operation);
        }
 /// <summary>
 /// Creates a leaf condition node that represents a comparison of property value and constant value. 
 /// Overload method takes a DateTime parameter for the comparison value.
 /// </summary>
 /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
 /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
 /// <param name="value">The DateTime value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
 /// the properties that are indexed, look for the specific property's property description and 
 /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, DateTime value, SearchConditionOperation operation)
 {
     using (PropVariant propVar = new PropVariant(value))
     {
         return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.DateTime", operation);
     }
 }
示例#5
0
 public SearchConditionAttribute(string propertyName, SearchConditionOperation operation)
 {
     this.PropertyName = propertyName;
     this.Operation    = operation;
 }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value. 
        /// Overload method takes a DateTime parameter for the comparison value.
        /// </summary>
        /// <param name="propertyKey">The property to be compared.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(PropertyKey propertyKey, int value, SearchConditionOperation operation)
        {
            string canonicalName;
            PropertySystemNativeMethods.PSGetNameFromPropertyKey(ref propertyKey, out canonicalName);

            if (!string.IsNullOrEmpty(canonicalName))
                return CreateLeafCondition(canonicalName, value, operation);
            else
                throw new ArgumentException("Given property key is invalid", "propertyKey");
        }
        private static SearchCondition CreateLeafCondition(string propertyName, PropVariant propVar, string valueType, SearchConditionOperation operation)
        {
            IConditionFactory nativeConditionFactory = null;
            SearchCondition   condition = null;

            try
            {
                // Same as the native "IConditionFactory:MakeLeaf" method
                nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass();

                ICondition nativeCondition = null;

                if (string.IsNullOrEmpty(propertyName) || propertyName.ToLower() == "system.null")
                {
                    propertyName = null;
                }

                HRESULT hr = HRESULT.E_FAIL;

                hr = nativeConditionFactory.MakeLeaf(propertyName, operation, valueType,
                                                     ref propVar, null, null, null, false, out nativeCondition);

                if (!CoreErrorHelper.Succeeded((int)hr))
                {
                    Marshal.ThrowExceptionForHR((int)hr);
                }

                // Create our search condition and set the various properties.
                condition = new SearchCondition(nativeCondition);
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return(condition);
        }
示例#8
0
 /// <summary>
 /// Creates a leaf condition node that represents a comparison of property value and constant value.
 /// </summary>
 /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property.
 /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
 /// <param name="value">The constant value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
 /// the properties that are indexed, look for the specific property's property description and
 /// <see cref="P:Ssz.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, string value, SearchConditionOperation operation)
 {
     using (PropVariant propVar = new PropVariant(value))
     {
         return(CreateLeafCondition(propertyName, propVar, null, operation));
     }
 }
示例#9
0
        private static SearchCondition CreateLeafCondition(string propertyName, PropVariant propVar, string valueType, SearchConditionOperation operation)
        {
            IConditionFactory nativeConditionFactory = null;
            SearchCondition   condition = null;

            try
            {
                // Same as the native "IConditionFactory:MakeLeaf" method
                nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass();

                ICondition nativeCondition = null;

                if (string.IsNullOrEmpty(propertyName) || propertyName.ToUpperInvariant() == "SYSTEM.NULL")
                {
                    propertyName = null;
                }

                HResult hr = HResult.Fail;

                hr = nativeConditionFactory.MakeLeaf(propertyName, operation, valueType,
                                                     propVar, null, null, null, false, out nativeCondition);

                if (!CoreErrorHelper.Succeeded(hr))
                {
                    throw new ShellException(hr);
                }

                // Create our search condition and set the various properties.
                condition = new SearchCondition(nativeCondition);
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return(condition);
        }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value. 
        /// Overload method takes a DateTime parameter for the comparison value.
        /// </summary>
        /// <param name="propertyKey">The property to be compared.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(PropertyKey propertyKey, int value, SearchConditionOperation operation)
        {
            string canonicalName;
            PropertySystemNativeMethods.PSGetNameFromPropertyKey(ref propertyKey, out canonicalName);

            if (string.IsNullOrEmpty(canonicalName))
            {
                throw new ArgumentException(LocalizedMessages.SearchConditionFactoryInvalidProperty, "propertyKey");
            }
            return CreateLeafCondition(canonicalName, value, operation);
        }
        private static SearchCondition CreateLeafCondition(string propertyName, PropVariant propVar, string valueType, SearchConditionOperation operation)
        {
            IConditionFactory nativeConditionFactory = null;
            SearchCondition condition = null;

            try
            {
                // Same as the native "IConditionFactory:MakeLeaf" method
                nativeConditionFactory = (IConditionFactory)new ConditionFactoryCoClass();

                ICondition nativeCondition = null;

                if (string.IsNullOrEmpty(propertyName) || propertyName.ToUpperInvariant() == "SYSTEM.NULL")
                {
                    propertyName = null;
                }

                HResult hr = HResult.Fail;

                hr = nativeConditionFactory.MakeLeaf(propertyName, operation, valueType,
                    propVar, null, null, null, false, out nativeCondition);

                if (!CoreErrorHelper.Succeeded(hr))
                {
                    throw new ShellException(hr);
                }

                // Create our search condition and set the various properties.
                condition = new SearchCondition(nativeCondition);
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return condition;
        }
示例#12
0
        private static Expression <Func <T, bool> > GetPropertyExpression <T>(BaseSearch <T> self, PropertyInfo p, ParameterExpression parameter)
        {
            //取得SearchConditionAttribute特性
            var attr           = p.GetCustomAttribute <SearchConditionAttribute>();
            var ignoreWhenNull = attr != null ? attr.IgnoreWhenNull : true;
            var value          = p.GetValue(self);

            if (value == null && ignoreWhenNull)
            {
                return(null);
            }
            if (p.PropertyType == typeof(string) && string.IsNullOrEmpty((string)value) && ignoreWhenNull)
            {
                return(null);
            }

            //如果有CustomConditionAttribute,则跳过该条件
            if (p.GetCustomAttribute <CustomConditionAttribute>() != null)
            {
                return(null);
            }

            var name = attr != null ? (attr.PropertyName.IsNotNullOrEmpty() ? attr.PropertyName : p.Name) : p.Name;
            //根据名称取得属性
            var property = typeof(T).GetProperty(name);

            if (property == null)
            {
                return(null);
            }
            var propertyType = property.PropertyType;
            ////如果是Nullable类型,只需要取得真实类。
            //if (value != null && propertyType.IsNullableType())
            //{
            //    propertyType = propertyType.RealType();
            //}

            SearchConditionOperation operation = attr != null ? attr.Operation : SearchConditionOperation.Equal;
            Expression body = null;

            switch (operation)
            {
            case SearchConditionOperation.Equal:
                body = Expression.Equal(
                    Expression.PropertyOrField(parameter, name),
                    Expression.Constant(value, propertyType)
                    );
                break;

            case SearchConditionOperation.NotEqual:
                body = Expression.NotEqual(
                    Expression.PropertyOrField(parameter, name),
                    Expression.Constant(p.GetValue(self), propertyType)
                    );
                break;

            case SearchConditionOperation.Contains:
                body = Expression.Call(Expression.PropertyOrField(parameter, name),
                                       typeof(string).GetMethod("Contains", new[] { typeof(string) }),
                                       Expression.Constant(value, propertyType));
                break;

            case SearchConditionOperation.NotContains:
                body = Expression.Not(Expression.Call(Expression.PropertyOrField(parameter, name),
                                                      typeof(string).GetMethod("Contains", new[] { typeof(string) }),
                                                      Expression.Constant(value, propertyType)));
                break;

            default:
                return(null);
            }

            var exp = Expression.Lambda <Func <T, bool> >(body, parameter);

            return(exp);
        }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Boolean value.
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property.
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The Boolean value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
        /// the properties that are indexed, look for the specific property's property description and
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, bool value, SearchConditionOperation operation)
        {
            PropVariant propVar = new PropVariant();

            propVar.SetBool(value);

            return(CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Boolean", operation));
        }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value.
        /// Overload method takes a DateTime parameter for the comparison value.
        /// </summary>
        /// <param name="propertyKey">The property to be compared.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
        /// the properties that are indexed, look for the specific property's property description and
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(PropertyKey propertyKey, int value, SearchConditionOperation operation)
        {
            string canonicalName;

            PropertySystemNativeMethods.PSGetNameFromPropertyKey(ref propertyKey, out canonicalName);

            if (!string.IsNullOrEmpty(canonicalName))
            {
                return(CreateLeafCondition(canonicalName, value, operation));
            }
            else
            {
                throw new ArgumentException("Given property key is invalid", "propertyKey");
            }
        }
示例#15
0
 public SearchConditionAttribute(SearchConditionOperation operation)
 {
     this.Operation = operation;
 }
 /// <summary>Creates a leaf condition node that represents a comparison of property value and Floating Point value.</summary>
 /// <param name="propertyName">
 /// The name of a property to be compared, or null for an unspecified property. The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.
 /// </param>
 /// <param name="value">The Floating Point value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find the properties that
 /// are indexed, look for the specific property's property description and
 /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, double value, SearchConditionOperation operation)
 {
     using (var propVar = new PropVariant(value))
     {
         return(CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.FloatingPoint", operation));
     }
 }
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Floating Point value. 
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property. 
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The Floating Point value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find 
        /// the properties that are indexed, look for the specific property's property description and 
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, double value, SearchConditionOperation operation)
        {
            PropVariant propVar = new PropVariant();
            propVar.SetDouble(value);

            return CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.FloatingPoint", operation);
        }
示例#18
0
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value.
        /// Overload method takes a DateTime parameter for the comparison value.
        /// </summary>
        /// <param name="propertyKey">The property to be compared.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
        /// the properties that are indexed, look for the specific property's property description and
        /// <see cref="P:Ssz.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(PropertyKey propertyKey, int value, SearchConditionOperation operation)
        {
            string canonicalName;

            PropertySystemNativeMethods.PSGetNameFromPropertyKey(ref propertyKey, out canonicalName);

            if (string.IsNullOrEmpty(canonicalName))
            {
                throw new ArgumentException(LocalizedMessages.SearchConditionFactoryInvalidProperty, "propertyKey");
            }
            return(CreateLeafCondition(canonicalName, value, operation));
        }
        private static SearchCondition CreateLeafCondition(string propertyName, PropVariant propVar, string valueType, SearchConditionOperation operation)
        {
            IConditionFactory nativeConditionFactory = null;
            SearchCondition condition = null;

            try
            {
                // Same as the native "IConditionFactory:MakeLeaf" method
                nativeConditionFactory = (IConditionFactory)new ConditionFactoryCoClass();

                ICondition nativeCondition = null;

                if (string.IsNullOrEmpty(propertyName) || propertyName.ToLower() == "system.null")
                    propertyName = null;

                HRESULT hr = HRESULT.E_FAIL;

                hr = nativeConditionFactory.MakeLeaf(propertyName, operation, valueType,
                    ref propVar, null, null, null, false, out nativeCondition);

                if (!CoreErrorHelper.Succeeded((int)hr))
                    Marshal.ThrowExceptionForHR((int)hr);

                // Create our search condition and set the various properties.
                condition = new SearchCondition(nativeCondition);
            }
            finally
            {
                if (nativeConditionFactory != null)
                    Marshal.ReleaseComObject(nativeConditionFactory);
            }

            return condition;
        }
示例#20
0
 /// <summary>
 /// Creates a leaf condition node that represents a comparison of property value and constant value.
 /// Overload method takes a DateTime parameter for the comparison value.
 /// </summary>
 /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property.
 /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
 /// <param name="value">The DateTime value against which the property value should be compared.</param>
 /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
 /// <returns>SearchCondition based on the given parameters</returns>
 /// <remarks>
 /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
 /// the properties that are indexed, look for the specific property's property description and
 /// <see cref="P:Ssz.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
 /// </remarks>
 public static SearchCondition CreateLeafCondition(string propertyName, DateTime value, SearchConditionOperation operation)
 {
     using (PropVariant propVar = new PropVariant(value))
     {
         return(CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.DateTime", operation));
     }
 }
示例#21
0
        /// <summary>
        /// Creates a leaf condition node that represents a comparison of property value and Integer value.
        /// </summary>
        /// <param name="propertyName">The name of a property to be compared, or null for an unspecified property.
        /// The locale name of the leaf node is LOCALE_NAME_USER_DEFAULT.</param>
        /// <param name="value">The Integer value against which the property value should be compared.</param>
        /// <param name="operation">Specific condition to be used when comparing the actual value and the expected value of the given property</param>
        /// <returns>SearchCondition based on the given parameters</returns>
        /// <remarks>
        /// The search will only work for files that are indexed, as well as the specific properties are indexed. To find
        /// the properties that are indexed, look for the specific property's property description and
        /// <see cref="P:Microsoft.WindowsAPICodePack.Shell.PropertySystem.ShellPropertyDescription.TypeFlags"/> property for IsQueryable flag.
        /// </remarks>
        public static SearchCondition CreateLeafCondition(string propertyName, int value, SearchConditionOperation operation)
        {
            using (var propVar = new PropVariant(value))

                return(CreateLeafCondition(propertyName, propVar, "System.StructuredQuery.CustomProperty.Integer", operation));
        }