本文整理汇总了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) { }
}
}
示例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);
}
}