/// <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) { } } }
/// <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); } }