Ejemplo n.º 1
0
 public static object CreateInMTA(Type type)
 {
     if (!MTAHelper.IsNoContextMTA())
     {
         MTAHelper.MTARequest mTARequest = new MTAHelper.MTARequest(type);
         lock (MTAHelper.critSec)
         {
             if (!MTAHelper.workerThreadInitialized)
             {
                 MTAHelper.InitWorkerThread();
                 MTAHelper.workerThreadInitialized = true;
             }
             int num = MTAHelper.reqList.Add(mTARequest);
             if (!MTAHelper.evtGo.Set())
             {
                 MTAHelper.reqList.RemoveAt(num);
                 throw new ManagementException(RC.GetString("WORKER_THREAD_WAKEUP_FAILED"));
             }
         }
         mTARequest.evtDone.WaitOne();
         if (mTARequest.exception == null)
         {
             return(mTARequest.createdObject);
         }
         else
         {
             throw mTARequest.exception;
         }
     }
     else
     {
         return(Activator.CreateInstance(type));
     }
 }
        internal static void ParseToken(ref string q, string token, string op, ref bool bTokenFound, ref string tokenValue)
        {
            int length;

            if (bTokenFound)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY_DUP_TOKEN"));
            }
            bTokenFound = true;
            q           = q.Remove(0, token.Length).TrimStart(null);
            if (op != null)
            {
                if (q.IndexOf(op, StringComparison.Ordinal) != 0)
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                }
                q = q.Remove(0, op.Length).TrimStart(null);
            }
            if (q.Length == 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY_NULL_TOKEN"));
            }
            if (-1 == (length = q.IndexOf(' ')))
            {
                length = q.Length;
            }
            tokenValue = q.Substring(0, length);
            q          = q.Remove(0, tokenValue.Length).TrimStart(null);
        }
Ejemplo n.º 3
0
        public static object CreateInMTA(Type type)
        {
            if (IsNoContextMTA())
            {
                return(Activator.CreateInstance(type));
            }
            MTARequest request = new MTARequest(type);

            lock (critSec)
            {
                if (!workerThreadInitialized)
                {
                    InitWorkerThread();
                    workerThreadInitialized = true;
                }
                int index = reqList.Add(request);
                if (!evtGo.Set())
                {
                    reqList.RemoveAt(index);
                    throw new ManagementException(RC.GetString("WORKER_THREAD_WAKEUP_FAILED"));
                }
            }
            request.evtDone.WaitOne();
            if (request.exception != null)
            {
                throw request.exception;
            }
            return(request.createdObject);
        }
Ejemplo n.º 4
0
 public SelectQuery(string queryOrClassName)
 {
     this.selectedProperties = new StringCollection();
     if (queryOrClassName == null)
     {
         return;
     }
     else
     {
         if (!queryOrClassName.TrimStart(new char[0]).StartsWith(ManagementQuery.tokenSelect, StringComparison.OrdinalIgnoreCase))
         {
             ManagementPath managementPath = new ManagementPath(queryOrClassName);
             if (!managementPath.IsClass || managementPath.NamespacePath.Length != 0)
             {
                 throw new ArgumentException(RC.GetString("INVALID_QUERY"), "queryOrClassName");
             }
             else
             {
                 this.ClassName = queryOrClassName;
                 return;
             }
         }
         else
         {
             this.QueryString = queryOrClassName;
             return;
         }
     }
 }
Ejemplo n.º 5
0
 public RelatedObjectQuery(string queryOrSourceObject)
 {
     if (queryOrSourceObject == null)
     {
         return;
     }
     else
     {
         if (!queryOrSourceObject.TrimStart(new char[0]).StartsWith(RelatedObjectQuery.tokenAssociators, StringComparison.OrdinalIgnoreCase))
         {
             ManagementPath managementPath = new ManagementPath(queryOrSourceObject);
             if ((managementPath.IsClass || managementPath.IsInstance) && managementPath.NamespacePath.Length == 0)
             {
                 this.SourceObject  = queryOrSourceObject;
                 this.isSchemaQuery = false;
                 return;
             }
             else
             {
                 throw new ArgumentException(RC.GetString("INVALID_QUERY"), "queryOrSourceObject");
             }
         }
         else
         {
             this.QueryString = queryOrSourceObject;
             return;
         }
     }
 }
 internal static void ParseToken(ref string q, string token, ref bool bTokenFound)
 {
     if (bTokenFound)
     {
         throw new ArgumentException(RC.GetString("INVALID_QUERY_DUP_TOKEN"));
     }
     bTokenFound = true;
     q           = q.Remove(0, token.Length).TrimStart(null);
 }
Ejemplo n.º 7
0
 public SelectQuery(bool isSchemaQuery, string condition)
 {
     if (!isSchemaQuery)
     {
         throw new ArgumentException(RC.GetString("INVALID_QUERY"), "isSchemaQuery");
     }
     this.isSchemaQuery      = true;
     this.className          = null;
     this.condition          = condition;
     this.selectedProperties = null;
     this.BuildQuery();
 }
 public RelationshipQuery(bool isSchemaQuery, string sourceObject, string relationshipClass, string relationshipQualifier, string thisRole)
 {
     if (!isSchemaQuery)
     {
         throw new ArgumentException(RC.GetString("INVALID_QUERY"), "isSchemaQuery");
     }
     this.isSchemaQuery         = true;
     this.sourceObject          = sourceObject;
     this.relationshipClass     = relationshipClass;
     this.relationshipQualifier = relationshipQualifier;
     this.thisRole             = thisRole;
     this.classDefinitionsOnly = false;
     this.BuildQuery();
 }
 public WqlEventQuery(string queryOrEventClassName)
 {
     this.groupByPropertyList = new StringCollection();
     if (queryOrEventClassName != null)
     {
         if (queryOrEventClassName.TrimStart(new char[0]).StartsWith(tokenSelectAll, StringComparison.OrdinalIgnoreCase))
         {
             this.QueryString = queryOrEventClassName;
         }
         else
         {
             ManagementPath path = new ManagementPath(queryOrEventClassName);
             if (!path.IsClass || (path.NamespacePath.Length != 0))
             {
                 throw new ArgumentException(RC.GetString("INVALID_QUERY"), "queryOrEventClassName");
             }
             this.EventClassName = queryOrEventClassName;
         }
     }
 }
 public RelationshipQuery(string queryOrSourceObject)
 {
     if (queryOrSourceObject != null)
     {
         if (queryOrSourceObject.TrimStart(new char[0]).StartsWith(tokenReferences, StringComparison.OrdinalIgnoreCase))
         {
             this.QueryString = queryOrSourceObject;
         }
         else
         {
             ManagementPath path = new ManagementPath(queryOrSourceObject);
             if ((!path.IsClass && !path.IsInstance) || (path.NamespacePath.Length != 0))
             {
                 throw new ArgumentException(RC.GetString("INVALID_QUERY"), "queryOrSourceObject");
             }
             this.SourceObject  = queryOrSourceObject;
             this.isSchemaQuery = false;
         }
     }
 }
        protected internal override void ParseQuery(string query)
        {
            int    index;
            string str2;

            this.eventClassName      = null;
            this.withinInterval      = TimeSpan.Zero;
            this.condition           = null;
            this.groupWithinInterval = TimeSpan.Zero;
            if (this.groupByPropertyList != null)
            {
                this.groupByPropertyList.Clear();
            }
            this.havingCondition = null;
            string strA        = query.Trim();
            bool   bTokenFound = false;
            string tokenSelect = ManagementQuery.tokenSelect;

            if ((strA.Length < tokenSelect.Length) || (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) != 0))
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            strA = strA.Remove(0, tokenSelect.Length).TrimStart(null);
            if (!strA.StartsWith("*", StringComparison.Ordinal))
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "*");
            }
            strA        = strA.Remove(0, 1).TrimStart(null);
            tokenSelect = "from ";
            if ((strA.Length < tokenSelect.Length) || (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) != 0))
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "from");
            }
            ManagementQuery.ParseToken(ref strA, tokenSelect, null, ref bTokenFound, ref this.eventClassName);
            tokenSelect = "within ";
            if ((strA.Length >= tokenSelect.Length) && (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                string tokenValue = null;
                bTokenFound = false;
                ManagementQuery.ParseToken(ref strA, tokenSelect, null, ref bTokenFound, ref tokenValue);
                this.withinInterval = TimeSpan.FromSeconds(((IConvertible)tokenValue).ToDouble(null));
            }
            tokenSelect = "group within ";
            if ((strA.Length >= tokenSelect.Length) && ((index = strA.ToLower(CultureInfo.InvariantCulture).IndexOf(tokenSelect, StringComparison.Ordinal)) != -1))
            {
                str2 = strA.Substring(0, index).Trim();
                strA = strA.Remove(0, index);
                string str6 = null;
                bTokenFound = false;
                ManagementQuery.ParseToken(ref strA, tokenSelect, null, ref bTokenFound, ref str6);
                this.groupWithinInterval = TimeSpan.FromSeconds(((IConvertible)str6).ToDouble(null));
                tokenSelect = "by ";
                if ((strA.Length >= tokenSelect.Length) && (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    string str3;
                    strA = strA.Remove(0, tokenSelect.Length);
                    if (this.groupByPropertyList != null)
                    {
                        this.groupByPropertyList.Clear();
                    }
                    else
                    {
                        this.groupByPropertyList = new StringCollection();
                    }
                    while ((index = strA.IndexOf(',')) > 0)
                    {
                        str3 = strA.Substring(0, index);
                        strA = strA.Remove(0, index + 1).TrimStart(null);
                        str3 = str3.Trim();
                        if (str3.Length > 0)
                        {
                            this.groupByPropertyList.Add(str3);
                        }
                    }
                    index = strA.IndexOf(' ');
                    if (index > 0)
                    {
                        str3 = strA.Substring(0, index);
                        strA = strA.Remove(0, index).TrimStart(null);
                        this.groupByPropertyList.Add(str3);
                    }
                    else
                    {
                        this.groupByPropertyList.Add(strA);
                        return;
                    }
                }
                tokenSelect = "having ";
                bTokenFound = false;
                if ((strA.Length >= tokenSelect.Length) && (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    strA = strA.Remove(0, tokenSelect.Length);
                    if (strA.Length == 0)
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "having");
                    }
                    this.havingCondition = strA;
                }
            }
            else
            {
                str2 = strA.Trim();
            }
            tokenSelect = "where ";
            if ((str2.Length >= tokenSelect.Length) && (string.Compare(str2, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                this.condition = str2.Substring(tokenSelect.Length);
            }
        }
Ejemplo n.º 12
0
        protected internal override void ParseQuery(string query)
        {
            this.className = null;
            this.condition = null;
            if (this.selectedProperties != null)
            {
                this.selectedProperties.Clear();
            }
            string strA        = query.Trim();
            bool   bTokenFound = false;

            if (!this.isSchemaQuery)
            {
                string tokenSelect = ManagementQuery.tokenSelect;
                if ((strA.Length < tokenSelect.Length) || (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                }
                ManagementQuery.ParseToken(ref strA, tokenSelect, ref bTokenFound);
                if (strA[0] != '*')
                {
                    string str2;
                    int    index;
                    if (this.selectedProperties != null)
                    {
                        this.selectedProperties.Clear();
                    }
                    else
                    {
                        this.selectedProperties = new StringCollection();
                    }
                    while ((index = strA.IndexOf(',')) > 0)
                    {
                        str2 = strA.Substring(0, index);
                        strA = strA.Remove(0, index + 1).TrimStart(null);
                        str2 = str2.Trim();
                        if (str2.Length > 0)
                        {
                            this.selectedProperties.Add(str2);
                        }
                    }
                    index = strA.IndexOf(' ');
                    if (index <= 0)
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                    }
                    str2 = strA.Substring(0, index);
                    strA = strA.Remove(0, index).TrimStart(null);
                    this.selectedProperties.Add(str2);
                }
                else
                {
                    strA = strA.Remove(0, 1).TrimStart(null);
                }
                tokenSelect = "from ";
                bTokenFound = false;
                if ((strA.Length < tokenSelect.Length) || (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                }
                ManagementQuery.ParseToken(ref strA, tokenSelect, null, ref bTokenFound, ref this.className);
                tokenSelect = "where ";
                if ((strA.Length >= tokenSelect.Length) && (string.Compare(strA, 0, tokenSelect, 0, tokenSelect.Length, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    this.condition = strA.Substring(tokenSelect.Length).Trim();
                }
            }
            else
            {
                string strB = "select";
                if ((strA.Length < strB.Length) || (string.Compare(strA, 0, strB, 0, strB.Length, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "select");
                }
                strA = strA.Remove(0, strB.Length).TrimStart(null);
                if (strA.IndexOf('*', 0) != 0)
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "*");
                }
                strA = strA.Remove(0, 1).TrimStart(null);
                strB = "from";
                if ((strA.Length < strB.Length) || (string.Compare(strA, 0, strB, 0, strB.Length, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "from");
                }
                strA = strA.Remove(0, strB.Length).TrimStart(null);
                strB = "meta_class";
                if ((strA.Length < strB.Length) || (string.Compare(strA, 0, strB, 0, strB.Length, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "meta_class");
                }
                strA = strA.Remove(0, strB.Length).TrimStart(null);
                if (0 < strA.Length)
                {
                    strB = "where";
                    if ((strA.Length < strB.Length) || (string.Compare(strA, 0, strB, 0, strB.Length, StringComparison.OrdinalIgnoreCase) != 0))
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "where");
                    }
                    strA = strA.Remove(0, strB.Length);
                    if ((strA.Length == 0) || !char.IsWhiteSpace(strA[0]))
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                    }
                    strA           = strA.TrimStart(null);
                    this.condition = strA;
                }
                else
                {
                    this.condition = string.Empty;
                }
                this.className          = null;
                this.selectedProperties = null;
            }
        }
Ejemplo n.º 13
0
        protected internal override void ParseQuery(string query)
        {
            string str;
            int    num;

            this.className = null;
            this.condition = null;
            if (this.selectedProperties != null)
            {
                this.selectedProperties.Clear();
            }
            string str1 = query.Trim();
            bool   flag = false;

            if (this.isSchemaQuery)
            {
                string str2 = "select";
                if (str1.Length < str2.Length || string.Compare(str1, 0, str2, 0, str2.Length, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "select");
                }
                else
                {
                    str1 = str1.Remove(0, str2.Length).TrimStart(null);
                    if (str1.IndexOf('*', 0) == 0)
                    {
                        str1 = str1.Remove(0, 1).TrimStart(null);
                        str2 = "from";
                        if (str1.Length < str2.Length || string.Compare(str1, 0, str2, 0, str2.Length, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            throw new ArgumentException(RC.GetString("INVALID_QUERY"), "from");
                        }
                        else
                        {
                            str1 = str1.Remove(0, str2.Length).TrimStart(null);
                            str2 = "meta_class";
                            if (str1.Length < str2.Length || string.Compare(str1, 0, str2, 0, str2.Length, StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "meta_class");
                            }
                            else
                            {
                                str1 = str1.Remove(0, str2.Length).TrimStart(null);
                                if (0 >= str1.Length)
                                {
                                    this.condition = string.Empty;
                                }
                                else
                                {
                                    str2 = "where";
                                    if (str1.Length < str2.Length || string.Compare(str1, 0, str2, 0, str2.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                    {
                                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "where");
                                    }
                                    else
                                    {
                                        str1 = str1.Remove(0, str2.Length);
                                        if (str1.Length == 0 || !char.IsWhiteSpace(str1[0]))
                                        {
                                            throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                                        }
                                        else
                                        {
                                            str1           = str1.TrimStart(null);
                                            this.condition = str1;
                                        }
                                    }
                                }
                                this.className          = null;
                                this.selectedProperties = null;
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "*");
                    }
                }
            }
            else
            {
                string str3 = ManagementQuery.tokenSelect;
                if (str1.Length < str3.Length || string.Compare(str1, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                }
                else
                {
                    ManagementQuery.ParseToken(ref str1, str3, ref flag);
                    if (str1[0] == '*')
                    {
                        str1 = str1.Remove(0, 1).TrimStart(null);
                    }
                    else
                    {
                        if (this.selectedProperties == null)
                        {
                            this.selectedProperties = new StringCollection();
                        }
                        else
                        {
                            this.selectedProperties.Clear();
                        }
                        while (true)
                        {
                            int num1 = str1.IndexOf(',');
                            num = num1;
                            if (num1 <= 0)
                            {
                                break;
                            }
                            str  = str1.Substring(0, num);
                            str1 = str1.Remove(0, num + 1).TrimStart(null);
                            str  = str.Trim();
                            if (str.Length > 0)
                            {
                                this.selectedProperties.Add(str);
                            }
                        }
                        int num2 = str1.IndexOf(' ');
                        num = num2;
                        if (num2 <= 0)
                        {
                            throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                        }
                        else
                        {
                            str  = str1.Substring(0, num);
                            str1 = str1.Remove(0, num).TrimStart(null);
                            this.selectedProperties.Add(str);
                        }
                    }
                    str3 = "from ";
                    flag = false;
                    if (str1.Length < str3.Length || string.Compare(str1, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                    }
                    else
                    {
                        ManagementQuery.ParseToken(ref str1, str3, null, ref flag, ref this.className);
                        str3 = "where ";
                        if (str1.Length >= str3.Length && string.Compare(str1, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.condition = str1.Substring(str3.Length).Trim();
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        protected internal override void ParseQuery(string query)
        {
            string str   = null;
            string str1  = null;
            string str2  = null;
            string str3  = null;
            string str4  = null;
            string str5  = null;
            bool   flag  = false;
            bool   flag1 = false;
            string str6  = query.Trim();

            if (string.Compare(str6, 0, RelatedObjectQuery.tokenAssociators, 0, RelatedObjectQuery.tokenAssociators.Length, StringComparison.OrdinalIgnoreCase) == 0)
            {
                str6 = str6.Remove(0, RelatedObjectQuery.tokenAssociators.Length);
                if (str6.Length == 0 || !char.IsWhiteSpace(str6[0]))
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                }
                else
                {
                    str6 = str6.TrimStart(null);
                    if (string.Compare(str6, 0, RelatedObjectQuery.tokenOf, 0, RelatedObjectQuery.tokenOf.Length, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        str6 = str6.Remove(0, RelatedObjectQuery.tokenOf.Length).TrimStart(null);
                        if (str6.IndexOf('{') == 0)
                        {
                            str6 = str6.Remove(0, 1).TrimStart(null);
                            int num  = str6.IndexOf('}');
                            int num1 = num;
                            if (-1 != num)
                            {
                                string str7 = str6.Substring(0, num1).TrimEnd(null);
                                str6 = str6.Remove(0, num1 + 1).TrimStart(null);
                                if (0 < str6.Length)
                                {
                                    if (string.Compare(str6, 0, RelatedObjectQuery.tokenWhere, 0, RelatedObjectQuery.tokenWhere.Length, StringComparison.OrdinalIgnoreCase) == 0)
                                    {
                                        str6 = str6.Remove(0, RelatedObjectQuery.tokenWhere.Length);
                                        if (str6.Length == 0 || !char.IsWhiteSpace(str6[0]))
                                        {
                                            throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                                        }
                                        else
                                        {
                                            str6 = str6.TrimStart(null);
                                            bool flag2 = false;
                                            bool flag3 = false;
                                            bool flag4 = false;
                                            bool flag5 = false;
                                            bool flag6 = false;
                                            bool flag7 = false;
                                            bool flag8 = false;
                                            bool flag9 = false;
                                            while (true)
                                            {
                                                if (str6.Length < RelatedObjectQuery.tokenResultClass.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenResultClass, 0, RelatedObjectQuery.tokenResultClass.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                {
                                                    if (str6.Length < RelatedObjectQuery.tokenAssocClass.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenAssocClass, 0, RelatedObjectQuery.tokenAssocClass.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                    {
                                                        if (str6.Length < RelatedObjectQuery.tokenResultRole.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenResultRole, 0, RelatedObjectQuery.tokenResultRole.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                        {
                                                            if (str6.Length < RelatedObjectQuery.tokenRole.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenRole, 0, RelatedObjectQuery.tokenRole.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                            {
                                                                if (str6.Length < RelatedObjectQuery.tokenRequiredQualifier.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenRequiredQualifier, 0, RelatedObjectQuery.tokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                                {
                                                                    if (str6.Length < RelatedObjectQuery.tokenRequiredAssocQualifier.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenRequiredAssocQualifier, 0, RelatedObjectQuery.tokenRequiredAssocQualifier.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                                    {
                                                                        if (str6.Length < RelatedObjectQuery.tokenSchemaOnly.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenSchemaOnly, 0, RelatedObjectQuery.tokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                                        {
                                                                            if (str6.Length < RelatedObjectQuery.tokenClassDefsOnly.Length || string.Compare(str6, 0, RelatedObjectQuery.tokenClassDefsOnly, 0, RelatedObjectQuery.tokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase) != 0)
                                                                            {
                                                                                break;
                                                                            }
                                                                            ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenClassDefsOnly, ref flag8);
                                                                            flag = true;
                                                                        }
                                                                        else
                                                                        {
                                                                            ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenSchemaOnly, ref flag9);
                                                                            flag1 = true;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenRequiredAssocQualifier, "=", ref flag7, ref str5);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenRequiredQualifier, "=", ref flag6, ref str4);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenRole, "=", ref flag5, ref str3);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenResultRole, "=", ref flag4, ref str2);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenAssocClass, "=", ref flag3, ref str1);
                                                    }
                                                }
                                                else
                                                {
                                                    ManagementQuery.ParseToken(ref str6, RelatedObjectQuery.tokenResultClass, "=", ref flag2, ref str);
                                                }
                                            }
                                            if (str6.Length == 0)
                                            {
                                                if (flag9 && flag8)
                                                {
                                                    throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                                                }
                                            }
                                            else
                                            {
                                                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "where");
                                    }
                                }
                                this.sourceObject          = str7;
                                this.relatedClass          = str;
                                this.relationshipClass     = str1;
                                this.relatedRole           = str2;
                                this.thisRole              = str3;
                                this.relatedQualifier      = str4;
                                this.relationshipQualifier = str5;
                                this.classDefinitionsOnly  = flag;
                                this.isSchemaQuery         = flag1;
                                return;
                            }
                            else
                            {
                                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                            }
                        }
                        else
                        {
                            throw new ArgumentException(RC.GetString("INVALID_QUERY"));
                        }
                    }
                    else
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "of");
                    }
                }
            }
            else
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "associators");
            }
        }
Ejemplo n.º 15
0
        protected internal override void ParseQuery(string query)
        {
            string str;
            string str1;

            this.eventClassName      = null;
            this.withinInterval      = TimeSpan.Zero;
            this.condition           = null;
            this.groupWithinInterval = TimeSpan.Zero;
            if (this.groupByPropertyList != null)
            {
                this.groupByPropertyList.Clear();
            }
            this.havingCondition = null;
            string str2 = query.Trim();
            bool   flag = false;
            string str3 = ManagementQuery.tokenSelect;

            if (str2.Length < str3.Length || string.Compare(str2, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            else
            {
                str2 = str2.Remove(0, str3.Length).TrimStart(null);
                if (str2.StartsWith("*", StringComparison.Ordinal))
                {
                    str2 = str2.Remove(0, 1).TrimStart(null);
                    str3 = "from ";
                    if (str2.Length < str3.Length || string.Compare(str2, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        throw new ArgumentException(RC.GetString("INVALID_QUERY"), "from");
                    }
                    else
                    {
                        ManagementQuery.ParseToken(ref str2, str3, null, ref flag, ref this.eventClassName);
                        str3 = "within ";
                        if (str2.Length >= str3.Length && string.Compare(str2, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            string str4 = null;
                            flag = false;
                            ManagementQuery.ParseToken(ref str2, str3, null, ref flag, ref str4);
                            this.withinInterval = TimeSpan.FromSeconds(((IConvertible)str4).ToDouble(null));
                        }
                        str3 = "group within ";
                        if (str2.Length >= str3.Length)
                        {
                            int num  = str2.ToLower(CultureInfo.InvariantCulture).IndexOf(str3, StringComparison.Ordinal);
                            int num1 = num;
                            if (num == -1)
                            {
                                str  = str2.Trim();
                                str3 = "where ";
                                if (str.Length >= str3.Length && string.Compare(str, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    this.condition = str.Substring(str3.Length);
                                }
                                return;
                            }
                            str  = str2.Substring(0, num1).Trim();
                            str2 = str2.Remove(0, num1);
                            string str5 = null;
                            flag = false;
                            ManagementQuery.ParseToken(ref str2, str3, null, ref flag, ref str5);
                            this.groupWithinInterval = TimeSpan.FromSeconds(((IConvertible)str5).ToDouble(null));
                            str3 = "by ";
                            if (str2.Length >= str3.Length && string.Compare(str2, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                str2 = str2.Remove(0, str3.Length);
                                if (this.groupByPropertyList == null)
                                {
                                    this.groupByPropertyList = new StringCollection();
                                }
                                else
                                {
                                    this.groupByPropertyList.Clear();
                                }
                                while (true)
                                {
                                    int num2 = str2.IndexOf(',');
                                    num1 = num2;
                                    if (num2 <= 0)
                                    {
                                        break;
                                    }
                                    str1 = str2.Substring(0, num1);
                                    str2 = str2.Remove(0, num1 + 1).TrimStart(null);
                                    str1 = str1.Trim();
                                    if (str1.Length > 0)
                                    {
                                        this.groupByPropertyList.Add(str1);
                                    }
                                }
                                int num3 = str2.IndexOf(' ');
                                num1 = num3;
                                if (num3 <= 0)
                                {
                                    this.groupByPropertyList.Add(str2);
                                    return;
                                }
                                else
                                {
                                    str1 = str2.Substring(0, num1);
                                    str2 = str2.Remove(0, num1).TrimStart(null);
                                    this.groupByPropertyList.Add(str1);
                                }
                            }
                            str3 = "having ";
                            if (str2.Length >= str3.Length && string.Compare(str2, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                str2 = str2.Remove(0, str3.Length);
                                if (str2.Length != 0)
                                {
                                    this.havingCondition = str2;
                                    str3 = "where ";
                                    if (str.Length >= str3.Length && string.Compare(str, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                                    {
                                        this.condition = str.Substring(str3.Length);
                                    }
                                    return;
                                }
                                else
                                {
                                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "having");
                                }
                            }
                            else
                            {
                                str3 = "where ";
                                if (str.Length >= str3.Length && string.Compare(str, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    this.condition = str.Substring(str3.Length);
                                }
                                return;
                            }
                        }
                        str  = str2.Trim();
                        str3 = "where ";
                        if (str.Length >= str3.Length && string.Compare(str, 0, str3, 0, str3.Length, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.condition = str.Substring(str3.Length);
                        }
                        return;
                    }
                }
                else
                {
                    throw new ArgumentException(RC.GetString("INVALID_QUERY"), "*");
                }
            }
        }
        protected internal override void ParseQuery(string query)
        {
            string str        = null;
            string tokenValue = null;
            string str3       = null;
            string str4       = null;
            int    num;
            bool   flag  = false;
            bool   flag2 = false;
            string strA  = query.Trim();

            if (string.Compare(strA, 0, tokenReferences, 0, tokenReferences.Length, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "references");
            }
            strA = strA.Remove(0, tokenReferences.Length);
            if ((strA.Length == 0) || !char.IsWhiteSpace(strA[0]))
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            strA = strA.TrimStart(null);
            if (string.Compare(strA, 0, tokenOf, 0, tokenOf.Length, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "of");
            }
            strA = strA.Remove(0, tokenOf.Length).TrimStart(null);
            if (strA.IndexOf('{') != 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            strA = strA.Remove(0, 1).TrimStart(null);
            if (-1 == (num = strA.IndexOf('}')))
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            str  = strA.Substring(0, num).TrimEnd(null);
            strA = strA.Remove(0, num + 1).TrimStart(null);
            if (0 >= strA.Length)
            {
                goto Label_0366;
            }
            if (string.Compare(strA, 0, tokenWhere, 0, tokenWhere.Length, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"), "where");
            }
            strA = strA.Remove(0, tokenWhere.Length);
            if ((strA.Length == 0) || !char.IsWhiteSpace(strA[0]))
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            strA = strA.TrimStart(null);
            bool bTokenFound = false;
            bool flag4       = false;
            bool flag5       = false;
            bool flag6       = false;
            bool flag7       = false;

Label_01D8:
            while ((strA.Length >= tokenResultClass.Length) && (string.Compare(strA, 0, tokenResultClass, 0, tokenResultClass.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                ManagementQuery.ParseToken(ref strA, tokenResultClass, "=", ref bTokenFound, ref tokenValue);
            }
            if ((strA.Length >= tokenRole.Length) && (string.Compare(strA, 0, tokenRole, 0, tokenRole.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                ManagementQuery.ParseToken(ref strA, tokenRole, "=", ref flag4, ref str3);
                goto Label_01D8;
            }
            if ((strA.Length >= tokenRequiredQualifier.Length) && (string.Compare(strA, 0, tokenRequiredQualifier, 0, tokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                ManagementQuery.ParseToken(ref strA, tokenRequiredQualifier, "=", ref flag5, ref str4);
                goto Label_01D8;
            }
            if ((strA.Length >= tokenClassDefsOnly.Length) && (string.Compare(strA, 0, tokenClassDefsOnly, 0, tokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                ManagementQuery.ParseToken(ref strA, tokenClassDefsOnly, ref flag6);
                flag = true;
                goto Label_01D8;
            }
            if ((strA.Length >= tokenSchemaOnly.Length) && (string.Compare(strA, 0, tokenSchemaOnly, 0, tokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase) == 0))
            {
                ManagementQuery.ParseToken(ref strA, tokenSchemaOnly, ref flag7);
                flag2 = true;
                goto Label_01D8;
            }
            if (strA.Length != 0)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
            if (flag && flag2)
            {
                throw new ArgumentException(RC.GetString("INVALID_QUERY"));
            }
Label_0366:
            this.sourceObject          = str;
            this.relationshipClass     = tokenValue;
            this.thisRole              = str3;
            this.relationshipQualifier = str4;
            this.classDefinitionsOnly  = flag;
            this.isSchemaQuery         = flag2;
        }