/// <summary> /// Enumerates items in the collection. /// </summary> public IEnumerator <KeyValuePair <object, object> > GetEnumerator() { lock (this) { return(_properties.GetEnumerator()); } }
/// <summary> /// Retrieves an array of properties that the given component instance /// provides. This may differ from the set of properties the class /// provides. If the component is sited, the site may add or remove /// additional properties. /// </summary> /// <returns> /// an array of properties this component surfaces. /// </returns> PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties() { PropertyCollection props = mgmtObj.Properties; PropertyCollection.PropertyEnumerator eProps = props.GetEnumerator(); PropertyDescriptor[] propDescrArray = new PropertyDescriptor[props.Count + NUM_OF_SYSTEM_PROPS]; if (propDescrArray.Length != 0) { int counter = 0; while (eProps.MoveNext()) { Property curProp = eProps.Current; if (GENUS == 2) { //get the property on the class object: to get to "Values" qualifier curProp = mgmtClassObj.Properties[curProp.Name]; } /* * if (WmiHelper.IsValueMap(curProp)) * { * //MessageBox.Show("Value map property " + ((ISWbemProperty)eProps.Current).Name); * propDescrArray[counter++] = new WMIEnumPropertyDescriptor(mgmtObj, * mgmtClassObj, * mgmtObj, * mgmtClassObj, * curProp.Name, * !IsNewInstance); * * } * else */ { propDescrArray[counter++] = new WMIPropertyDescriptor(mgmtObj, mgmtClassObj, curProp.Name, !IsNewInstance); } } //add system properties IDictionaryEnumerator enumSys = (IDictionaryEnumerator)((IEnumerable)SystemPropertyDictionary).GetEnumerator(); while (enumSys.MoveNext()) { propDescrArray[counter++] = new WMISystemPropertyDescriptor(mgmtObj, enumSys.Key.ToString(), enumSys.Value); } } return(new PropertyDescriptorCollection(propDescrArray)); }
/// <summary> /// note that Properties_ on ISWbemObject doesn't return system properties, /// so need to reconstruct them: __SERVER, __PATH, __GENUS are available through /// SWbemObjectPath; __DYNASTY, __DERIVATION can be accessed through SWbemObjct.Derivation_ /// </summary> private void Initialize() { try { ManagementPath path = mgmtObj.Path; if (path.IsClass) { GENUS = 1; } else //instance { GENUS = 2; } SystemPropertyDictionary.Add("__GENUS", GENUS); CLASS = path.ClassName; SystemPropertyDictionary.Add("__CLASS", CLASS); NAMESPACE = path.NamespacePath; SystemPropertyDictionary.Add("__NAMESPACE", NAMESPACE); PATH = path.Path; SystemPropertyDictionary.Add("__PATH", PATH); RELPATH = path.RelativePath; SystemPropertyDictionary.Add("__RELPATH", RELPATH); SERVER = path.Server; SystemPropertyDictionary.Add("__SERVER", SERVER); //get PROPERTY_COUNT PropertyCollection props = mgmtObj.Properties; PropertyCollection.PropertyEnumerator eProps = props.GetEnumerator(); while (eProps.MoveNext()) { PROPERTY_COUNT++; } SystemPropertyDictionary.Add("__PROPERTY_COUNT", PROPERTY_COUNT); //get inheritance-related properties Object[] oaDerivation = (Object[])mgmtObj.SystemProperties["__DERIVATION"].Value; if (oaDerivation.Length == 0) { DYNASTY = CLASS; } else { SUPERCLASS = oaDerivation[0].ToString(); DYNASTY = oaDerivation[oaDerivation.Length - 1].ToString(); } SystemPropertyDictionary.Add("__SUPERCLASS", SUPERCLASS); SystemPropertyDictionary.Add("__DYNASTY", DYNASTY); DERIVATION = new string[oaDerivation.Length]; Array.Copy(oaDerivation, DERIVATION, oaDerivation.Length); SystemPropertyDictionary.Add("__DERIVATION", DERIVATION); IsNewInstance = ((GENUS == 2) && (PATH == string.Empty)); } catch (Exception exc) { MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace)); } }
private void btnLoad_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "PDN Preset Files (.pst)|*.pst"; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream stream = File.Open(openFileDialog.FileName, FileMode.Open); BinaryFormatter reader = new BinaryFormatter(); this.lbEffect.Items.Clear(); this.types = new List <int>(); this.effects = new List <Effect>(); this.dialogs = new List <EffectConfigDialog>(); this.collections = new List <PropertyCollection>(); int type = 0; Effect effect = null; EffectConfigDialog dialog = null; PropertyCollection collection = null; PropertyBasedEffectConfigToken token = null; int effectCount = (int)reader.Deserialize(stream); for (int i = 0; i < effectCount; i++) { type = (int)reader.Deserialize(stream); effect = (Effect)available[type].GetConstructor(Type.EmptyTypes).Invoke(new object[0]); if ((effect.Options.Flags & EffectFlags.Configurable) != 0) { dialog = effect.CreateConfigDialog(); dialog.Effect = effect; if (dialog.EffectToken is PropertyBasedEffectConfigToken) { collection = ((PropertyBasedEffectConfigToken)dialog.EffectToken).Properties; token = new PropertyBasedEffectConfigToken(collection); IEnumerator <Property> enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { token.SetPropertyValue(enumerator.Current.Name, reader.Deserialize(stream)); } dialog.EffectToken = token; collection = ((PropertyBasedEffectConfigToken)dialog.EffectToken).Properties; } else { Type tokenType = dialog.EffectToken.GetType(); PropertyInfo[] info = tokenType.GetProperties(); for (int j = 0; j < info.Length; j++) { if (info[j].GetValue(dialog.EffectToken).GetType().IsSerializable == true) { object property = reader.Deserialize(stream); info[j].SetValue(dialog.EffectToken, property); } } } } this.lbEffect.Items.Add(this.cbEffect.Items[type]); this.types.Add(type); this.effects.Add(effect); this.dialogs.Add(dialog); this.collections.Add(collection); } FinishTokenUpdate(); stream.Close(); } }