Esempio n. 1
0
        /// <summary>
        /// Modifies the query, so that it returns only objects that have a property value greater than or equal to a <paramref name="minPropertyValue"/> threshold
        /// </summary>
        /// <param name="propertyName">Property name to query on</param>
        /// <param name="minPropertyValue">Minimum property value</param>
        /// <param name="behaviorOnNoMatch">
        /// Describes how to handle filters that didn't match any objects
        /// </param>
        public override void FilterByMinPropertyValue(string propertyName, object minPropertyValue, BehaviorOnNoMatch behaviorOnNoMatch)
        {
            this.ClientSideQuery.FilterByMinPropertyValue(propertyName, minPropertyValue, behaviorOnNoMatch);

            string wqlLiteral = CimQuery.ObjectToWqlLiteral(minPropertyValue);

            if (!string.IsNullOrWhiteSpace(wqlLiteral))
            {
                string condition = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0} >= {1}",
                    propertyName,
                    wqlLiteral);
                this.AddWqlCondition(condition);
            }
        }
Esempio n. 2
0
        private static string GetMatchConditionForEqualityOperator(string propertyName, object propertyValue)
        {
            string condition;

            // comparison of 'char' is case-sensitive in WQL (comparison of 'string' is case-insensitive)
            if (propertyValue is char)
            {
                char   c                = (char)propertyValue;
                char   lowerCase        = char.ToLowerInvariant(c);
                char   upperCase        = char.ToUpperInvariant(c);
                string lowerCaseLiteral = CimQuery.ObjectToWqlLiteral(lowerCase);
                string upperCaseLiteral = CimQuery.ObjectToWqlLiteral(upperCase);
                Dbg.Assert(!string.IsNullOrWhiteSpace(lowerCaseLiteral), "All characters are assumed to have valid WQL literals (lower)");
                Dbg.Assert(!string.IsNullOrWhiteSpace(upperCaseLiteral), "All characters are assumed to have valid WQL literals (upper)");
                condition = string.Format(
                    CultureInfo.InvariantCulture,
                    "(({0} = {1}) OR ({0} = {2}))",
                    propertyName,
                    lowerCaseLiteral,
                    upperCaseLiteral);
                return(condition);
            }

            string wqlLiteral = CimQuery.ObjectToWqlLiteral(propertyValue);

            if (string.IsNullOrWhiteSpace(wqlLiteral))
            {
                return(null);
            }

            condition = string.Format(
                CultureInfo.InvariantCulture,
                "({0} = {1})",
                propertyName,
                wqlLiteral);
            return(condition);
        }
Esempio n. 3
0
        private static string WildcardToWqlLikeOperand(WildcardPattern wildcardPattern, out bool needsClientSideFiltering)
        {
            string str = WildcardPatternToCimQueryParser.Parse(wildcardPattern, out needsClientSideFiltering);

            return(CimQuery.ObjectToWqlLiteral(str));
        }
Esempio n. 4
0
 private static string ObjectToWqlLiteral(object o)
 {
     if (!LanguagePrimitives.IsNull(o))
     {
         o = CimValueConverter.ConvertFromDotNetToCim(o);
         PSObject pSObject = PSObject.AsPSObject(o);
         Type     type     = pSObject.BaseObject.GetType();
         TypeCode typeCode = LanguagePrimitives.GetTypeCode(type);
         if (typeCode != TypeCode.String)
         {
             if (typeCode != TypeCode.Char)
             {
                 if (typeCode != TypeCode.DateTime)
                 {
                     if (type != typeof(TimeSpan))
                     {
                         if (!LanguagePrimitives.IsNumeric(typeCode))
                         {
                             if (!LanguagePrimitives.IsBooleanType(type))
                             {
                                 throw CimValueConverter.GetInvalidCastException(null, "InvalidCimQueryCast", o, CmdletizationResources.CimConversion_WqlQuery);
                             }
                             else
                             {
                                 if (!(bool)LanguagePrimitives.ConvertTo(o, typeof(bool), CultureInfo.InvariantCulture))
                                 {
                                     return("FALSE");
                                 }
                                 else
                                 {
                                     return("TRUE");
                                 }
                             }
                         }
                         else
                         {
                             return((string)LanguagePrimitives.ConvertTo(o, typeof(string), CultureInfo.InvariantCulture));
                         }
                     }
                     else
                     {
                         return(null);
                     }
                 }
                 else
                 {
                     DateTime dateTime     = (DateTime)LanguagePrimitives.ConvertTo(o, typeof(DateTime), CultureInfo.InvariantCulture);
                     string   dmtfDateTime = ManagementDateTimeConverter.ToDmtfDateTime(dateTime);
                     return(string.Concat("'", dmtfDateTime, "'"));
                 }
             }
             else
             {
                 return(CimQuery.ObjectToWqlLiteral(LanguagePrimitives.ConvertTo(o, typeof(string), CultureInfo.InvariantCulture)));
             }
         }
         else
         {
             string str = o.ToString();
             str = str.Replace("\\", "\\\\");
             str = str.Replace("'", "\\'");
             return(string.Concat("'", str, "'"));
         }
     }
     else
     {
         return("null");
     }
 }