/// <summary> /// Get the best settings for the first property found in a set of property names. /// This is useful for setting/retrieving contextual properties based upon the group setting of /// some root property. The user may want to look up the setting based upon the contextual name, /// and then the root property name, if it couldn't find one. /// </summary> /// <param name="ids"></param> /// <returns></returns> internal PropertyTable.SettingsGroup GetBestSettings(string[] ids) { PropertyTable.SettingsGroup bestSettings = PropertyTable.SettingsGroup.Undecided; // see if we have already stored the property with its context. foreach (string id in ids) { bestSettings = GetBestSettings(id); if (bestSettings != PropertyTable.SettingsGroup.Undecided) { break; } } return(bestSettings); }
static public void ChooseSinglePropertySequenceValue(Mediator mediator, string choiceValue, XmlNode choiceParameterNode, string propertyName, bool fEmptyAllowed, PropertyTable.SettingsGroup settingsGroup) { mediator.PropertyTable.SetProperty(propertyName + "Parameters", choiceParameterNode, settingsGroup); mediator.PropertyTable.SetPropertyPersistence(propertyName + "Parameters", false, settingsGroup); string sValue = mediator.PropertyTable.GetStringProperty(propertyName, "", settingsGroup); string[] rgsValues = sValue.Split(','); int idx = -1; if (sValue == choiceValue) { if (fEmptyAllowed) { sValue = ""; } } else if ((idx = IndexOf(rgsValues, choiceValue)) != -1) { // remove the choiceValue from the string. Debug.Assert(rgsValues.Length > 1); System.Text.StringBuilder sbValues = new System.Text.StringBuilder(sValue.Length); for (int i = 0; i < rgsValues.Length; ++i) { if (idx != i) { if (sbValues.Length > 0) { sbValues.Append(","); } sbValues.Append(rgsValues[i]); } } sValue = sbValues.ToString(); } else { if (sValue.Length == 0) { sValue = choiceValue; } else { sValue = sValue + "," + choiceValue; } } mediator.PropertyTable.SetProperty(propertyName, sValue, settingsGroup); mediator.PropertyTable.SetPropertyPersistence(propertyName, false, settingsGroup); }
/// <summary> /// set the value of a property to a node of a list. Also sets the corresponding parameters property. /// </summary> /// <remarks> this is static so that it can be called by the XCore initializationcode and set from the contents of the XML configuration file</remarks> /// <param name="mediator"></param> /// <param name="choice"></param> /// <param name="propertyName"></param> static public void ChooseSinglePropertyAtomicValue(Mediator mediator, string choiceValue, XmlNode choiceParameters, string propertyName, PropertyTable.SettingsGroup settingsGroup) { //a hack (that may be we could live with) // if(choiceParameters !=null) // { mediator.PropertyTable.SetProperty(propertyName + "Parameters", choiceParameters, settingsGroup); //it is possible that we would like to persist these parameters //however, as a practical matter, you cannot have XmlNodes witch do not belong to a document. //therefore, they could not be deserialize if we did save them. //unless, of course, we convert them to a string before serializing. //However, when de-serializing, what document would we attach the new xmlnode to? mediator.PropertyTable.SetPropertyPersistence(propertyName + "Parameters", false, settingsGroup); //} //remember, each of these calls to SetProperty() generate a broadcast, so the order of these two calls //is relevant. mediator.PropertyTable.SetProperty(propertyName, choiceValue, settingsGroup); if (choiceParameters != null) { //since we cannot persist the parameters, it's safer to not persist the choice either. mediator.PropertyTable.SetPropertyPersistence(propertyName, false, settingsGroup); } }
static public PropertyTable.SettingsGroup GetSettingsGroup(XmlNode configurationNode, PropertyTable.SettingsGroup defaultSettings) { string settingsGroupValue = XmlUtils.GetAttributeValue(configurationNode, "settingsGroup"); if (String.IsNullOrEmpty(settingsGroupValue)) { return(defaultSettings); } switch (settingsGroupValue) { case "local": return(PropertyTable.SettingsGroup.LocalSettings); case "global": return(PropertyTable.SettingsGroup.GlobalSettings); default: throw new Exception(String.Format("GetSettingsGroup does not yet support {0} for 'settingsGroup' attribute.", settingsGroupValue)); } }