static public String GetMethodDescription(String methName, ManagementObject curObj, string connectAs, string pw) { try { Qualifier descrQual = null; Method verboseMeth = null; if (!curObj.Path.IsClass) { ManagementClass classObj = WmiHelper.GetClassObject(curObj, connectAs, pw); verboseMeth = classObj.Methods[methName]; } else { verboseMeth = ((ManagementClass)curObj).Methods[methName]; } descrQual = verboseMeth.Qualifiers["Description"]; return(descrQual.Value.ToString()); } catch (Exception) { //2880: removed message here return(""); } }
static public String GetPropertyDescription(String propName, ISWbemObject curObj) { try { if (curObj == null) { throw new ArgumentNullException("curObj"); } ISWbemProperty verboseProp = null; if (!curObj.Path_.IsClass) { ISWbemObject classObj = WmiHelper.GetClassObject(curObj); verboseProp = classObj.Properties_.Item(propName, 0); } else { verboseProp = curObj.Properties_.Item(propName, 0); } string descr = string.Empty; ISWbemQualifier descrQual = verboseProp.Qualifiers_.Item("Description", 0); descr = descrQual.get_Value().ToString(); return(descr); } catch (Exception) { return(""); } }
static public String GetMethodDescription(String methName, ISWbemObject curObj) { try { ISWbemQualifier descrQual = null; ISWbemMethod verboseMeth = null; if (!curObj.Path_.IsClass) { ISWbemObject classObj = WmiHelper.GetClassObject(curObj); verboseMeth = classObj.Methods_.Item(methName, 0); } else { verboseMeth = curObj.Methods_.Item(methName, 0); } descrQual = verboseMeth.Qualifiers_.Item("Description", 0); return(descrQual.get_Value().ToString()); } catch (Exception) { //2880: removed message here return(""); } }
static public String GetPropertyDescription(String propName, ManagementObject curObj, string connectAs, string pw) { try { if (curObj == null) { throw new ArgumentNullException("curObj"); } Property verboseProp = null; if (!curObj.Path.IsClass) { ManagementObject classObj = WmiHelper.GetClassObject(curObj, connectAs, pw); verboseProp = classObj.Properties[propName]; } else { verboseProp = curObj.Properties[propName]; } string descr = string.Empty; Qualifier descrQual = verboseProp.Qualifiers["Description"]; descr = descrQual.Value.ToString(); return(descr); } catch (Exception) { return(""); } }
public AssocGroupComponent(ManagementObject assocInstance, ManagementObject sourceObj) { sourceInst = sourceObj; associationPath = assocInstance.Path.Path; associationClass = assocInstance.Path.ClassName; //now, inspect assocInstance object to find target role and path string targetNamespacePath = WmiHelper.GetAssocTargetNamespacePath(assocInstance, sourceObj.Path); int colon = targetNamespacePath.IndexOf(":"); if (colon >= 0) { targetClass = targetNamespacePath.Substring(colon + 1); targetNS = targetNamespacePath.Substring(0, colon + 1); } else { targetClass = targetNamespacePath; targetNS = sourceObj.Path.NamespacePath; } targetRole = WmiHelper.GetAssocTargetRole(assocInstance, sourceObj.Path); }
private bool UpdateClassDescription(ClassListControls curControl) { string ns = string.Empty; string className = string.Empty; if (curControl == ClassListControls.ClassTreeView) { if (classList.SelectedNode != null) { ns = classList.SelectedNode.Parent.Text; className = classList.SelectedNode.Text; } } else //this is a selected class list { //see if this is a multiple selection (or nothing is selected) and clear description in this case if (selectedClassList.SelectedIndices.Count != 1) { descr.Text = string.Empty; return(true); } string relPath = selectedClassList.SelectedItem.ToString(); ns = relPath.Substring(0, relPath.IndexOf(":")); className = relPath.Substring(relPath.IndexOf(":") + 1); // MessageBox.Show(path); } ISWbemObject obj = WmiHelper.GetClassObject(machineName, ns, className); string theDescr = WmiHelper.GetClassDescription(obj); if (theDescr != string.Empty) { //Add special handling for newlines: change all "\n" to System.Environment.NewLine: int i = -1; string theRest = theDescr; string theStart = string.Empty; while ((i = theRest.IndexOf("\n")) >= 0) { theStart = theStart + theRest.Substring(0, i) + System.Environment.NewLine; theRest = theRest.Substring(i + 1); } theDescr = theStart + theRest; descr.Text = theDescr; return(true); } else { descr.Text = WMISys.GetString("WMISE_NoDescr"); return(false); } }
public AssocGroupComponent(ISWbemObject assocInstance, ISWbemObject sourceObj) { sourceInst = sourceObj; associationPath = assocInstance.Path_.Path; associationClass = assocInstance.Path_.Class; //now, inspect assocInstance object to find target role and path targetClass = WmiHelper.GetAssocTargetClass(assocInstance, sourceObj.Path_); targetRole = WmiHelper.GetAssocTargetRole(assocInstance, sourceObj.Path_); }
public override Boolean CanResetValue(Object component) { //Cannot reset key property (this would create a new instance) if (WmiHelper.IsKeyProperty(prop)) { return(false); } else { return(!IsReadOnly); } }
/// <summary> /// This returns false if the object should be filtered out according to currentFilters value /// </summary> /// <param name="obj"> </param> private bool FilterPass(ManagementClass obj) { switch (currentFilters) { case (ClassFilters.ConcreteData): { if (!WmiHelper.IsAbstract(obj) && !WmiHelper.IsAssociation(obj)) { return(true); } else { return(false); } } case (ClassFilters.ConcreteOrHavingConcreteSubclasses): { if (!WmiHelper.IsAbstract(obj) || WmiHelper.HasNonAbstractChildren(obj)) { return(true); } else { return(false); } } case (ClassFilters.ExtrinsicEvents): { if (WmiHelper.IsEvent(obj)) { return(true); } else { return(false); } } case (ClassFilters.All): { return(true); } default: break; } return(true); }
private void OnSelectClass(Object source, EventArgs args) { try { StringTable strs = new StringTable(50); SelectWMIClassTreeDialog selectClassDlg = new SelectWMIClassTreeDialog( serverName, ClassFilters.ExtrinsicEvents, //SchemaFilters.NoSystem |SchemaFilters.NoAssoc, strs); DialogResult ret = ((SelectWMIClassTreeDialog)selectClassDlg).ShowDialog(); if (ret != DialogResult.OK) { return; } String selClass = ((SelectWMIClassTreeDialog)selectClassDlg).SelectedClasses.ToArray()[0]; eventClassBox.Text = selClass; if (grid != null) { this.Controls.Remove(grid); grid = null; } grid = new WMIObjectGrid(WmiHelper.GetClassObject(serverName, NS, ClassName), PropertyFilters.NoSystem, GridMode.EditMode, true, false, false); grid.Location = new Point(16, 70); grid.Size = (Size) new Point(368, 180); grid.Anchor = AnchorStyles.All; grid.PreferredColumnWidth = 90; grid.PreferredRowHeight = 19; grid.TabIndex = 3; ((DataTable)grid.DataSource).RowChanging += new DataRowChangeEventHandler(this.GridRowChanging); this.Controls.Add(grid); QueryText.Text = "SELECT * FROM " + ClassName; } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); } }
public QueryConditionDialog(string serverIn, string user, string pw, string NS, string clsName, string queryIn) { try { if (serverIn == string.Empty || NS == string.Empty || clsName == string.Empty) { throw new ArgumentException(); } serverName = serverIn; connectAs = user; password = pw; className = clsName; nsName = NS; queryString = queryIn; InitializeComponent(); gridLabel.Location = new Point(16, 16); gridLabel.Text = "Set query conditions:"; gridLabel.Size = new Size(250, 20); grid = new WMIObjectGrid(WmiHelper.GetClassObject(serverName, nsName, className, connectAs, password), new PropertyFilters(true, true), GridMode.LocalEditMode, true, false, false, true, false, true, true); grid.Location = new Point(16, 40); grid.Size = (Size) new Point(468, 160); grid.Anchor = AnchorStyles.Top; //.All; grid.PreferredColumnWidth = 90; grid.PreferredRowHeight = 19; grid.TabIndex = 3; ((DataTable)grid.DataSource).RowChanging += new DataRowChangeEventHandler(this.GridRowChanging); Controls.Add(grid); } catch (Exception exc) { throw (exc); } }
public static ManagementClass GetClassObject(ManagementObject objIn, string user, string pw) { if (objIn == null) { throw new ArgumentException(); } try { ManagementPath path = objIn.Path; if (path.IsClass) { return((ManagementClass)objIn); } ManagementPath classPath = new ManagementPath(path.NamespacePath + ":" + path.ClassName); ObjectGetOptions options = new ObjectGetOptions(null, true); ConnectionOptions connectOpts = new ConnectionOptions( "", //locale user, //username pw, //password "", //authority ImpersonationLevel.Impersonate, AuthenticationLevel.Connect, true, //enablePrivileges null //context ); ManagementScope scope = (path.Server == WmiHelper.DNS2UNC(Dns.GetHostName())) ? new ManagementScope(path.NamespacePath) : new ManagementScope(path.NamespacePath, connectOpts); ManagementClass classObj = new ManagementClass(scope, classPath, options); return(classObj); } catch (Exception) { return(null); } }
public static ManagementObject GetClassObject(string server, string ns, string className, string user, string pw) { if (ns == string.Empty || className == string.Empty) { throw new ArgumentException(); } try { ManagementPath classPath = new ManagementPath(WmiHelper.MakeClassPath(server, ns, className)); ObjectGetOptions options = new ObjectGetOptions(null, true); ConnectionOptions connectOpts = new ConnectionOptions( "", //locale user, //username pw, //password "", //authority ImpersonationLevel.Impersonate, AuthenticationLevel.Connect, true, //enablePrivileges null //context ); ManagementScope scope = (server == WmiHelper.DNS2UNC(Dns.GetHostName())) ? new ManagementScope(WmiHelper.MakeNSPath(server, ns)) : new ManagementScope(WmiHelper.MakeNSPath(server, ns), connectOpts); ManagementObject classObj = new ManagementObject(scope, classPath, options); return(classObj); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(null); } }
// // METHODS // // <doc> // <desc> // Create associator instance nodes under this grouping. // </desc> // </doc> public override Node[] CreateChildren() { GetRelatedOptions opts = new GetRelatedOptions(null, //context TimeSpan.MaxValue, //timeout 50, //block size false, //rewindable true, //return immediately true, //use amended true, //locatable false, //prototype only false, //direct read theComp.targetClass, //related class theComp.associationClass, //RELATIONSHIP CLASS string.Empty, //relationship qualifier string.Empty, //related qualifier theComp.targetRole, //related role string.Empty, //this role false //classes only ); ManagementObjectCollection assocInstances = theComp.sourceInst.GetRelated(opts); if (assocInstances == null) { return(null); } ArrayList arNodes = new ArrayList(50); ManagementObjectCollection.ManagementObjectEnumerator enumAssocInst = assocInstances.GetEnumerator(); while (enumAssocInst.MoveNext()) { ManagementObject curObj = (ManagementObject)enumAssocInst.Current; arNodes.Add(new WMIInstanceNode(curObj, WmiHelper.GetClassObject(curObj, connectAs, password), connectAs, password)); } Node[] childNodes = new Node[arNodes.Count]; arNodes.CopyTo(childNodes); return(childNodes); }
internal void SetPropertyValue(int rowNum, String val) { try { DataRow row = this.Rows.All[rowNum]; ISWbemProperty propAffected = wmiObj.Properties_.Item(row[propNameColumn].ToString(), 0); Object newValue = WmiHelper.GetTypedObjectFromString(propAffected.CIMType, val); propAffected.set_Value(ref newValue); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw (exc); } }
public static String GetDisplayName(ISWbemObject obj) { try { ISWbemObject verboseObj = obj; if (!obj.Path_.IsClass) { verboseObj = WmiHelper.GetClassObject(obj); } ISWbemQualifier dispName = verboseObj.Qualifiers_.Item("DisplayName", 0); return(dispName.get_Value().ToString()); } catch (Exception) { return(String.Empty); } }
static public String GetClassDescription(ISWbemObject obj) { try { ISWbemObject verboseObj = obj; if (!obj.Path_.IsClass) { verboseObj = WmiHelper.GetClassObject(obj); } ISWbemQualifier descrQual = verboseObj.Qualifiers_.Item("Description", 0); return(descrQual.get_Value().ToString()); } catch (Exception) { return(""); } }
internal void SetPropertyValue(int rowNum, String val) { try { DataRow row = this.Rows[rowNum]; Property propAffected = (Property)this.rowPropertyMap[row]; //mgmtObj.Properties[row[propNameColumn].ToString()]; Object newValue = WmiHelper.GetTypedObjectFromString(propAffected.Type, val); propAffected.Value = newValue; } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw (exc); } }
static public String GetClassDescription(ManagementObject obj, string connectAs, string pw) { try { ManagementObject verboseObj = obj; if (!obj.Path.IsClass) { verboseObj = WmiHelper.GetClassObject(obj, connectAs, pw); } Qualifier descrQual = verboseObj.Qualifiers["Description"]; return(descrQual.Value.ToString()); } catch (Exception) { return(""); } }
public static String GetDisplayName(ManagementObject obj, string connectAs, string pw) { try { ManagementObject verboseObj = obj; if (!obj.Path.IsClass) { verboseObj = WmiHelper.GetClassObject(obj, connectAs, pw); } Qualifier dispName = verboseObj.Qualifiers["DisplayName"]; return(dispName.Value.ToString()); } catch (Exception) { return(String.Empty); } }
// // METHODS // // <doc> // <desc> // Create <Add Classes> node under this node. // </desc> // </doc> public override Node[] CreateChildren() { //TODO: if connectAs and password are specified and this is a local server, //you cannot connect to WMI. Offer an option to connect as a current user //instead. If rejected, make this node an error node. Node[] children = GetNodeSite().GetChildNodes(); if (children == null || children.Length == 0) { children = new Node[DefaultClasses.Length + 1]; int i, k; for (i = 0, k = 0; i < DefaultClasses.Length; i++) { try { children[k] = new WMIClassNode(WmiHelper.MakeClassPath(GetNodeSite().GetMachineName(), DefaultNS, DefaultClasses[i]), this.ConnectAs, this.Password); } catch (Exception) { //children[k] = new ErrorNode(new ErrorComponent(exc)); continue; //k wouldn't get increased } k++; } children[k] = GetNewChildNode(); Node[] children2 = new Node[k + 1]; Array.Copy(children, children2, k + 1); return(children2); } return(children); }
/// <summary> /// Returns true if classObj has non-abstract subclasses (with deep enumeration) /// </summary> /// <param name="classObj"> </param> static public bool HasNonAbstractChildren(ManagementClass classObj) { GetSubclassesOptions opts = new GetSubclassesOptions(null, //context TimeSpan.MaxValue, //timeout 50, //block size false, //rewindable true, //return immediately false, //amended true); //deep ManagementObjectCollection subClasses = classObj.GetSubclasses(opts); ManagementObjectCollection.ManagementObjectEnumerator childEnum = subClasses.GetEnumerator(); while (childEnum.MoveNext()) { ManagementClass curChild = (ManagementClass)childEnum.Current; if (!WmiHelper.IsAbstract(curChild)) { return(true); } } return(false); }
private string FilterPass(ISWbemObject obj) { try { String strLabel = ((ISWbemObjectPath)(obj.Path_)).RelPath; //TreeNode child = new TreeNode(strLabel); //child.ImageIndex = (int)schema_icons.SCHEMA_CLASS; //child.SelectedImageIndex = (int)schema_icons.SCHEMA_CLASS; if (WmiHelper.IsAbstract(obj)) { if (currentFilters == ClassFilters.ConcreteData) { return(string.Empty); } if (!WmiHelper.IsEvent(obj) && (currentFilters == ClassFilters.ExtrinsicEvents)) { return(string.Empty); } //child.ImageIndex = (int)schema_icons.SCHEMA_CLASS_ABSTRACT2; //child.SelectedImageIndex = (int)schema_icons.SCHEMA_CLASS_ABSTRACT2; } if (WmiHelper.IsAssociation(obj)) { if (currentFilters != ClassFilters.All) { return(string.Empty); } else { if (!WmiHelper.IsAbstract(obj)) { //child.ImageIndex = (int)schema_icons.SCHEMA_ASSOC; //child.SelectedImageIndex = (int)schema_icons.SCHEMA_ASSOC; } //else //{//covered before, in the "abstract" case} } } if (WmiHelper.IsSystem(obj)) { if (currentFilters != ClassFilters.All) { return(string.Empty); } else { //child.ImageIndex = (int)schema_icons.SCHEMA_CLASS_ABSTRACT2; //child.SelectedImageIndex = (int)schema_icons.SCHEMA_CLASS_ABSTRACT2; } } if (WmiHelper.IsEvent(obj)) { if (currentFilters == ClassFilters.ConcreteData) { return(string.Empty); } else { //child.ImageIndex = (int)schema_icons.SCHEMA_CLASS_ABSTRACT2; //child.SelectedImageIndex = (int)schema_icons.SCHEMA_CLASS_ABSTRACT2; } } else { if (currentFilters == ClassFilters.ExtrinsicEvents) { return(string.Empty); } } return(strLabel); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(string.Empty); } }
private bool EnumNamespaces(string parent, int num) //recursively adds namespaces to the drop-down box { try { //show the node TreeNode dummy = new TreeNode(""); TreeNode[] children = new TreeNode[] { dummy }; TreeNode nsNode = new TreeNode(parent, //(int)schema_icons.SCHEMA_NS_CLOSED, //(int)schema_icons.SCHEMA_NS_CLOSED, children); nsNode.Collapse(); this.Nodes.Insert(num, nsNode); string nsPath = WmiHelper.MakeClassPath(server, parent, "__NAMESPACE"); string nsScopePath = WmiHelper.MakeNSPath(server, parent); ConnectionOptions connectOpts = new ConnectionOptions("", //locale this.connectAs, //username this.password, //password "", //authority ImpersonationLevel.Impersonate, AuthenticationLevel.Connect, true, //enablePrivileges null //context ); ManagementScope scope = (this.server == WmiHelper.DNS2UNC(Dns.GetHostName())) ? new ManagementScope(nsScopePath): new ManagementScope(nsScopePath, connectOpts); ManagementClass nsClass = new ManagementClass(scope, new ManagementPath(nsPath), new ObjectGetOptions(null, true)); ManagementObjectCollection subNSCollection = nsClass.GetInstances(); IEnumerator eInstances = ((IEnumerable)subNSCollection).GetEnumerator(); while (eInstances.MoveNext()) { num++; ManagementObject obj = (ManagementObject)eInstances.Current; PropertyCollection props = (PropertyCollection)obj.Properties; string NameOut = ""; string curName = props["Name"].Value.ToString(); //skip localized namespace //NOTE: this assumes that localized namespaces are always leaf if (curName.ToUpper().IndexOf("MS_", 0) == 0) { continue; } //skip root\security namespace (we don't want to expose it) if (curName.ToUpper() == "SECURITY" && parent.ToUpper() == "ROOT") { continue; } //skip root\directory\ldap namespace (BUGBUG: change this in Beta2 when we can do asynchronous class enumerations) if (curName.ToUpper() == "LDAP" && parent.ToUpper() == "ROOT\\DIRECTORY") { continue; } if (parent != "") { NameOut = parent + "\\" + curName; } else { NameOut = curName; } EnumNamespaces(NameOut, num); } return(true); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); return(false); } }
private void OnAdvanced(Object source, EventArgs args) { try { QueryConditionDialog dlg = null; if (this.SelectedEventType == EventType.Instance) { //spawn an instance of the appropriate intrinsic event class //and set its TargetInstance property to the selected data class //Then, pass the instance object to QueryConditionDialog ctor. ManagementClass classObj = null; ManagementObject instObj = null; ManagementScope rootScope = new ManagementScope(new ManagementPath(WmiHelper.MakeNSPath(server, "root")), new ConnectionOptions("", connectAs, password, "", ImpersonationLevel.Impersonate, AuthenticationLevel.Connect, true, null)); if (EventTypeSelector.Text == WMISys.GetString("WMISE_IntrinsicEvent_Created")) { classObj = new ManagementClass(rootScope, new ManagementPath(WmiHelper.MakeClassPath(server, "root", "__InstanceCreationEvent")), new ObjectGetOptions(null, true)); instObj = classObj.CreateInstance(); } else if (EventTypeSelector.Text == WMISys.GetString("WMISE_IntrinsicEvent_Modified")) { classObj = new ManagementClass(rootScope, new ManagementPath(WmiHelper.MakeClassPath(server, "root", "__InstanceModificationEvent")), new ObjectGetOptions(null, true)); instObj = classObj.CreateInstance(); } else if (EventTypeSelector.Text == WMISys.GetString("WMISE_IntrinsicEvent_Deleted")) { classObj = new ManagementClass(rootScope, new ManagementPath(WmiHelper.MakeClassPath(server, "root", "__InstanceDeletionEvent")), new ObjectGetOptions(null, true)); instObj = classObj.CreateInstance(); } else if (EventTypeSelector.Text == WMISys.GetString("WMISE_IntrinsicEvent_Operated")) { classObj = new ManagementClass(rootScope, new ManagementPath(WmiHelper.MakeClassPath(server, "root", "__InstanceOperationEvent")), new ObjectGetOptions(null, true)); instObj = classObj.CreateInstance(); } ManagementObject targetObj = new ManagementObject(WmiHelper.MakeClassPath(server, classTree.SelectedNS, classTree.SelectedClass), new ObjectGetOptions(null, false)); instObj["TargetInstance"] = (Object)targetObj; dlg = new QueryConditionDialog(instObj, server, classTree.SelectedNS, classTree.SelectedClass, queryString); } else { dlg = new QueryConditionDialog(server, connectAs, password, classTree.SelectedNS, classTree.SelectedClass, queryString); } DialogResult res = dlg.ShowDialog(); if (res == DialogResult.Cancel) { return; } //update query text; queryString = dlg.QueryString; } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); } }
internal bool ShowClasses(TreeNode curNode) { try { //check that this is a namespace: if (curNode.Parent != null) { return(false); } this.Cursor = Cursors.WaitCursor; curNode.Nodes.Clear(); curNSExpanded = curNode; curClassList.Clear(); //spawn a thread that would handle cancel dialog //Thread cancelDlgThread = new Thread (new ThreadStart(CancelDlgThread)); //cancelDlgThread.Start(); string nsPath = WmiHelper.MakeNSPath(server, curNSExpanded.Text); ConnectionOptions connectOpts = new ConnectionOptions( "", //locale this.connectAs, //username this.password, //password "", //authority ImpersonationLevel.Impersonate, AuthenticationLevel.Connect, true, //enablePrivileges null //context ); ManagementScope scope = (this.server == WmiHelper.DNS2UNC(Dns.GetHostName())) ? new ManagementScope(nsPath): new ManagementScope(nsPath, connectOpts); QueryOptions enumOpts = new QueryOptions(null, //context new TimeSpan(Int64.MaxValue), //timeout 50, //block size false, //non-rewindable true, //return immediately true, //use amended quals true, //ensure locatable false, //prototype only false //direct read ); ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, new ObjectQuery("select * from meta_class"), enumOpts); ManagementObjectCollection objs = searcher.Get(); ManagementObjectCollection.ManagementObjectEnumerator objEnum = objs.GetEnumerator(); while (objEnum.MoveNext() && !bCancelled) { ManagementClass obj = (ManagementClass)objEnum.Current; if (FilterPass(obj)) { TreeNode child = new TreeNode(obj.Path.RelativePath); curNSExpanded.Nodes.Add(child); //curClassList.Add(obj.Path.RelativePath, obj.Path.RelativePath); } } if (!bCancelled) { /* * for (int i = 0; i < curClassList.Count; i++) * { * * //TreeNode child = new TreeNode(curClassList.GetByIndex(i).ToString()); * //curNSExpanded.Nodes.Add(child); * } * * * cancelDlg.DialogResult = DialogResult.None; * cancelDlg.Hide(); * cancelDlg.Dispose(); * cancelDlg = null; */ } else { curClassList.Clear(); //re-set NS node: curNSExpanded.Nodes.Clear(); //show the node TreeNode dummy = new TreeNode(""); curNSExpanded.Nodes.Add(dummy); curNSExpanded.Collapse(); } this.OnNSExpandComplete(curNode.Text); this.Cursor = Cursors.Default; return(true); } catch (Exception e) { MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace)); this.Cursor = Cursors.Default; return(false); } }
public static Type ToType(CIMType cimtype, bool bIsArray, Property prop) { Type t = null; switch (cimtype) { case (CIMType.Boolean): { if (bIsArray) { Boolean[] ar = new Boolean[0]; t = ar.GetType(); } else { t = typeof(Boolean); } } break; case (CIMType.Char16): { if (bIsArray) { Char[] ar = new Char[0]; t = ar.GetType(); } else { t = typeof(Char); } } break; case (CIMType.DateTime): { if (WmiHelper.IsInterval(prop)) { if (bIsArray) { TimeSpan[] ar = new TimeSpan[0]; t = ar.GetType(); } else { t = typeof(TimeSpan); } } else { if (bIsArray) { DateTime[] ar = new DateTime[0]; t = ar.GetType(); } else { t = typeof(DateTime); } } } break; case (CIMType.Object): { if (bIsArray) { WMIObjectComponent[] ar = new WMIObjectComponent[0]; t = ar.GetType(); } else { t = typeof(WMIObjectComponent); } } break; case (CIMType.Real32): { if (bIsArray) { Single[] ar = new Single[0]; t = ar.GetType(); } else { t = typeof(Single); } } break; case (CIMType.Real64): { if (bIsArray) { Double[] ar = new Double[0]; t = ar.GetType(); } else { t = typeof(Double); } } break; case (CIMType.Reference): { if (bIsArray) { String[] ar = new String[0]; t = ar.GetType(); } else { t = typeof(String); } } break; case (CIMType.Sint16): { if (bIsArray) { Int16[] ar = new Int16[0]; t = ar.GetType(); } else { t = typeof(Int16); } } break; case (CIMType.Sint32): { if (bIsArray) { Int32[] ar = new Int32[0]; t = ar.GetType(); } else { t = typeof(Int32); } } break; case (CIMType.Sint64): { if (bIsArray) { Int64[] ar = new Int64[0]; t = ar.GetType(); } else { t = typeof(Int64); } } break; case (CIMType.Sint8): { if (bIsArray) { SByte[] ar = new SByte[0]; t = ar.GetType(); } else { t = typeof(SByte); } } break; case (CIMType.String): { if (bIsArray) { String[] ar = new String[0]; t = ar.GetType(); //return typeof(System.Collections.ArrayList); } else { t = typeof(String); } } break; case (CIMType.Uint16): { if (bIsArray) { UInt16[] ar = new UInt16[0]; t = ar.GetType(); } else { t = typeof(UInt16); } } break; case (CIMType.Uint32): { if (bIsArray) { UInt32[] ar = new UInt32[0]; t = ar.GetType(); } else { t = typeof(UInt32); } } break; case (CIMType.Uint64): { if (bIsArray) { UInt64[] ar = new UInt64[0]; t = ar.GetType(); } else { t = typeof(UInt64); } } break; case (CIMType.Uint8): { if (bIsArray) { Byte[] ar = new Byte[0]; t = ar.GetType(); } else { t = typeof(Byte); } } break; default: { if (bIsArray) { Object[] ar = new Object[0]; t = ar.GetType(); } else { t = typeof(Object); } } } return(t); }
/// <summary> /// Creates and adds to grid a single row corresponding to a single property. Can be called recursively for embedded /// objects. /// </summary> /// <param name="prop"> </param> /// <param name="namePrefix">This is used for embedded objects, so that the propertyof an embedded object /// appears to have name of form "Parent.Child" </param> private DataRow CreatePropertyRow(Property prop, string namePrefix) { if (prop == null) { return(null); } if (propFilters.HideInherited && !prop.IsLocal) { return(null); //skip this property } DataRow propRow = NewRow(); propRow[propNameColumn] = namePrefix + prop.Name; propRow[propTypeColumn] = CimTypeMapper.ToString(prop.Type); if (showOperators) { //TODO: initialize drop-down. How: in Beta2, a DataGridColumnStyle derived class //can be added, DataGridComboBoxColumn. Ask urtuser if they are planning to //to add one themselves propRow[operatorColumn] = string.Empty; } if (prop.Type == CimType.Object) { if ((showValues || showEmbeddedObjValue) && prop.Value is ManagementBaseObject) { if (showOperators) { propRow[operatorColumn] = "ISA"; } propRow[propValueColumn] = ((ManagementBaseObject)prop.Value).SystemProperties["__CLASS"].Value.ToString(); } else { propRow[propValueColumn] = string.Empty; } } else { if (showValues) { propRow[propValueColumn] = prop.Value; } else { propRow[propValueColumn] = string.Empty; } } //propRow[propDescrColumn] = WmiHelper.GetPropertyDescription(prop, wmiObj); //set property origin column if (showOrigin) { if (prop.IsLocal) { propRow[propOrigin] = true; } else { propRow[propOrigin] = false; } } if (showKeys) { propRow[propIsKey] = WmiHelper.IsKeyProperty(prop); } //grey selectionBoxColumn for expanded embedded object properties: if (propRow[propNameColumn].ToString().IndexOf(".") > 0) { //NOTE: this doesn't work!!! is there a way to disable input on an individual cell? propRow.SetUnspecified(selectionBoxColumn); } Rows.Add(propRow); if (prop.Type == CimType.Object && expandEmbedded) { if (prop.Value != null && prop.Value is ManagementBaseObject) { ManagementBaseObject embeddedObj = (ManagementBaseObject)prop.Value; foreach (Property embeddedProp in embeddedObj.Properties) { CreatePropertyRow(embeddedProp, prop.Name + "."); } } } rowPropertyMap.Add(propRow, prop); return(propRow); }
protected void RowChangingEventHandler(object sender, DataRowChangeEventArgs e) { try { DataRow row = e.Row; switch (e.Action) { case (DataRowAction.Add): { //throw (new Exception("Cannot add rows")); break; } case (DataRowAction.Change): { //if this is an object, datetime, enum or ref property changing, //bring up custom UI for editing these!!!! if (gridMode == GridMode.EditMode) { //this can only be value change Property propAffected = (Property)this.rowPropertyMap[row]; //mgmtObj.Properties[row[propNameColumn].ToString()]; if (propAffected.Type == CimType.Object) { ////MessageBox.Show("should bring up custom type editor for objects"); } if (propAffected.Type == CimType.Reference) { //MessageBox.Show("should bring up custom type editor for refs"); } if (propAffected.Type == CimType.DateTime) { //MessageBox.Show("should bring up custom type editor for datetime"); } if (WmiHelper.IsValueMap(propAffected)) { //MessageBox.Show("should bring up custom type editor for enums"); } } break; } case (DataRowAction.Commit): { //MessageBox.Show("DataRowAction.Commit"); break; } case (DataRowAction.Delete): { throw (new Exception("Cannot delete rows")); } case (DataRowAction.Nothing): { MessageBox.Show("DataRowAction.Nothing"); break; } case (DataRowAction.Rollback): { MessageBox.Show("DataRowAction.Rollback"); break; } } } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); throw(exc); } }
protected void RowChangedEventHandler(object sender, DataRowChangeEventArgs e) { try { DataRow RowAffected = e.Row; switch (e.Action) { case (DataRowAction.Add): { /* * MessageBox.Show("Cannot Add Rows. Deleting..."); * RowAffected.Delete(); */ break; } case (DataRowAction.Change): { DataRow row = e.Row; if (gridMode == GridMode.EditMode) { //this can only be value change Property propAffected = (Property)this.rowPropertyMap[row]; Object newValue = WmiHelper.GetTypedObjectFromString(propAffected.Type, row[propValueColumn].ToString()); propAffected.Value = newValue; } //possibly handle other modes here break; } case (DataRowAction.Commit): { //MessageBox.Show("DataRowAction.Commit"); break; } case (DataRowAction.Delete): { MessageBox.Show("Cannot delete nodes.Adding back..."); RowAffected.CancelEdit(); break; } case (DataRowAction.Nothing): { MessageBox.Show("DataRowAction.Nothing"); break; } case (DataRowAction.Rollback): { MessageBox.Show("DataRowAction.Rollback"); break; } } } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); } }