当前位置: 首页>>代码示例>>C#>>正文


C# ManagementClass.GetDefaultQuery方法代码示例

本文整理汇总了C#中System.Management.ManagementClass.GetDefaultQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementClass.GetDefaultQuery方法的具体用法?C# ManagementClass.GetDefaultQuery怎么用?C# ManagementClass.GetDefaultQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementClass的用法示例。


在下文中一共展示了ManagementClass.GetDefaultQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RefreshScript

        /// <summary>
        /// Refreshes the code tab with content generated by CurrentCodeGenerator for the specified ManagementClass.
        /// </summary>
        /// <param name="c">The System.Management.ManagementClass to be displayed.</param>
        private void RefreshScript(ManagementClass c)
        {
            if (this.CurrentCodeGenerator != null && c != null)
            {
                var query = c.GetDefaultQuery();

                // Reset script editor
                this.txtCode.IsReadOnly = false;
                this.txtCode.Text = String.Empty;
                this.txtCode.ConfigurationManager.Language = String.Empty;
                this.txtCode.ConfigurationManager.Configure();

                try
                {
                    this.txtCode.Text = this.CurrentCodeGenerator.GetScript(c, query);

                    // Update script
                    this.txtCode.ConfigurationManager.Language = this.CurrentCodeGenerator.Lexer;
                    this.txtCode.ConfigurationManager.Configure();

                    // Add CIM Type keywords
                    this.txtCode.Lexing.Keywords[0] += String.Format(" uint8 uint16 uint32 uint64 sint8 sint16 sint32 sint64 real32 real64 string boolean object datetime reference char16");

                    // Set colors
                    if (!String.IsNullOrEmpty(this.CurrentCodeGenerator.Lexer))
                    {
                        this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["STRING"]].ForeColor = Color.FromArgb(163, 21, 21);
                        this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["LINENUMBER"]].ForeColor = Color.FromArgb(43, 145, 175);
                        this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["LINENUMBER"]].BackColor = SystemColors.Window;
                        this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["NUMBER"]].ForeColor = SystemColors.WindowText;
                        this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["OPERATOR"]].ForeColor = SystemColors.WindowText;

                        if (this.CurrentCodeGenerator.Lexer == "cs" || this.CurrentCodeGenerator.Lexer == "cpp")
                        {
                            this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["GLOBALCLASS"]].ForeColor = Color.Blue;
                            this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["WORD2"]].ForeColor = Color.Blue;

                            this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["COMMENTLINE"]].ForeColor = Color.FromArgb(0, 128, 0);
                            this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["COMMENTDOC"]].ForeColor = Color.FromArgb(0, 128, 0);
                            this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["PREPROCESSOR"]].ForeColor = Color.Blue;
                        }

                        if (this.CurrentCodeGenerator.Lexer != "perl")
                        {
                            this.txtCode.Styles[this.txtCode.Lexing.StyleNameMap["COMMENT"]].ForeColor = Color.FromArgb(0, 128, 0);
                        }
                    }
                }

                catch (Exception e)
                {
                    this.txtCode.Text = e.Message;
                }
                this.txtCode.IsReadOnly = true;

                this.RefreshScriptOptions();

                // Reset actions
                var toDelete = new List<ToolStripMenuItem>();
                foreach (ToolStripMenuItem item in this.menuStripCode.Items)
                {
                    if (item.Tag != null && item.Tag.GetType() == typeof(CodeGeneratorAction))
                        toDelete.Add(item);
                }

                foreach(ToolStripMenuItem item in toDelete)
                    this.menuStripCode.Items.Remove(item);

                // Update actions
                try
                {
                    foreach (var action in this.CurrentCodeGenerator.GetActions(c, query))
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem
                        {
                            Text = action.Name,
                            Image = action.Image,
                            ImageTransparentColor = Color.Magenta,
                            Tag = action,
                            Alignment = ToolStripItemAlignment.Right
                        };

                        item.Click += new EventHandler(OnActionClicked);

                        this.menuStripCode.Items.Add(item);
                    }
                }
                catch (NotImplementedException) { }
            }
        }
开发者ID:giapdangle,项目名称:wmilab,代码行数:94,代码来源:frmMain.cs

示例2: RefreshQueryView

        /// <summary>
        /// Refreshes the query tab for the specified ManagementClass.
        /// </summary>
        /// <param name="c">The System.Management.ManagementClass to be displayed.</param>
        /// <remarks>Cancels any currently running queries.</remarks>
        private void RefreshQueryView(ManagementClass c)
        {
            // Stop an existing query
            if (this.queryBroker != null)
            {
                this.queryBroker.Cancel();
            }

            if (c != null)
            {
                var query = c.GetDefaultQuery();

                this.txtQuery.Text = query;
                this.queryBroker = new ManagementQueryBroker(query, this.CurrentNamespaceScope);

                InitQueryResultGrid(c, query);
            }
        }
开发者ID:giapdangle,项目名称:wmilab,代码行数:23,代码来源:frmMain.cs


注:本文中的System.Management.ManagementClass.GetDefaultQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。