/// <summary>
        /// Creates a condition node that is a logical negation (NOT) of another condition
        /// (a subnode of this node).
        /// </summary>
        /// <param name="conditionToBeNegated">SearchCondition node to be negated.</param>
        /// <param name="simplify">True to logically simplify the result if possible; False otherwise.
        /// In a query builder scenario, simplyfy should typically be set to false.</param>
        /// <returns>New SearchCondition</returns>
        public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplify)
        {
            if (conditionToBeNegated == null)
            {
                throw new ArgumentNullException(nameof(conditionToBeNegated));
            }

            // Same as the native "IConditionFactory:MakeNot" method
            IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass();
            ICondition        result;

            try
            {
                HResult hr = nativeConditionFactory.MakeNot(conditionToBeNegated.NativeSearchCondition, simplify, out result);

                if (!CoreErrorHelper.Succeeded(hr))
                {
                    throw new ShellException(hr);
                }
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return(new SearchCondition(result));
        }
Example #2
0
        private static SearchCondition CreateLeafCondition(string propertyName, PropVariant propVar, string valueType,
                                                           SearchConditionOperation operation)
        {
            IConditionFactory nativeConditionFactory = null;
            SearchCondition   condition = null;

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

                nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass();

                ICondition nativeCondition = null;
                var        hr = nativeConditionFactory.MakeLeaf(propertyName, (CONDITION_OPERATION)operation, valueType,
                                                                propVar, null, null, null, false, out nativeCondition);
                if (HRESULT.Failed(hr))
                {
                    throw ShellException.FromHRESULT(hr);
                }

                condition = new SearchCondition(nativeCondition);
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return(condition);
        }
Example #3
0
        /// <summary>
        /// Creates a condition node that is a logical negation (NOT) of another condition
        /// (a subnode of this node).
        /// </summary>
        /// <param name="conditionToBeNegated">SearchCondition node to be negated.</param>
        /// <param name="simplyfy">True to logically simplify the result if possible; False otherwise.
        /// In a query builder scenario, simplyfy should typically be set to false.</param>
        /// <returns>New SearchCondition</returns>
        public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplyfy)
        {
            // Same as the native "IConditionFactory:MakeNot" method
            IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass();
            ICondition        result;

            try
            {
                HRESULT hr = nativeConditionFactory.MakeNot(conditionToBeNegated.NativeSearchCondition, simplyfy, out result);

                if (!CoreErrorHelper.Succeeded((int)hr))
                {
                    Marshal.ThrowExceptionForHR((int)hr);
                }
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return(new SearchCondition(result));
        }
Example #4
0
        /// <summary>
        /// Creates a condition node that is a logical conjunction ("AND") or disjunction ("OR")
        /// of a collection of subconditions.
        /// </summary>
        /// <param name="conditionType">The SearchConditionType of the condition node.
        /// Must be either AndCondition or OrCondition.</param>
        /// <param name="simplyfy">TRUE to logically simplify the result, if possible;
        /// then the result will not necessarily to be of the specified kind. FALSE if the result should
        /// have exactly the prescribed structure. An application that plans to execute a query based on the
        /// condition tree would typically benefit from setting this parameter to TRUE. </param>
        /// <param name="conditionNodes">Array of subconditions</param>
        /// <returns>New SearchCondition based on the operation</returns>
        public static SearchCondition CreateAndOrCondition(SearchConditionType conditionType, bool simplyfy, params SearchCondition[] conditionNodes)
        {
            // Same as the native "IConditionFactory:MakeAndOr" method
            IConditionFactory nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass();
            ICondition        result = null;

            try
            {
                //
                List <ICondition> conditionList = new List <ICondition>();
                foreach (SearchCondition c in conditionNodes)
                {
                    conditionList.Add(c.NativeSearchCondition);
                }

                IEnumUnknown subConditions = new EnumUnknownClass(conditionList.ToArray());

                HRESULT hr = nativeConditionFactory.MakeAndOr(conditionType, subConditions, simplyfy, out result);

                if (!CoreErrorHelper.Succeeded((int)hr))
                {
                    Marshal.ThrowExceptionForHR((int)hr);
                }
            }
            finally
            {
                if (nativeConditionFactory != null)
                {
                    Marshal.ReleaseComObject(nativeConditionFactory);
                }
            }

            return(new SearchCondition(result));
        }
        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);
        }
Example #6
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.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);
        }